FAQ
Can you combine these two queries somehow so that they behave like a
PhraseQuery?

I have a custom query parser which takes a phrase like "*at sat" and
produces a BooleanQuery consisting of a WildcardQuery ('*at') and a
TermQuery ('sat'). This works, but matches more widely than expected
(by me).

e.g.
"*at sat" will match any docs containing '*at' OR 'sat', whereas
"cat sat" will only match docs containing the exact phrase

I would like the latter behaviour if at all possible.

I have looked at SpanQuery, but I can't see how to use it in this case...

Any pointers happily received.

- Chris


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

Search Discussions

  • Daniel Naber at Aug 26, 2008 at 4:28 pm

    On Dienstag, 26. August 2008, Chris Bamford wrote:

    Can you combine these two queries somehow so that they behave like a
    PhraseQuery?
    You can use MultiPhraseQuery, see
    http://lucene.apache.org/java/2_3_2/api/core/org/apache/lucene/search/MultiPhraseQuery.html

    Regards
    Daniel

    --
    http://www.danielnaber.de

    ---------------------------------------------------------------------
    To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
    For additional commands, e-mail: java-user-help@lucene.apache.org
  • Chris Bamford at Aug 26, 2008 at 5:02 pm
    Daniel,

    That sounds like what I'm after - but how do I get hold of the
    IndexReader so I can call IndexReader.terms(Term) ?
    The code where I am doing this work is getFieldQuery(String field,
    String queryText) of my custom query parser ...

    Thanks,

    - Chris


    Daniel Naber wrote:
    On Dienstag, 26. August 2008, Chris Bamford wrote:

    Can you combine these two queries somehow so that they behave like a
    PhraseQuery?
    You can use MultiPhraseQuery, see
    http://lucene.apache.org/java/2_3_2/api/core/org/apache/lucene/search/MultiPhraseQuery.html

    Regards
    Daniel

    ---------------------------------------------------------------------
    To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
    For additional commands, e-mail: java-user-help@lucene.apache.org
  • Daniel Naber at Aug 26, 2008 at 5:12 pm

    On Dienstag, 26. August 2008, Chris Bamford wrote:

    That sounds like what I'm after - but how do I get hold of the
    IndexReader so I can call IndexReader.terms(Term) ?
    The code where I am doing this work is getFieldQuery(String field,
    String queryText) of my custom query parser ...
    QueryParser indeed doesn't know about IndexSearchers and IndexReaders, so
    you either have to do the work outside (whereever you have an
    IndexSearcher, it lets you access the IndexReader) and hand the results
    over to your QueryParser via e.g. its constructor. Or you hand over the
    IndexReader to your QueryParser. That's not really elegant but I don't
    know a better solution.

    Regards
    Daniel

    --
    http://www.danielnaber.de

    ---------------------------------------------------------------------
    To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
    For additional commands, e-mail: java-user-help@lucene.apache.org
  • Chris Hostetter at Aug 28, 2008 at 3:27 am
    : > That sounds like what I'm after - but how do I get hold of the
    : > IndexReader so I can call IndexReader.terms(Term) ?
    : > The code where I am doing this work is getFieldQuery(String field,
    : > String queryText) of my custom query parser ...
    :
    : QueryParser indeed doesn't know about IndexSearchers and IndexReaders, so
    : you either have to do the work outside (whereever you have an
    : IndexSearcher, it lets you access the IndexReader) and hand the results
    : over to your QueryParser via e.g. its constructor. Or you hand over the
    : IndexReader to your QueryParser. That's not really elegant but I don't
    : know a better solution.

    it's what the Query.rewrite method is for, it gets an IndexReader as
    input. your custom QueryParser should return a new type of query that
    rewrites itself into a MultiPhraseQuery




    -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
postedAug 26, '08 at 3:08p
activeAug 28, '08 at 3:27a
posts5
users3
websitelucene.apache.org

People

Translate

site design / logo © 2022 Grokbase