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 John Byrne <jo...@propylon.com> on 2007/10/05 18:22:57 UTC
Querying the Query object
Hi,
Is there any way to find out if an instance of Query has any terms
within it? I have a custom parser (QueryParser does not do everything I
need) and it somtimes creates empty BooleanQuerys. (This happens as a
side effect of recursive parsing - even if there are no terms for a
query, I still need to create it in case there turns out to be another
query nested inside it. ).
So I need to have a way of finding out if a query is blank, so that I
can exclude it when creating my final query.
The documented "extractTerms" method apparently only works if the
"rewrite" method is used first, and this requires an instance of
IndexReader which is not feasible for me, since all this happens in a
search servlet, and needs to be thread safe.
One way I have tried is to create a BooleanClause with the query, turn
it into a string with "toString()" and then check if that string
contains "()".
But I was hoping for a neater way!
Any suggestions?
Thanks!
JohnB
---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org
Re: Querying the Query object
Posted by Mark Miller <ma...@gmail.com>.
What makes you think the query needs to be rewritten to extract terms?
Not the case...unless you want to extract Terms from say, a Wildcard or
Fuzzy query. In that case you need an IndexReader however, as the terms
in the Wildcard/Fuzzy query are determined by what is in your index...
I am also confused by your thread safety concern...
- Mark
John Byrne wrote:
> Hi,
>
> Is there any way to find out if an instance of Query has any terms
> within it? I have a custom parser (QueryParser does not do everything
> I need) and it somtimes creates empty BooleanQuerys. (This happens as
> a side effect of recursive parsing - even if there are no terms for a
> query, I still need to create it in case there turns out to be another
> query nested inside it. ).
>
> So I need to have a way of finding out if a query is blank, so that I
> can exclude it when creating my final query.
>
> The documented "extractTerms" method apparently only works if the
> "rewrite" method is used first, and this requires an instance of
> IndexReader which is not feasible for me, since all this happens in a
> search servlet, and needs to be thread safe.
>
> One way I have tried is to create a BooleanClause with the query, turn
> it into a string with "toString()" and then check if that string
> contains "()".
>
> But I was hoping for a neater way!
>
> Any suggestions?
>
> Thanks!
> JohnB
>
>
> ---------------------------------------------------------------------
> 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
Re: Querying the Query object
Posted by "balaji.gandhi" <ji...@gmail.com>.
Hi,
I am trying to do something similar:-
Eg.
Input: (name:John AND name:Doe)
Output: ((firstName:John OR lastName:John) AND (firstName:John OR
lastName:John))
How can I extract the fields, change them and repackage the query?
Thanks,
Balaji
--
View this message in context: http://lucene.472066.n3.nabble.com/Querying-the-Query-object-tp549970p4033986.html
Sent from the Lucene - Java Users mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org
Re: Querying the Query object
Posted by John Byrne <jo...@propylon.com>.
Yes, that sounds like what I was looking for! Thanks.
Chris Hostetter wrote:
> : Is there any way to find out if an instance of Query has any terms within it?
> : I have a custom parser (QueryParser does not do everything I need) and it
> : somtimes creates empty BooleanQuerys. (This happens as a side effect of
>
> so you're problem is not "does a Query have any terms in it" it's "does a
> BooleanQuery have any clauses in it?" ... booleanQuery.clauses().size()
> will answer that question for you.
>
>
>
>
> -Hoss
>
>
> ---------------------------------------------------------------------
> 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
Re: Querying the Query object
Posted by Chris Hostetter <ho...@fucit.org>.
: Is there any way to find out if an instance of Query has any terms within it?
: I have a custom parser (QueryParser does not do everything I need) and it
: somtimes creates empty BooleanQuerys. (This happens as a side effect of
so you're problem is not "does a Query have any terms in it" it's "does a
BooleanQuery have any clauses in it?" ... booleanQuery.clauses().size()
will answer that question for you.
-Hoss
---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org