lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Erick Erickson" <erickerick...@gmail.com>
Subject Re: Using PerFieldAnalyzerWrapper with KeywordAnalyzer - MultiFieldQueryParser
Date Tue, 13 Jan 2009 13:43:52 GMT
Are you sure that you close the IndexWriter *before* you
open your _Searcher in your program (it kinda looks
like a test program is why I'm asking).

If the above is OK, I'd really recommend getting a copy
of Luke, writing your index to a FSDirectory and looking
at it with Luke.

Barring all that, try peeling back your code. That is, use
a very simple analyzer first on a single field then move up
to MultiFieldQueryParser. Usually whenever I do this I
wind up finding something silly <G>....

Best
Erick

On Mon, Jan 12, 2009 at 6:02 PM, Michael Nguyen <n.tm.michael@gmail.com>wrote:

> 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.
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message