简体   繁体   中英

Lucene .NET searching

Hi i am trying to make autocomplete system using Lucene library to search over 170K records.

But there is a litle problem.

For example when i search for Candice Gra(...), it brings records like

Candice Jackson
Candice Hamilton
Candice Hayes

Bu not Candice Graham to make Lucene find Candice Graham i need to type Candice Graham exactly.

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)

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

Grass
Gravity
Gray (etc.)

By the way i used KeywordAnalyzer and SimpleAnalyzer but these are not worked either. Any ideas?

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

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

I think you need to put a AND keyword between these two words.

"Candice" AND "Gra"

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

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