Solr query based on a string field's subset
I'd like to send a string to Solr and let it answer with all records which are a subset of that string.
The string I would send has intege开发者_如何学Cr numbers separated by spaces. I wanna make solr give me all records where a specific string field is a subset of the numbers I provide as the request string.
An example...
Imagine I have an string field indexed in Solr which is in reality a set of integers separated by space. For example, let's say I have the following record's field indexed in Solr:
- "888110"
- "888110 888120"
- "888110 888120 888130"
- "888110 888120 888130 888140"
- "888110 888130 888140"
- "888110 888140"
- "888140"
- "888120 888130"
I wanna Solr to receive a query with, for example, "888110 888140" and reply with the following records:
- "888110"
- "888110 888140"
- "888140"
If I query by "888110 888120 888130" the retrieved records would be...
- "888110"
- "888110 888120"
- "888110 888120 888130"
- "888120 888130"
The retrieved records must be exactly a subset of the numbers provided as a string.
Is it possible to make Solr behave like this?
I'm a bit confused why in the first example "888110" is not returned, but it is in the second example.
Anyways, if I understand generally what you are trying to do, I would be making a new field multi valued
and use your boolean operators (AND ,OR) on the query.
eg in the schema
<field name="code_string" ... />
<field name="codes" ... multiValued="true"/>
so you have a document like
<doc>
<arr name="codes">
<str>811001</str>
<str>811002</str>
</arr>
and in your query
?=codes=811001 OR codes=811002 OR ....
In my experience with solr it is generally cleaner / more maintainable to sacrifice a little memory rather than creating debilitatingly complex chains of filters etc
精彩评论