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

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

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

        <legend id='HXEfC'><style id='HXEfC'><dir id='HXEfC'><q id='HXEfC'></q></dir></style></legend>
      1. 在 Lucene 中索引和搜索日期

        Indexing and Searching Date in Lucene(在 Lucene 中索引和搜索日期)

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

            <tbody id='geKgu'></tbody>

            1. <small id='geKgu'></small><noframes id='geKgu'>

              <tfoot id='geKgu'></tfoot>
                <bdo id='geKgu'></bdo><ul id='geKgu'></ul>
                • <legend id='geKgu'><style id='geKgu'><dir id='geKgu'><q id='geKgu'></q></dir></style></legend>
                • 本文介绍了在 Lucene 中索引和搜索日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我尝试使用 DateTools.dateToString() 方法来索引日期.它可以正常用于索引和搜索.

                  I tried it to index date with DateTools.dateToString() method. Its working properly for indexing as well as searching.

                  但是我已经索引的数据有一些引用,它已经将 Date 索引为一个新的 Date().getTime().

                  But my already indexed data which has some references is in such a way that it has indexed Date as a new Date().getTime().

                  所以我的问题是如何对这些数据执行 RangeSearch Query...

                  So my problem is how to perform RangeSearch Query on this data...

                  有什么解决办法吗???

                  Any solution to this???

                  提前致谢.

                  推荐答案

                  您需要在日期字段上使用 TermRangeQuery.该字段始终需要使用 DateTools.dateToString() 进行索引才能正常工作.下面是使用 Lucene 3.0 对日期范围进行索引和搜索的完整示例:

                  You need to use a TermRangeQuery on your date field. That field always needs to be indexed with DateTools.dateToString() for it to work properly. Here's a full example of indexing and searching on a date range with Lucene 3.0:

                  public class LuceneDateRange {
                      public static void main(String[] args) throws Exception {
                          // setup Lucene to use an in-memory index
                          Directory directory = new RAMDirectory();
                          Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_30);
                          MaxFieldLength mlf = MaxFieldLength.UNLIMITED;
                          IndexWriter writer = new IndexWriter(directory, analyzer, true, mlf);
                  
                          // use the current time as the base of dates for this example
                          long baseTime = System.currentTimeMillis();
                  
                          // index 10 documents with 1 second between dates
                          for (int i = 0; i < 10; i++) {
                              Document doc = new Document();
                              String id = String.valueOf(i);
                              String date = buildDate(baseTime + i * 1000);
                              doc.add(new Field("id", id, Store.YES, Index.NOT_ANALYZED));
                              doc.add(new Field("date", date, Store.YES, Index.NOT_ANALYZED));
                              writer.addDocument(doc);
                          }
                          writer.close();
                  
                          // search for documents from 5 to 8 seconds after base, inclusive
                          IndexSearcher searcher = new IndexSearcher(directory);
                          String lowerDate = buildDate(baseTime + 5000);
                          String upperDate = buildDate(baseTime + 8000);
                          boolean includeLower = true;
                          boolean includeUpper = true;
                          TermRangeQuery query = new TermRangeQuery("date",
                                  lowerDate, upperDate, includeLower, includeUpper);
                  
                          // display search results
                          TopDocs topDocs = searcher.search(query, 10);
                          for (ScoreDoc scoreDoc : topDocs.scoreDocs) {
                              Document doc = searcher.doc(scoreDoc.doc);
                              System.out.println(doc);
                          }
                      }
                  
                      public static String buildDate(long time) {
                          return DateTools.dateToString(new Date(time), Resolution.SECOND);
                      }
                  }
                  

                  这篇关于在 Lucene 中索引和搜索日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Lucene Porter Stemmer not public(Lucene Porter Stemmer 未公开)
                  How to index pdf, ppt, xl files in lucene (java based or python or php any of these is fine)?(如何在 lucene 中索引 pdf、ppt、xl 文件(基于 java 或 python 或 php 中的任何一个都可以)?)
                  KeywordAnalyzer and LowerCaseFilter/LowerCaseTokenizer(KeywordAnalyzer 和 LowerCaseFilter/LowerCaseTokenizer)
                  How to search between dates (Hibernate Search)?(如何在日期之间搜索(休眠搜索)?)
                  How to get positions from a document term vector in Lucene?(如何从 Lucene 中的文档术语向量中获取位置?)
                  Java Lucene 4.5 how to search by case insensitive(Java Lucene 4.5如何按不区分大小写进行搜索)
                      • <bdo id='yuUVj'></bdo><ul id='yuUVj'></ul>
                        <tfoot id='yuUVj'></tfoot>
                        • <small id='yuUVj'></small><noframes id='yuUVj'>

                            <legend id='yuUVj'><style id='yuUVj'><dir id='yuUVj'><q id='yuUVj'></q></dir></style></legend>
                            <i id='yuUVj'><tr id='yuUVj'><dt id='yuUVj'><q id='yuUVj'><span id='yuUVj'><b id='yuUVj'><form id='yuUVj'><ins id='yuUVj'></ins><ul id='yuUVj'></ul><sub id='yuUVj'></sub></form><legend id='yuUVj'></legend><bdo id='yuUVj'><pre id='yuUVj'><center id='yuUVj'></center></pre></bdo></b><th id='yuUVj'></th></span></q></dt></tr></i><div id='yuUVj'><tfoot id='yuUVj'></tfoot><dl id='yuUVj'><fieldset id='yuUVj'></fieldset></dl></div>

                              <tbody id='yuUVj'></tbody>