lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Bill Chesky <>
Subject Analyzer on query question
Date Thu, 02 Aug 2012 21:09:11 GMT

I understand that generally speaking you should use the same analyzer on querying as was used
on indexing.  In my code I am using the SnowballAnalyzer on index creation.  However, on the
query side I am building up a complex BooleanQuery from other BooleanQuerys and/or PhraseQuerys
on several fields.  None of these require specifying an analyzer anywhere.  This is causing
some odd results, I think, because a different analyzer (or no analyzer?) is being used for
the query.

Question: how do I build my boolean and phrase queries using the SnowballAnalyzer?

One thing I did that seemed to kind of work was to build my complex query normally then build
a snowball-analyzed query using a QueryParser instantiated with a SnowballAnalyzer.  To do
this, I simply pass the string value of the complex query to the QueryParser.parse() method
to get the new query.  Something like this:

    // build a complex query from other BooleanQuerys and PhraseQuerys
    BooleanQuery fullQuery = buildComplexQuery();
    QueryParser parser = new QueryParser(Version.LUCENE_30, "title", new SnowballAnalyzer(Version.LUCENE_30,
    Query snowballAnalyzedQuery = parser.parse(fullQuery.toString());

    TopScoreDocCollector collector = TopScoreDocCollector.create(10000, true);, collector);

Like I said, this seems to kind of work but it doesn't feel right.  Does this make sense?
 Is there a better way?

thanks in advance,

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