Haystack 中的精确查询匹配不起作用
Exact Query Match in Haystack not working
我有一个以关键字作为多值字段的产品索引
class ProductIndex(indexes.SearchIndex, indexes.Indexable):
text = indexes.CharField(document=True, use_template=True)
keywords = indexes.MultiValueField(faceted=True)
def prepare_keywords(self, product):
return [p.name for p in product.tags.all()]
我需要找到关键字与 lightning
完全相同的产品。我使用这个查询 -
SearchQuerySet().models(Product).filter(keywords__exact=u'Lighting')
但这也为我提供了包含 lightning
作为单词一部分的产品。喜欢
print SearchQuerySet().models(Product).filter(keywords__exact=u'Lighting')[1].keywords
[u'LED lighting', u'Optic Lighting']
正确的做法是什么?
看看example/solr/collection1/conf/schema.conf
<field name="keywords" type="text_en" indexed="true" stored="true" multiValued="true" />
我认为 exact 仅适用于字符串字段而不适用于文本字段。您必须像这样编辑此配置并创建关键字字段:
<field name="keywords" type="string" indexed="true" stored="true" multiValued="true" />
我有一个以关键字作为多值字段的产品索引
class ProductIndex(indexes.SearchIndex, indexes.Indexable):
text = indexes.CharField(document=True, use_template=True)
keywords = indexes.MultiValueField(faceted=True)
def prepare_keywords(self, product):
return [p.name for p in product.tags.all()]
我需要找到关键字与 lightning
完全相同的产品。我使用这个查询 -
SearchQuerySet().models(Product).filter(keywords__exact=u'Lighting')
但这也为我提供了包含 lightning
作为单词一部分的产品。喜欢
print SearchQuerySet().models(Product).filter(keywords__exact=u'Lighting')[1].keywords
[u'LED lighting', u'Optic Lighting']
正确的做法是什么?
看看example/solr/collection1/conf/schema.conf
<field name="keywords" type="text_en" indexed="true" stored="true" multiValued="true" />
我认为 exact 仅适用于字符串字段而不适用于文本字段。您必须像这样编辑此配置并创建关键字字段:
<field name="keywords" type="string" indexed="true" stored="true" multiValued="true" />