: What I don't like is that it systematically uses the positive version. : Sometimes the negative version will give many less results (for example, : in some cases I filter by documents not having a given field, and there : are very few of them). I think it would be much better that solr
the "positive" version of the filter is the only one that can be executed, so it's the one that gets cached today, but the principle you are describing is still sound -- in fact I'm pretty sure there is a note in the code about this exact idea as a possible performance enhancment: if the cardinality of a filter is very large (regardless of wether the query was "positive" or "negative") it's negative relative the set of all docs could be cached in it's place to save space... ...but... ...the complication would comes later when doing lookups -- for cache lookups to work with an arbitrary query, you would either need to changed the cache structure from Query=>DocSet to a mapping of Query=>[DocSet,inverseionBit] and store the same cache value needs needs with two keys -- both the positive and the negative; or you keep the current cache structure, store whichever Query=>DocSet pair has the smallest cardinality, but then every logical cache lookup requires a second actual cache lookup under the covers (for the negation of the query) if the first one doesn't match anything. it would require some benchmarking and hard decisions about whether the (hypothetical) memory savings are worth the (hypothetical) CPU cost. : query that in fact returns the "negative" results. As a simple example, : I believe that, for a boolean field, -field:true is exactly the same as : +field:false, but the former is a negative query and the latter is a that's not strictly true in all cases... * if the field is multivalued=true, a doc may contain both "false" and "true" in "field", in which case it would match +field:false but it would not match -field:true * if the field is not multivalued-false, and required=false, a doc may not contain any value, in which case it would match -field:true but it would not match +field:false -Hoss