Reputation: 472
In Solr it is possible to query for any value in a certain field with a query such as field:*
. I would like to be able to perform the inverse of this such that I can add a value to a document (*
) that causes it to match any query on that field.
For instance, the following document:
{
"a": 1,
"b": *,
"c": *
}
should match these queries:
b:5
b:[9 TO 11]
a:1
c:foo
but not these queries:
a:4
The reason I want to do this is so that whenever a user searches for a:1
the document will be matched no matter what other conditions are specified. I can achieve this by editing the query but would prefer not to. Is there a way to do this?
Upvotes: 0
Views: 51
Reputation: 9789
You could probably do something similar with Solr switch statement (reference, example). You pass your condition in a variable different from standard Solr and then switch on the values/presence/absence in that variable.
I use that for advanced multi-field search and don't use actual value, just presence or absence of value as a way to trigger a Solr condition.
Upvotes: 0
Reputation: 26713
This is a bit of a strange request. Effectively what you want is to make a certain field useless as with this sort of logic, any data for this field becomes irrelevant (as the query will match it no matter what is persisted). Anyway, this should be possible.
In Lucene, you could do the following:
b
, e.g. set the value to MatchAllValuesNoMatterWhatTheWeatherIs
public Query rewrite(IndexReader reader)
methodb
(if it exists) into b:MatchAllValuesNoMatterWhatTheWeatherIs
. Other terms should remain untouched.Upvotes: 1