13👍
Try this:
-(-price:[300 TO 400] AND price:[* TO *])
is logically the same and it works in Solr.
6👍
As per the SolrQuerySyntax
Pure Negative Queries:
-field:[* TO *]
finds all documents without a value for field
You can try:
q=(*:* -price:[* TO *]) OR price:[300 TO 400]
0👍
The aim was to sort some items by score based on an boosting by type and plus if a type:bike item has an image.
The result should be:
- Cars
- Boats
- Bikes with an image
- Bikes without an image
This was my first query approach:
type:"car"^10000 OR type:"boat"^5000 OR (type:"bike" AND image-type:[* TO *])^100 OR type:"bike"^5
(works fine)
But i forgot old data items without the type field. The should be in the result set like this:
- Cars
- Boats
- Bikes with an image
- Bikes without an image
- All items without a type
So i changed my query to -type:[* TO *] OR type:"car"^10000 OR type:"boat"^5000 OR (type:"bike" AND image-type:[* TO *])^100 OR type:"bike"^5
and ended up with no results.
So i found this thread and tried to change my query to -(type:[* TO *] OR -type:"car"^10000 OR -type:"boat"^5000 OR -(type:"bike" AND image-type:[* TO *])^100 OR -type:"bike"^5
) like shown in this answer https://stackoverflow.com/a/17211744/326905
But sadly all items have the same score 🙁
- How to add a default array of values to ArrayField?
- What is the correct way to deal with DB migration while using South, Django and Git?
- Translating formatted strings in Django not working
- Django: Save user uploads in seperate folders
0👍
The double negated query suggested by Maurizio may cause error:
unexpected docvalues type NUMERIC for field 'price' (expected one of [SORTED, SORTED_SET]). Re-index with correct docvalues type.
(Even after re-indexing. This may have something to do with the index
and store
and docvalues
settings of the field.)
What you could do instead is exempt both ranges (before and after) of the values you are actually interested in:
-(price:[* TO 300} price:{400 TO *])
Note that values 300 and 400 are excluded by using curly brackets in this negated query and are thus included in the search results.
-1👍
One can use a filter query
if you do not care about the document score and want to leverage the filter cache, like:
?q=*:*&fq=((-price:[* TO *]) or (price:[300 TO 400]))
- Celery: launch task on start
- Django: datetime filter by date ignoring time
- Problem reusing serializers with django and drf-yasg