还有一个极端新手的另一个Lucene.net问题.
这一次,我发现了使用包含范围和使用突出显示的查询的一个有趣问题.
我是从内存中写的,所以请原谅任何语法错误.
我有一个假设的Lucene索引:
---------------------------------------------------------
| date | text |
---------------------------------------------------------
| 1317809124 | a crazy block of text |
---------------------------------------------------------
| 1317809284 | programmers are crazy |
---------------------------------------------------------
** date is a unix timestamp
Run Code Online (Sandbox Code Playgroud)
......并且它们已通过以下方式添加到索引中:
Lucene.Net.Documents.Document doc = new Lucene.Net.Documents.Document();
doc.Add(new Lucene.Net.Documents.Field("text", "some block of text", Lucene.Net.Documents.Field.Store.YES, Lucene.Net.Documents.Field.Index.ANALYZED, Lucene.Net.Documents.Field.TermVector.WITH_POSITIONS_OFFSETS));
doc.Add(new Lucene.Net.Documents.Field("date", "some unix timestamp", Lucene.Net.Documents.Field.Store.YES, Lucene.Net.Documents.Field.Index.NOT_ANALYZED));
Run Code Online (Sandbox Code Playgroud)
这就是我查询Lucene的方式:
Lucene.Net.Analysis.Standard.StandardAnalyzer analyzer = new Lucene.Net.Analysis.Standard.StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_29);
Lucene.Net.Search.IndexSearcher searcher = new Lucene.Net.Search.IndexSearcher(Lucene.Net.Store.FSDirectory.Open(_headlinesDirectory), true);
Lucene.Net.QueryParsers.QueryParser parser = new Lucene.Net.QueryParsers.QueryParser(Lucene.Net.Util.Version.LUCENE_29, "text", analyzer);
Lucene.Net.Search.Query query = parser.Parse(queryPhrase); …Run Code Online (Sandbox Code Playgroud)