filtering the boolean query results in lucene

59 Views Asked by At

I have the solr json response as follows,

{
     "stateOrProvinceId":"TN",
     "entityType":"hotelInfo",
     "chainCode":"SM",
     "marketerName":"InnLink",
     "propertyId":"4380",
     "marketerId":"INNLINK",
     "propertyStatus":"Active",
     "chainName":"Innlink",
     "propertyName":"Value Place Memphis NE",
     "countryCode":"US"},
{
     "entityType":"hotelInfo",
     "chainCode":"GT",
     "marketerName":"Golden Tulip",
     "propertyId":"69170",
     "marketerId":"GOLDENT",
     "propertyStatus":"Active",
     "chainName":"Golden Tulip Hotels",
     "propertyName":"Tulip Inn Sunny Hill",
     "countryCode":"RO"},
{
     "stateOrProvinceId":"TN",
     "entityType":"hotelInfo",
     "chainCode":"BW",
     "marketerName":"Best Western",
     "propertyId":"85336",
     "marketerId":"BESTWEST",
     "propertyStatus":"Active",
     "chainName":"Best Western Intl",
     "propertyName":"BEST WESTERN Brentwood",
     "countryCode":"US"},
{
     "entityType":"amenitiesInfo",
     "propertyId":"69170",
     "amenitiesInfoAttrId":"AC"},

We are searching for the specific property-id for that we are using the below boolean query,

BooleanQuery booleanQuery = new BooleanQuery(); 
booleanQuery.add(new TermQuery(new Term("propertyId", pid)), BooleanClause.Occur.SHOULD);

Which is giving the below response,

{
     "entityType":"hotelInfo",
     "chainCode":"GT",
     "marketerName":"Golden Tulip",
     "propertyId":"69170",
     "marketerId":"GOLDENT",
     "propertyStatus":"Active",
     "chainName":"Golden Tulip Hotels",
     "propertyName":"Tulip Inn Sunny Hill",
     "countryCode":"RO"},

{
     "entityType":"amenitiesInfo",
     "propertyId":"69170",
     "amenitiesInfoAttrId":"AC"},

Now i need a query to get only hotelInfo with out amenitiesInfo.

Thanks in advance for the help. Raghavan

1

There are 1 best solutions below

2
On

I don't know if I'm getting it right, from what I understood you want to construct a query based on two criteria: pid and entityType, if you want to do so you should add an other TermQuery to your BooleanQuery on entityType you should try something like the following :

BooleanQuery booleanQuery = new BooleanQuery(); 
booleanQuery.add(new TermQuery(new Term("propertyId", pid)), BooleanClause.Occur.SHOULD);
booleanQuery.add(new TermQuery(new Term("entityType", "hotelInfo")), BooleanClause.Occur.SHOULD);