开发者

Lucene Searcher return only one match result

My search text goes as "ma" and i have two lucene document which have ma as the text in it. But in return i only get one document.

Below is the code :

//adding deocument 
document.Add(new Field("Text",text,Field.Store.YES, Field.Index.TOKENIZED));

//search logic :

IndexReader reader = Index开发者_运维技巧Reader.Open(GetFileInfo(indexName));
//create an index searcher that will perform the search
IndexSearcher searcher = new IndexSearcher(reader);

//List of ID
List<string> searchResultID = new List<string>();

//build a query object
QueryParser parser = new QueryParser("Text", analyzer);
parser.SetAllowLeadingWildcard(true);
Query query = parser.Parse(searchText);
//execute the query
Hits hits = searcher.Search(query);


Maybe you could use luke. It's a useful diagnostic tool that can display the contents of an existing Lucene index and do other interesting stuff. I haven't used it myself, so I'm not sure, but I think it might help you in debugging this issue. Good luck!


I was able to solve my issue :

Index Writer must be created only once.You can check whether the index exits or not if not you create an new IndexWriter . for eg :

//The last parameter bool of an IndexWriter Contructor which says that you want to create an newIndexWriter or not

IndexWriter writer = new IndexWriter(GetFileInfo(indexName), analyzer, true);

On adding the new Document you must perform an check whether index exists or not , if it exists , then just pass bool param as false to the IndexWriter constructor:

IndexWriter  writer = new IndexWriter(GetFileInfo(indexName), analyzer, false);
 writer.AddDocument(CreateDocument(Id, text, dateTime));
 writer.Optimize();
 writer.Close();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜