Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Django Haystack精确查询未按预期运行_Python_Django_Django Haystack_Whoosh - Fatal编程技术网

Python Django Haystack精确查询未按预期运行

Python Django Haystack精确查询未按预期运行,python,django,django-haystack,whoosh,Python,Django,Django Haystack,Whoosh,我正在使用django haystack与嗖嗖声的精确匹配来过滤,并得到意想不到的结果 search_index.py views.py 我希望上面的搜索是这样的:按查询搜索,其中asset_type等于brand_asset,brand为b.name。所以一切都在一起了 事实上,品牌并不精确。例如,如果我选择卡夫奶酪或卡夫macn奶酪,我会得到相同的结果,即使这是两个不同的品牌 TLDR-我的搜索不限于搜索索引文件中的品牌字段 使现代化 我也用Elasticsearch得到了同样的结果 cla

我正在使用django haystack与嗖嗖声的精确匹配来过滤,并得到意想不到的结果

search_index.py

views.py

我希望上面的搜索是这样的:按查询搜索,其中asset_type等于brand_asset,brand为b.name。所以一切都在一起了

事实上,品牌并不精确。例如,如果我选择卡夫奶酪或卡夫macn奶酪,我会得到相同的结果,即使这是两个不同的品牌

TLDR-我的搜索不限于搜索索引文件中的品牌字段

使现代化 我也用Elasticsearch得到了同样的结果

class AssetIndex(indexes.SearchIndex, indexes.Indexable):
    text = indexes.CharField(document=True, use_template=True)        
    asset_type = indexes.CharField(model_attr='asset_type')        
    brand = indexes.CharField(model_attr='brand')

    def prepare_brand(self, obj):
          return obj.brand.name

    def index_queryset(self, using=None):
          """Used when the entire index for model is updated."""
          return self.get_model().objects.filter(created_on__lte=datetime.datetime.now())
    assets = SearchQuerySet().models(Asset)
    assets = assets.filter(
                    content=query, asset_type=Exact('brand_asset'))
    assets = assets.filter(brand=Exact(b.name))