Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/solr/3.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
Django Haystack中的精确查询匹配不起作用_Django_Solr_Django Haystack - Fatal编程技术网

Django Haystack中的精确查询匹配不起作用

Django Haystack中的精确查询匹配不起作用,django,solr,django-haystack,Django,Solr,Django Haystack,我有一个以关键字作为多值字段的产品索引 class ProductIndex(indexes.SearchIndex, indexes.Indexable): text = indexes.CharField(document=True, use_template=True) keywords = indexes.MultiValueField(faceted=True) def prepare_keywords(self, product): retu

我有一个以关键字作为多值字段的产品索引

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" />

我认为确切的方法只适用于字符串字段,而不适用于文本字段。您必须编辑此配置并创建关键字字段,如下所示:

<field name="keywords" type="string" indexed="true" stored="true" multiValued="true" />


你有
准备关键字的方法吗?@tobltobs-是的,因为它有多个值,所以我正在传递该产品的关键字列表使用搜索后端和haystack版本更新你的问题。@iamkhush不知道你的“准备关键字”方法看起来如何,我们只能猜测。我猜你会把每一个单词都分成两部分,然后把它们作为值输入。如果是,则必须引入一个包含完整字符串的新索引字段。我可以再猜一下这个应该是什么样子…@tobltobs-是的,我提供了一个关键字列表。我添加了一个准备关键字的方法。太棒了!!有没有黑客在haystack上设置这个?@iamkhush这是solr配置,haystack只使用solr配置的字段。您必须修复solr配置。