Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/23.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\uuu包含未找到通过GET[ElasticSearch backeng]传递的子字符串_Django_<img Src="//i.stack.imgur.com/RUiNP.png" Height="16" Width="18" Alt="" Class="sponsor Tag Img">elasticsearch_Django Haystack - Fatal编程技术网 elasticsearch,django-haystack,Django,elasticsearch,Django Haystack" /> elasticsearch,django-haystack,Django,elasticsearch,Django Haystack" />

Django Haystack\uuu包含未找到通过GET[ElasticSearch backeng]传递的子字符串

Django Haystack\uuu包含未找到通过GET[ElasticSearch backeng]传递的子字符串,django,elasticsearch,django-haystack,Django,elasticsearch,Django Haystack,我有以下型号: class ProductIndex(CelerySearchIndex, indexes.Indexable): text = indexes.CharField(document=True, use_template=True) number = indexes.CharField() description = indexes.CharField(model_attr='description') 在我的网页中,我对一个函数执行了一个AJAX调用,

我有以下型号:

class ProductIndex(CelerySearchIndex, indexes.Indexable):
    text = indexes.CharField(document=True, use_template=True)
    number = indexes.CharField()
    description = indexes.CharField(model_attr='description')
在我的网页中,我对一个函数执行了一个AJAX调用,该函数应该会将产品的描述返回给我,这些产品的描述中包含了一些使用类型的单词。例如,如果我有一个描述为“Apple Macbook Pro”的产品,而用户键入“book”,我希望返回该结果

我执行以下操作:

q = request.GET['q']
results = SearchQuerySet().models(Product).filter(description__contains=q)
然而,正如我所说,我确实有一个产品,其描述如下:

Macbook
和用户类型
book
,它将无法工作。但是,
Macbook
将起作用


最后,如果我打印
q
,它将返回
u'book'

,您可以使用
索引.EdgeNgramField
而不是
索引.CharField
。自动完成文档()中建议了这一点

您不需要更改查询代码

编辑:

要使它不区分大小写,您可以这样做

class ProductIndex(CelerySearchIndex, indexes.Indexable):
    ... fields here ...
    def prepare_description(self, object):
        return object.description.lower()

q
上查询使用
lower()
时,可以使用
索引.EdgeNgramField
而不是
索引.CharField
。自动完成文档()中建议了这一点

您不需要更改查询代码

编辑:

要使它不区分大小写,您可以这样做

class ProductIndex(CelerySearchIndex, indexes.Indexable):
    ... fields here ...
    def prepare_description(self, object):
        return object.description.lower()

当查询时,在
q

上使用
lower()!但是,它是区分大小写的。。。如何解决这个问题?如果在
prepare
中使用
lower
,并且该字段是一个刻面字段,则在刻面UI中,它将返回看起来难看的小写项目:/n内存处理和包含的内容类似,但不相同。这不是一个正确的答案。很好,它起作用了!但是,它是区分大小写的。。。如何解决这个问题?如果在
prepare
中使用
lower
,并且该字段是一个刻面字段,则在刻面UI中,它将返回看起来难看的小写项目:/n内存处理和包含的内容类似,但不相同。这不是一个正确的答案。