java - Lucene Solr using complex filters -
i having problem specifying filters lucene/solr. every solution come breaks other solutions. let me start example. assume have following 5 documents:
- doc1 = [type:car, sold:false, owner:john]
- doc2 = [type:bike, productid:1, owner:brian]
- doc3 = [type:car, sold:true, owner:mike]
- doc4 = [type:bike, productid:2, owner:josh]
- doc5 = [type:car, sold:false, owner:john]
so need construct following filter queries:
give me documents of type:car has sold:false , if type different car, include in result. want docs 1, 2, 4, 5 document don't want doc3 because has sold:true. put more precisely:
for each document d in solr/lucene if d.type == car { if d.sold == false, add result else ignore } else { add result } return result
filter in documents of (type:car , sold:false) or (type:bike , productid:1). 1,2,5.
- get documents if type:car sold:false, otherwise me documents owners john, brian, josh. query should 1, 2, 4, 5.
note: don't know types in documents. here obvious because of small number of documents.
so solutions were:
- (-type:car) or ((type:car) , (sold:false). works fine , expected.
- ((-type:car) or ((type:car) , (sold:false)) , ((-type:bike) or ((type:bike) , (productid:1))). solution not work.
- ((owner:john) or (owner:brian) or (owner:josh)) , ((-type:car) or ((type:car) , (sold:false)). not work, can make work if do this: ((owner:john) or (owner:brian) or (owner:josh)) , ((version:* or (-type:car)) or ((type:car) , (sold:false)). don't understand how works, because logically should work, solr/lucene somehow something.
okay, sold car, use -(type:car sold:true)
.
this can incorporated other queries, you'll need careful lonely negative queries this. lucene doesn't handle them well, speaking, , solr has odd gotchas well. particularly, a -b
reads more "get forbid b" rather "get , b". similar problem a or -b
, see this question more.
to around that, you'll need surround negative set of parentheses, ensure understood solr standalone negative query, like: (-(type:car , sold:true))
so:
-(type:car , sold:true)
(this doesn't result stated, per comment, don't understand stated results)(type:bike , productid:1) (-(type:car , sold:true))
(you wrote in description of problem!)(-(type:car , sold:false)) owner:(john brian josh)
Comments
Post a Comment