简体   繁体   中英

Why is this implementaion of Lucene not returning any results?

I'm adding SimpleLuucene to my app which is a wrapper layer that makes Lucene simpler to implement in basic situations, hoping to improve query speed. However when I did the most simplistic working concept to wire up the code I do not get any results. What am I doing wrong?

PS: I left out the code to initially create my indexes. But it has been run and the cfs and fdt files have data.

var searchcriteria = new Search.Helpers.Mapping().MapToModel(postdata);
var searcher = new DirectoryIndexSearcher(
    new DirectoryInfo(@"c:\search.index"), 
    true);
var query = new TermQuery(
    new Term("situs", "1144 Air Cargo Ave, Sarasota, Fl, 34243"));

var searchService = new SearchService(searcher);
var luceneresults = searchService.SearchIndex(query);

The query object TermQuery will try to match the input value exactly as is. Any difference between input and indexed values (such as Fl instead of FL ) will result in zero match. All casing, spaces and symbols need to be identical for Lucene to return a matching document. I would suggest pre-processing the input and indexed value before hand (ie lower-casing strings before indexing, and similarly for all search input) to avoid the subtle differences.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM