So I have the following multifields in my Solr docs (just an example).
"type": [
"Single",
"Series",
"Other association"
],
"name": [
"Name associated with first type",
"Name associated with second type",
"Name associated with third type"
]
I'm to be able to query both fields with:
name:"Name associated with third type" AND type:"Series"
But I need to query the value of name
and also match the type
value in the same array index. So the above example should not hit because "Name associated with third type" is third name
and "Series" is second in type
.
A query that should produce a hit would be this, because both values are in the same array index.
name:"Name associated with second type" AND type:"Series"
But this matches everything. I hope this was properly explained. I don't even know if this is possible.
No, not possible to match across two multi-valued fields with the same index. You will need to get all the docs that match and deal with them in the client side.
However, if you will always have the full values for both type
and name
then you can alter your schema and make it work like this.
Define a new field called type_names
which is a multi-valued string field. Modify your indexer to set values in that field like
type_names: [Single#Name associated with first type,
Series#Name associated with second type,
Other association#Name associated with third type]
I am using #
but you can use any delimiter string that works for you.
(You may want to lower case everything in your index if you want case-insensitive matching and also lower-case your query values.)
Then query this field like:
type_names:(Series#Name associated with second type)
If it so happens that you know the full value for type
but only one word in name
(say second
), then you can use regex match:
type_names:/Series#.*second.*/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With