FAQ
I'm new to the list and I'm having an issue that I wanted to ask about quick. I'm using Lucene version 2.4.1

I recently rewrote a query to use the Query classes rather than a String and QueryParser. The search results between the two queries are now in different orders while the number of results are the same. I have one caveat with my change, I still use QueryParser for part of it so that I can easily handle quoting.

Here's some pseudo code:

Old Way
QueryParser parser = new QueryParser("words", analyzer);
Query q = parser.parse("+words:(one two) +year:[1950 2010]");
System.out.println("Old query is " + q);

New Way
BooleanQuery q = new BooleanQuery();
QueryParser parser = new QueryParser("words", analyzer);
q.add(parser.parse("one two"), Occur.MUST);
q.add(new RangeQuery(new Term("year", 1950), new Term("year", 2010), true), Occur.MUST);
System.out.println("New query is " + q);

My first thought was that the queries were ending up actually being different queries. To verify, I do a toString on the two different queries and they are the same. That output is:

Old query is +(words:one words:two) +year:[1950 TO 2010]
New query is +(words:one words:two) +year:[1950 TO 2010]

So, I'm sorta stuck as to what to do next in order to figure this out. I'm thinking that it has to do with the QueryParser usage in my "New Way", but I'm not sure how that would effect the ordering.

Anyone have experience with this or other things I can try?

Thanks,
-bp

Search Discussions

  • Ian Lea at Mar 26, 2010 at 12:08 pm
    Odd. Query.toString() and back to Query via parser are not guaranteed
    to be consistent but it looks pretty straightforward in this case.

    Maybe Searcher.explain would give a clue. Or post a minimal
    self-contained program or test case that demonstrates this. Or try a
    later version of lucene.


    --
    Ian.

    On Thu, Mar 25, 2010 at 11:04 PM, Brian Pontarelli wrote:
    I'm new to the list and I'm having an issue that I wanted to ask about quick. I'm using Lucene version 2.4.1

    I recently rewrote a query to use the Query classes rather than a String and QueryParser. The search results between the two queries are now in different orders while the number of results are the same. I have one caveat with my change, I still use QueryParser for part of it so that I can easily handle quoting.

    Here's some pseudo code:

    Old Way
    QueryParser parser = new QueryParser("words", analyzer);
    Query q = parser.parse("+words:(one two) +year:[1950 2010]");
    System.out.println("Old query is " + q);

    New Way
    BooleanQuery q = new BooleanQuery();
    QueryParser parser = new QueryParser("words", analyzer);
    q.add(parser.parse("one two"), Occur.MUST);
    q.add(new RangeQuery(new Term("year", 1950), new Term("year", 2010), true), Occur.MUST);
    System.out.println("New query is " + q);

    My first thought was that the queries were ending up actually being different queries. To verify, I do a toString on the two different queries and they are the same. That output is:

    Old query is +(words:one words:two) +year:[1950 TO 2010]
    New query is +(words:one words:two) +year:[1950 TO 2010]

    So, I'm sorta stuck as to what to do next in order to figure this out. I'm thinking that it has to do with the QueryParser usage in my "New Way", but I'm not sure how that would effect the ordering.

    Anyone have experience with this or other things I can try?

    Thanks,
    -bp


    ---------------------------------------------------------------------
    To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
    For additional commands, e-mail: java-user-help@lucene.apache.org
  • Brian Pontarelli at Mar 26, 2010 at 3:32 pm
    Yeah. I was thinking about of those. I don't want to upgrade as it is in production. I can't get a test case that reproduces the issue for some reason. I might need the production data set to test with.

    I'll definitely try an explain and see what the heck is going on.

    For now, I just reverted to a String search and everything is good again. Not a huge fan, but the change was fast and worked. I definitely think that the Query from QueryParser doesn't seem to mix well with BooleanQuery, which again seems odd.

    Thanks for the reply.

    -bp
    On Mar 26, 2010, at 6:07 AM, Ian Lea wrote:

    Odd. Query.toString() and back to Query via parser are not guaranteed
    to be consistent but it looks pretty straightforward in this case.

    Maybe Searcher.explain would give a clue. Or post a minimal
    self-contained program or test case that demonstrates this. Or try a
    later version of lucene.


    --
    Ian.

    On Thu, Mar 25, 2010 at 11:04 PM, Brian Pontarelli wrote:
    I'm new to the list and I'm having an issue that I wanted to ask about quick. I'm using Lucene version 2.4.1

    I recently rewrote a query to use the Query classes rather than a String and QueryParser. The search results between the two queries are now in different orders while the number of results are the same. I have one caveat with my change, I still use QueryParser for part of it so that I can easily handle quoting.

    Here's some pseudo code:

    Old Way
    QueryParser parser = new QueryParser("words", analyzer);
    Query q = parser.parse("+words:(one two) +year:[1950 2010]");
    System.out.println("Old query is " + q);

    New Way
    BooleanQuery q = new BooleanQuery();
    QueryParser parser = new QueryParser("words", analyzer);
    q.add(parser.parse("one two"), Occur.MUST);
    q.add(new RangeQuery(new Term("year", 1950), new Term("year", 2010), true), Occur.MUST);
    System.out.println("New query is " + q);

    My first thought was that the queries were ending up actually being different queries. To verify, I do a toString on the two different queries and they are the same. That output is:

    Old query is +(words:one words:two) +year:[1950 TO 2010]
    New query is +(words:one words:two) +year:[1950 TO 2010]

    So, I'm sorta stuck as to what to do next in order to figure this out. I'm thinking that it has to do with the QueryParser usage in my "New Way", but I'm not sure how that would effect the ordering.

    Anyone have experience with this or other things I can try?

    Thanks,
    -bp


    ---------------------------------------------------------------------
    To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
    For additional commands, e-mail: java-user-help@lucene.apache.org

    ---------------------------------------------------------------------
    To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
    For additional commands, e-mail: java-user-help@lucene.apache.org
  • Chris Hostetter at Mar 27, 2010 at 1:21 am
    : quick. I'm using Lucene version 2.4.1
    ...
    : and QueryParser. The search results between the two queries are now in
    : different orders while the number of results are the same. I have one

    : Old Way
    : QueryParser parser = new QueryParser("words", analyzer);
    : Query q = parser.parse("+words:(one two) +year:[1950 2010]");
    ...
    : New Way
    ...
    : q.add(new RangeQuery(new Term("year", 1950), new Term("year", 2010), true), Occur.MUST);


    You are using RangeQuery which takes into account the idf of each term ...
    QueryParser (in 2.4) uses ConstantScoreRangeQuery instead.

    I would change your new code to use ConstantScoreRangeQuery and go with
    that (the order will be determed based on the score of the "words" not the
    dates -- that's typically what people want)

    -Hoss


    ---------------------------------------------------------------------
    To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
    For additional commands, e-mail: java-user-help@lucene.apache.org

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupjava-user @
categorieslucene
postedMar 25, '10 at 11:04p
activeMar 27, '10 at 1:21a
posts4
users3
websitelucene.apache.org

People

Translate

site design / logo © 2021 Grokbase