You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@lucene.apache.org by Chris Bamford <ch...@scalix.com> on 2008/08/26 17:08:14 UTC
Combining Wildcard and Term Queries?
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
Re: Combining Wildcard and Term Queries?
Posted by Chris Hostetter <ho...@fucit.org>.
: > 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
Re: Combining Wildcard and Term Queries?
Posted by Daniel Naber <lu...@danielnaber.de>.
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
Re: Combining Wildcard and Term Queries?
Posted by Chris Bamford <ch...@scalix.com>.
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
Re: Combining Wildcard and Term Queries?
Posted by Daniel Naber <lu...@danielnaber.de>.
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