lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Chris Hostetter <hossman_luc...@fucit.org>
Subject Re: Translating Lucene Query Syntax to Traditional Boolean Syntax
Date Tue, 25 Sep 2007 04:57:14 GMT

: Search we need to translate the Lucene style query into a more traditional
: Boolean query.  So this is the opposite of the much discussed Boolean Query
: to Lucene Query conversion.

it should be possible to translate, but like many translations there will 
be a small loss of information, specificly: strict boolean queries have no 
notion of score, so hte concept of an "optional" clause has no meaning ... 
either it's there and you get a match, or it's not and you don't.

You can translate to a query with an equivilent result set, but not one 
with equivilent semantic meaning, because the semantics don't apply 
(which also means you cannot have a reflexive translation except in 
trivial cases)

: Lucene: +a +b -c -d e f
	...
: (a AND b NOT c NOT d) OR (a AND b NOT c NOT d AND (e OR f))
	... 
: (+a +b -c -d)(+a +b -c -d +(e f))
: 
: which I think is equivalent but not as concise!  But I have not tested this

the first and third are not equivilent .. mainly because they will in fact 
score differently.  but that's not what you really care about -- what you 
realy care about is have you translated the first to the second correctly?  
i believe hte answer is "yes" with the caveat that it can be reduced to 
just the first clause of hte outermost OR query...
   (a AND b NOT c NOT d)
...anything mathcing the second clause of the outermost OR will match 
this, making the second clause redundent.  you could likewise translate 
the lucene query to....
   (a AND b NOT c NOT d) OR (a AND b NOT c NOT d AND a AND a AND a AND a)
...the point is they reduce to the same thing.

as a general rule when converting lucene queries to strict boolean 
queries: any optional clauses in a BQ containing at least one required 
clause can be eliminated, the are irrlevent from a strict matching 
standpoint -- they only influence score.


-Hoss


---------------------------------------------------------------------
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