Hi Uwe,
Thanks.
Actually, I do use that logic in another part of the code for some other 
functionality :).
However, I was wondering if we have some direct API to check for the presence 
of terms (Terms, NumericRanges, etc.) given an abstract query. My requirement 
is simple: Irrespective of the Query sub-class implementation (which will 
either extend or change in the future), I want to check whether the net effect 
of this query (bool or otherwise) is a MatchAllQuery (i.e. without any terms) 
or a query with at least one term, or numeric range.
The alternative to traverse the bool hierarchy and check instanceOf() on every 
clause for a Query Subclass may be involved, cumbersome, and prone to error. 
Your thoughts? -----------------------Thanks n Regards,
Sandeep Ramesh Khanzode 


    On Saturday, November 28, 2015 5:29 PM, Uwe Schindler <[email protected]> 
wrote:
 

 Hi,

You can also traverse a BooleanQuery. Just do instanceof BooleanQuery checks 
and if it is a BooleanQuery recursively iterate over all clauses [you can use a 
BooleanQuery in a for-each java loop as it implements Iterable]. For each 
clause recurse and check types again. Then you should be able to detect all 
types of queries in the tree.

Uwe

-----
Uwe Schindler
H.-H.-Meier-Allee 63, D-28213 Bremen
http://www.thetaphi.de
eMail: [email protected]

> -----Original Message-----
> From: Sandeep Khanzode [mailto:[email protected]]
> Sent: Saturday, November 28, 2015 12:22 PM
> To: [email protected]
> Subject: Re: Determine whether a MatchAllQuery or a Query with atleast
> one Term
> 
> Hi,
> Actually, the MatchAllQuery, for all I know (since it is invoked by the 
> client)
> can be wrapped in a Bool Query type. Hence, it is difficult for me to traverse
> the Bool Query clauses and determine MatchAll, whereas there may be
> other clauses which do contain a TermQuery or a NumericRangeQuery in
> which case a MatchAllQuery check is futile.
> Given any query, Bool Query or MatchAll, or a specific subclass of Query,
> what would be the safe way to determine that this is not a MatchAll query
> without any terms, or whether this is a query that contains at least one term
> or range? -----------------------Thanks n Regards,
> Sandeep Ramesh Khanzode
> 
> 
>    On Saturday, November 28, 2015 12:30 PM, Michael Wilkowski
> <[email protected]> wrote:
> 
> 
>  Instanceof?
> 
> MW
> Sent from Mi phone
> On 28 Nov 2015 06:57, "Sandeep Khanzode"
> <[email protected]>
> wrote:
> 
> > Hi,
> > I have a question.
> > In my program, I need to check whether the input query is a MatchAll
> Query
> > that contains no terms, or a Query (any variant) that has at least one
> > term. For typical Term queries, this seems reasonable to be done with
> > Query.extractTerms(Set<> terms) which gives the list of terms.
> > However, when there is a NumericRangeQuery, this method throws an
> > UnsupportedOperationException.
> > How can I determine that a NumericRangeQuery or any non-Term query
> exists
> > in the Input Query and differentiate it from the MatchAllQuery? -- SRK
> 
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]


  

Reply via email to