[英]Lucene .NET searching
Hi i am trying to make autocomplete system using Lucene library to search over 170K records. 嗨,我正在尝试使用Lucene库制作自动完成系统来搜索170K记录。
But there is a litle problem. 但是有一个小问题。
For example when i search for Candice Gra(...), it brings records like 例如,当我搜索Candice Gra(...)时,它会带来诸如
Candice Jackson
Candice Hamilton
Candice Hayes
Bu not Candice Graham
to make Lucene find Candice Graham
i need to type Candice Graham
exactly. Bu not Candice Graham
要让Lucene找到Candice Graham
我需要完全输入Candice Graham
。
Here is the code that i'm building query. 这是我正在建立查询的代码。
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);
If i build strQuery like this (* appended to the query) 如果我这样构建strQuery(*附加到查询中)
string strQuery = string.Format("{0}*", q);
But using this way brings irrelevant records too. 但是使用这种方式也会带来不相关的记录。 For example if i search Candice Gra(...) again it returns records like 例如,如果我再次搜索Candice Gra(...),它将返回类似
Grass
Gravity
Gray (etc.)
By the way i used KeywordAnalyzer and SimpleAnalyzer but these are not worked either. 顺便说一句,我使用了KeywordAnalyzer和SimpleAnalyzer,但它们都不起作用。 Any ideas? 有任何想法吗?
如果要在搜索中包含空格,则应转义它们;
var query = queryParser.Parse(QueryParser.Escape(strQuery));
I think you need to put a AND keyword between these two words. 我认为您需要在这两个词之间加入AND关键字。
"Candice" AND "Gra" “ Candice”和“ Gra”
http://lucene.apache.org/core/2_9_4/queryparsersyntax.html#AND http://lucene.apache.org/core/2_9_4/queryparsersyntax.html#AND
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.