0
我在.NET 4.5上使用Lucene .NET v3。我不知道爲什麼我在查詢中收到不正確的結果。這裏有一個簡單的測試程序:Lucene數字範圍查詢返回無結果/意外結果
static class Program
{
static Document MakeDocument(String rcaName, int statusCode)
{
var doc = new Document();
doc.Add(new Field("RCAName", rcaName, Field.Store.YES, Field.Index.NO));
doc.Add(new Field("ActionId", Guid.NewGuid().ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED));
var status = new NumericField("Status", Field.Store.YES, true);
status.SetLongValue(statusCode);
doc.Add(status);
return doc;
}
static void Main()
{
var dir = new SimpleFSDirectory(new DirectoryInfo("C:/Sologic/temp/bsindex"));
// var analyzer = new SologicAnalyzer() { StopWords = StopAnalyzer.ENGLISH_STOP_WORDS_SET };
var analyzer = new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_30);
using (var writer = new Lucene.Net.Index.IndexWriter(dir, analyzer, true, Lucene.Net.Index.IndexWriter.MaxFieldLength.UNLIMITED))
{
writer.AddDocument(MakeDocument("RCA 1", 2));
writer.AddDocument(MakeDocument("RCA 2", 4));
writer.AddDocument(MakeDocument("RCA 3", 2));
writer.AddDocument(MakeDocument("RCA 4", 4));
}
var searcher = new Lucene.Net.Search.IndexSearcher(IndexReader.Open(dir, true));
var query = new Lucene.Net.QueryParsers.QueryParser(Lucene.Net.Util.Version.LUCENE_30, "Status", analyzer).Parse("2");
var hits = searcher.Search(query, 100);
Console.WriteLine(hits.TotalHits);
Console.Read();
}
}
當我打開與盧克的指數,我運行下面的查詢:
Status:[2 TO 2] - 0
Status:[4 TO 4] - 0
Status:[0 TO 4] - 4
Status:[0 TO 2] - 4
Status:[0 TO 0] - 0
我有點困惑。任何人看到我做錯了什麼?
status.SetLongValue()如何變成SetIntValue()? statusCode將隱含地被轉換爲一長串。 – HelloWorld