Hi all,

I encountered the following problem with the searching the exact text.

This is how I index:
...
document.Add(new Field("keyword", "hello world", Field.Store.YES,
Field.Index.UN_TOKENIZED));
....

This is how I try to search for "hello world"
string[] fields = new string[] { "name", "keyword", "shortDescription" };

string strSearchTerm = "hello world";
PerFieldAnalyzerWrapper wrapper = new PerFieldAnalyzerWrapper(new
StandardAnalyzer());
wrapper.AddAnalyzer("keyword", new KeywordAnalyzer());

QueryParser parser = new MultiFieldQueryParser(fields, wrapper);

Query query = parser.Parse(strSearchTerm);
Hits hits = _Searcher.Search(query);

This returns 0 match.

The problem was that the query returns from QueryParser is: (name:hello
keyword:hello shortDescription:hello) (name:world keyword:world
shortDescription:world)

I've been searching for this issue and someone said that we can only use
TermQuery for search the entire text such as TermQuery termQuery = new
TermQuery(new Term("keyword", strSearchTerm);
Is that correct?
I'd like to use PerFieldAnalyzerWrapper with KeywordAnalyzer and
MultiFieldQueryParser as I try to search in multiple fields.

Can anyone clarify for me how to use KeywordAnalyzer and
PerFieldAnalyzerWrapper with MultiFieldQueryParser? Any help would be
appreciated.

Reply via email to