久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

<legend id='rVttK'><style id='rVttK'><dir id='rVttK'><q id='rVttK'></q></dir></style></legend>

    • <bdo id='rVttK'></bdo><ul id='rVttK'></ul>
    1. <tfoot id='rVttK'></tfoot>
      <i id='rVttK'><tr id='rVttK'><dt id='rVttK'><q id='rVttK'><span id='rVttK'><b id='rVttK'><form id='rVttK'><ins id='rVttK'></ins><ul id='rVttK'></ul><sub id='rVttK'></sub></form><legend id='rVttK'></legend><bdo id='rVttK'><pre id='rVttK'><center id='rVttK'></center></pre></bdo></b><th id='rVttK'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='rVttK'><tfoot id='rVttK'></tfoot><dl id='rVttK'><fieldset id='rVttK'></fieldset></dl></div>

      <small id='rVttK'></small><noframes id='rVttK'>

        如何在 Lucene 3.0.2 中索引和搜索文本文件?

        How do I index and search text files in Lucene 3.0.2?(如何在 Lucene 3.0.2 中索引和搜索文本文件?)
        <tfoot id='rkcr1'></tfoot>
          <tbody id='rkcr1'></tbody>

        • <small id='rkcr1'></small><noframes id='rkcr1'>

          <i id='rkcr1'><tr id='rkcr1'><dt id='rkcr1'><q id='rkcr1'><span id='rkcr1'><b id='rkcr1'><form id='rkcr1'><ins id='rkcr1'></ins><ul id='rkcr1'></ul><sub id='rkcr1'></sub></form><legend id='rkcr1'></legend><bdo id='rkcr1'><pre id='rkcr1'><center id='rkcr1'></center></pre></bdo></b><th id='rkcr1'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='rkcr1'><tfoot id='rkcr1'></tfoot><dl id='rkcr1'><fieldset id='rkcr1'></fieldset></dl></div>

            <legend id='rkcr1'><style id='rkcr1'><dir id='rkcr1'><q id='rkcr1'></q></dir></style></legend>

              • <bdo id='rkcr1'></bdo><ul id='rkcr1'></ul>

                  本文介紹了如何在 Lucene 3.0.2 中索引和搜索文本文件?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我是 Lucene 的新手,在創建查詢文本文件集合的簡單代碼時遇到了一些問題.

                  I am newbie in Lucene, and I'm having some problems creating simple code to query a text file collection.

                  我試過 這個例子,但是和新版本的Lucene不兼容.

                  I tried this example, but is incompatible with the new version of Lucene.

                  UDPATE: 這是我的新代碼,但還是不行還沒有.

                  UDPATE: This is my new code, but it still doesn't work yet.

                  推薦答案

                  Lucene 是一個相當大的話題,涉及到很多類和方法,如果不了解一些基本概念,通常是無法使用它的.如果您需要快速可用的服務,請改用 Solr.如果您需要完全控制 Lucene,請繼續閱讀.我將介紹一些代表它們的核心 Lucene 概念和類.(有關如何在內存中讀取文本文件的信息讀取,例如,this 文章).

                  Lucene is a quite big topic with a lot of classes and methods to cover, and you normally cannot use it without understanding at least some basic concepts. If you need a quickly available service, use Solr instead. If you need full control of Lucene, go on reading. I will cover some core Lucene concepts and classes, that represent them. (For information on how to read text files in memory read, for example, this article).

                  無論您要在 Lucene 中做什么 - 索引或搜索 - 您都需要一個分析器.分析器的目標是對輸入文本進行標記(分解成單詞)和詞干(獲取單詞的基礎).它還會拋出最常用的詞,如a"、the"等.您可以找到超過 20 種語言的分析器,或者您可以使用 SnowballAnalyzer 并將語言作為參數傳遞.
                  要為英語創建 SnowballAnalyzer 的實例,請執行以下操作:

                  Whatever you are going to do in Lucene - indexing or searching - you need an analyzer. The goal of analyzer is to tokenize (break into words) and stem (get base of a word) your input text. It also throws out the most frequent words like "a", "the", etc. You can find analyzers for more then 20 languages, or you can use SnowballAnalyzer and pass language as a parameter.
                  To create instance of SnowballAnalyzer for English you this:

                  Analyzer analyzer = new SnowballAnalyzer(Version.LUCENE_30, "English");
                  

                  如果你要索引不同語言的文本,并且想自動選擇分析器,你可以使用 tika 的語言標識符.

                  If you are going to index texts in different languages, and want to select analyzer automatically, you can use tika's LanguageIdentifier.

                  您需要將索引存儲在某個地方.這有兩種主要的可能性:易于嘗試的內存索引和使用最廣泛的磁盤索引.
                  使用接下來的 2 行中的任何一行:

                  You need to store your index somewhere. There's 2 major possibilities for this: in-memory index, which is easy-to-try, and disk index, which is the most widespread one.
                  Use any of the next 2 lines:

                  Directory directory = new RAMDirectory();   // RAM index storage
                  Directory directory = FSDirectory.open(new File("/path/to/index"));  // disk index storage
                  

                  當你想添加、更新或刪除文檔時,你需要IndexWriter:

                  When you want to add, update or delete document, you need IndexWriter:

                  IndexWriter writer = new IndexWriter(directory, analyzer, true, new IndexWriter.MaxFieldLength(25000));
                  

                  任何文檔(在您的情況下為文本文件)都是一組字段.要創建包含文件信息的文檔,請使用以下命令:

                  Any document (text file in your case) is a set of fields. To create document, which will hold information about your file, use this:

                  Document doc = new Document();
                  String title = nameOfYourFile;
                  doc.add(new Field("title", title, Field.Store.YES, Field.Index.ANALYZED));  // adding title field
                  String content = contentsOfYourFile;
                  doc.add(new Field("content", content, Field.Store.YES, Field.Index.ANALYZED)); // adding content field
                  writer.addDocument(doc);  // writing new document to the index
                  

                  Field 構造函數采用字段名稱、文本和至少 2 個參數.首先是一個標志,顯示 Lucene 是否必須存儲該字段.如果它等于 Field.Store.YES 您將有可能從索引中獲取所有文本,否則只會存儲有關它的索引信息.
                  第二個參數顯示 Lucene 是否必須索引該字段.將 Field.Index.ANALYZED 用于您要搜索的任何字段.
                  通常,您使用如上所示的兩個參數.

                  Field constructor takes field's name, it's text and at least 2 more parameters. First is a flag, that show whether Lucene must store this field. If it equals Field.Store.YES you will have possibility to get all your text back from the index, otherwise only index information about it will be stored.
                  Second parameter shows whether Lucene must index this field or not. Use Field.Index.ANALYZED for any field you are going to search on.
                  Normally, you use both parameters as shown above.

                  別忘了在工作完成后關閉你的 IndexWriter:

                  Don't forget to close your IndexWriter after the job is done:

                  writer.close();
                  

                  搜索有點棘手.您將需要幾個類:QueryQueryParser 從字符串中進行 Lucene 查詢,IndexSearcher 用于實際搜索,TopScoreDocCollector 存儲結果(它作為參數傳遞給 IndexSearcher)和 ScoreDoc 迭代結果.下一個片段顯示了這一切是如何組成的:

                  Searching is a bit tricky. You will need several classes: Query and QueryParser to make Lucene query from the string, IndexSearcher for actual searching, TopScoreDocCollector to store results (it is passed to IndexSearcher as a parameter) and ScoreDoc to iterate through results. Next snippet shows how this all is composed:

                  IndexSearcher searcher = new IndexSearcher(directory);
                  QueryParser parser = new QueryParser(Version.LUCENE_30, "content", analyzer);
                  Query query = parser.parse("terms to search");
                  TopScoreDocCollector collector = TopScoreDocCollector.create(HOW_MANY_RESULTS_TO_COLLECT, true);
                  searcher.search(query, collector);
                  
                  ScoreDoc[] hits = collector.topDocs().scoreDocs;
                  // `i` is just a number of document in Lucene. Note, that this number may change after document deletion 
                  for (int i = 0; i < hits.length; i++) {
                      Document hitDoc = searcher.doc(hits[i].doc);  // getting actual document
                      System.out.println("Title: " + hitDoc.get("title"));
                      System.out.println("Content: " + hitDoc.get("content"));
                      System.out.println();
                  }
                  

                  注意 QueryParser 構造函數的第二個參數 - 它是默認字段,即如果沒有給出限定符則將搜索的字段.例如,如果您的查詢是title:term",Lucene 將在所有文檔的title"字段中搜索單詞term",但如果您的查詢只是term",則在默認字段中搜索,在這種情況下- 內容".有關詳細信息,請參閱 Lucene 查詢語法.
                  QueryParser 也將分析器作為最后一個參數.這必須與您用于索引文本的分析器相同.

                  Note second argument to the QueryParser constructor - it is default field, i.e. field that will be searched if no qualifier was given. For example, if your query is "title:term", Lucene will search for a word "term" in field "title" of all docs, but if your query is just "term" if will search in default field, in this case - "contents". For more info see Lucene Query Syntax.
                  QueryParser also takes analyzer as a last argument. This must be same analyzer as you used to index your text.

                  您必須知道的最后一件事是 TopScoreDocCollector.create 第一個參數.它只是一個數字,表示您要收集多少個結果.例如,如果它等于 100,Lucene 將只收集第一個(按分數)100 個結果并丟棄其余的.這只是一種優化行為——你收集了最好的結果,如果你對它不滿意,你就用更大的數字重復搜索.

                  The last thing you must know is a TopScoreDocCollector.create first parameter. It is just a number that represents how many results you want to collect. For example, if it is equal 100, Lucene will collect only first (by score) 100 results and drop the rest. This is just an act of optimization - you collect best results, and if you're not satisfied with it, you repeat search with a larger number.

                  最后,不要忘記關閉搜索器和目錄以免丟失系統資源:

                  Finally, don't forget to close searcher and directory to not loose system resources:

                  searcher.close();
                  directory.close();
                  

                  另見 IndexFiles 演示類,來自 Lucene 3.0 源代碼一個>.

                  Also see IndexFiles demo class from Lucene 3.0 sources.

                  這篇關于如何在 Lucene 3.0.2 中索引和搜索文本文件?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  How can I detect integer overflow on 32 bits int?(如何檢測 32 位 int 上的整數溢出?)
                  Local variables before return statements, does it matter?(return 語句之前的局部變量,這有關系嗎?)
                  How to convert Integer to int?(如何將整數轉換為整數?)
                  How do I create an int array with randomly shuffled numbers in a given range(如何在給定范圍內創建一個隨機打亂數字的 int 數組)
                  Inconsistent behavior on java#39;s ==(java的行為不一致==)
                  Why is Java able to store 0xff000000 as an int?(為什么 Java 能夠將 0xff000000 存儲為 int?)
                  • <i id='zhSIw'><tr id='zhSIw'><dt id='zhSIw'><q id='zhSIw'><span id='zhSIw'><b id='zhSIw'><form id='zhSIw'><ins id='zhSIw'></ins><ul id='zhSIw'></ul><sub id='zhSIw'></sub></form><legend id='zhSIw'></legend><bdo id='zhSIw'><pre id='zhSIw'><center id='zhSIw'></center></pre></bdo></b><th id='zhSIw'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='zhSIw'><tfoot id='zhSIw'></tfoot><dl id='zhSIw'><fieldset id='zhSIw'></fieldset></dl></div>
                  • <legend id='zhSIw'><style id='zhSIw'><dir id='zhSIw'><q id='zhSIw'></q></dir></style></legend>

                        <tbody id='zhSIw'></tbody>

                        <bdo id='zhSIw'></bdo><ul id='zhSIw'></ul>

                        <small id='zhSIw'></small><noframes id='zhSIw'>

                        1. <tfoot id='zhSIw'></tfoot>
                            主站蜘蛛池模板: 国产蜜臀 | 天天搞天天搞 | 亚洲一区二区免费视频 | 久久91精品 | 国产精品亚洲视频 | 在线播放国产一区二区三区 | 久久精品一区二区三区四区 | 91av视频在线观看 | 欧美午夜精品久久久久久浪潮 | 欧美性生活视频 | 欧美xxxx性xxxxx高清 | 成人av在线大片 | 羞羞的视频在线看 | 久久精品视频91 | 这里有精品 | 一区二区三区四区免费观看 | 天天干夜夜| 一区二区三区免费观看 | 国产一二三视频在线观看 | 99久久婷婷国产综合精品电影 | 2018天天干天天操 | 欧美aⅴ| 一级黄色毛片免费 | 久热精品在线 | 中文字幕第三页 | 日韩av免费在线观看 | 成人av一区| 久久久久国产一区二区三区 | av日韩在线播放 | 三级成人在线 | 美女久久| 伊人影院99| 久久成人在线视频 | 久久久国产一区二区 | 观看毛片 | 久久精品一区 | 超黄毛片 | 亚洲区一 | 国产欧美在线一区二区 | 在线看片网站 | 国产视频在线观看一区二区三区 |