how to filter search by values that are not available

后端 未结 5 2399
逝去的感伤
逝去的感伤 2021-02-20 06:11

I have a list of items as:

i = SearchQuerySet().models(Item)

now, each item in i has a attribute, price

I wan

5条回答
  •  别跟我提以往
    2021-02-20 06:46

    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:

    1. Cars
    2. Boats
    3. Bikes with an image
    4. 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:

    1. Cars
    2. Boats
    3. Bikes with an image
    4. Bikes without an image
    5. 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 :(

提交回复
热议问题