繁体   English   中英

Lucene .NET搜索

[英]Lucene .NET searching

嗨,我正在尝试使用Lucene库制作自动完成系统来搜索170K记录。

但是有一个小问题。

例如,当我搜索Candice Gra(...)时,它会带来诸如

Candice Jackson
Candice Hamilton
Candice Hayes

Bu not 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,但它们都不起作用。 有任何想法吗?

如果要在搜索中包含空格,则应转义它们;

var query = queryParser.Parse(QueryParser.Escape(strQuery));

我认为您需要在这两个词之间加入AND关键字。

“ Candice”和“ Gra”

http://lucene.apache.org/core/2_9_4/queryparsersyntax.html#AND

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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