您好我正在尝试使用 Lucene 库来搜索超过 17 万条记录的自动完成系统。
但是有一个小问题。
例如,当我搜索 Candice Gra(...) 时,它会带来类似的记录
Candice Jackson
Candice Hamilton
Candice Hayes
但是不要 Candice Graham
让 Lucene 发现Candice Graham
我需要Candice Graham
准确输入。
这是我正在构建查询的代码。
Directory directory = FSDirectory.Open(new DirectoryInfo(context.Server.MapPath("
ISet<string> stopWordSet = new HashSet<string>(stopWords);
Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_30, stopWordSet);
IndexReader indexReader = IndexReader.Open(directory, true);
Searcher indexSearch = new IndexSearcher(indexReader);
//Singe Field Search
var queryParser = new QueryParser(Version.LUCENE_30,
"Title",
analyzer);
string strQuery = string.Format("{0}", q);
var query = queryParser.Parse(strQuery);
如果我像这样构建 strQuery(* 附加到查询中)
string strQuery = string.Format("{0}*", q);
但是使用这种方式也会带来不相关的记录。例如,如果我再次搜索 Candice Gra(...) 它会返回类似的记录
Grass
Gravity
Gray (etc.)
顺便说一句,我使用了 KeywordAnalyzer 和 SimpleAnalyzer,但这些也不起作用。有任何想法吗?