Lucene的 - 寻找一个数值场 [英] Lucene - searching for a numeric value field
问题描述
好吧,我有与结果过去2小时搜索这仅仅给的小费,
,而不是连一个完整的代码救援(怎么会菜鸟学习,如果他们不能看到一些样品吗?)
ok, i have searched for this in the past two hours with results that only give's tips, and not even one complete code to the rescue ( how would noobs learn if they cant see some samples ? )
我创建了一个索引像这样:
i have created an index like so:
Directory directory = FSDirectory.Open(new System.IO.DirectoryInfo(Server.MapPath("/data/channels/")));
Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_29);
IndexWriter writer = new IndexWriter(directory, analyzer, true, Lucene.Net.Index.IndexWriter.MaxFieldLength.UNLIMITED);
Document doc = new Document();
doc.Add(new Field("ID", "0", Field.Store.YES, Field.Index.NO));
doc.Add(new Field("parentID", "0", Field.Store.YES, Field.Index.NO));
doc.Add(new Field("Title", "Root", Field.Store.YES, Field.Index.ANALYZED));
writer.AddDocument(doc);
writer.Optimize();
writer.Close();
现在,我想搜索字段 ID
中值等于 0
(获取单个记录,我有没有)......
Now, i want to search for the field ID
Where the value equals 0
( to get the single record i have there )....
但,一个简单的搜索是这样的:
but, a simple search like this:
Directory directory = FSDirectory.Open(new System.IO.DirectoryInfo(Server.MapPath("/data/channels")));
Analyzer analyzer = new Lucene.Net.Analysis.Standard.StandardAnalyzer(Version.LUCENE_29);
Searcher searcher = new Lucene.Net.Search.IndexSearcher(IndexReader.Open(directory, true));
Query query = new Lucene.Net.QueryParsers.QueryParser(Version.LUCENE_29, "ID", analyzer).Parse("0");
Hits hits = searcher.Search(query);
返回任何结果。
I读过关于 NumericRange
, KeywordAnalyzer
和一些更多的东西,
,但由于他们没有提供了一个示例我无法弄清楚如何做到这一点。
returns no results.
i have read about NumericRange
, KeywordAnalyzer
and some more things,
but since none of them provides a sample i could not figure out how to do it.
请,善良的人,给我如何让这件事工作的例子。
please, kind people, give me an example of how to make this thing work.
推荐答案
修改 Field.Index.NO
到 Field.Index。 ANALYZED
(或 Field.Index.NOT_ANALYZED
)的ID字段
Change Field.Index.NO
to Field.Index.ANALYZED
(or Field.Index.NOT_ANALYZED
) in ID field
这篇关于Lucene的 - 寻找一个数值场的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!