Reputation: 1658
I have documents that has multivalue fields in my solr. I want to make search according to these multivalue fields. When I want to query with;
http://localhost:8983/solr/demo/select?q=*:*&fq=id:FEAE38C2-ABFF-4F0C-8AFD-9B8F51036D8A
it gives me the following query result.
response": {
"numFound": 1,
"start": 0,
"docs": [
{
"created_date": "2016-03-23T13:47:46.55Z",
"solr_index_date": "2016-04-01T08:21:59.78Z",
"TitleForUrl": "it-s-a-wonderful-life",
"modified_date": "2016-03-30T08:45:44.507Z",
"id": "FEAE38C2-ABFF-4F0C-8AFD-9B8F51036D8A",
"title": "It's a wonderful life",
"article": "An angel helps a compassionate but despairingly frustrated businessman by showing what life would have been like if he never exis",
"Cast": [
"James Stewart",
"Donna Reed",
"Lionel Barrymore"
],
"IsCastActive": [
"false",
"true",
"true"
]
}
]
}
As you see I have 2 maltivalue fields that are named "Cast" and "IsCastActive". My problem is When I add filters like Cast:"James Stewart" AND IsCastActive = "true" like the following:
http://localhost:8983/solr/demo/select?q=*:*&fq=id:FEAE38C2-ABFF-4F0C-8AFD-9B8F51036D8A&fq=Cast:"James Stewart"&fq=IsCastActive:"true"
Solr still gives the same result but "James Stewart" is not active in the document. So, I don't want Solr to response any document acconding to my query. I think I'm doing something wrong. What's the correctly way to do it?
Upvotes: 0
Views: 2211
Reputation: 5005
I want to propose an alternative solution to your problem. Such solution stores true/false as payloads integers. So the idea is to have a field called cast having a definition in the schema like:
<field name="cast" type="payloads" indexed="true" stored="true"/>
<fieldtype name="payloads" stored="false" indexed="true" class="solr.TextField" >
<analyzer>
<tokenizer class="solr.WhitespaceTokenizerFactory"/>
<filter class="solr.DelimitedPayloadTokenFilterFactory" encoder="integer"/>
</analyzer>
<similarity class="payloadexample.PayloadSimilarityFactory" />
</fieldtype>
The content can be indexed for instance as:
James Stewart|0
Donna Reed|1
where 0/1 is true/false. Using payloads would also allow you to read directly from the posting list improving your performance on relevant queries. Here you can find an example explaining how to achieve what I explained above.
Upvotes: 0
Reputation: 2156
This does not look much possible in a straight forward manner here in Solr . But i think more effective way would be that you keep your Cast member's name as key , and then associate it with the value as true , or false and then filter on your username as key . Something like this : James Stewart :["true"]
. Or may be you can use a single field that store cast name and his/her activity status delimited by a colon .
. Something like this castInfo:["James Stewart:false","John Sanders:true"]
. You can filter on it then by something like this fq=castInfo:"James Stewart:false"
.
Upvotes: 1