lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From AHMET ARSLAN <iori...@yahoo.com>
Subject Re: relation among Terms included in Query
Date Mon, 28 Dec 2009 16:08:22 GMT
> Hello All,
>             I have observed
> extractTerms() in the class
> org.apache.lucene.search.Query which returns set of terms
> extracted
> from user input query. Is there any chance of getting the
> connecting-operator between all those terms. for example..
> Term1 OR
> Term2 AND Term3 ..    or  Term1 AND Term2
> AND Term3 , etc..
> Thanks.

You can extract org.apache.lucene.search.BooleanClause from BooleanQuery. Something like:



 if (contents instanceof BooleanQuery) {

BooleanQuery bq = (BooleanQuery) contents;
BooleanClause[] bclauses = bq.getClauses();
          
            for (int i = 0; i < bclauses.length; i++) {
                
                Query qc = bclauses[i].getQuery();
               
                
                if (bclauses[i].getOccur().equals(BooleanClause.Occur.MUST_NOT)) {
                 // NOT
                    
                }
                else if (bclauses[i].getOccur().equals(BooleanClause.Occur.MUST)) {
                // AND
                    
                }
                else if (bclauses[i].getOccur().equals(BooleanClause.Occur.SHOULD)) {
                // OR
                    
                }
           }
} 

Hope this helps.


      

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


Mime
View raw message