Django干草堆问题与小搜索条件

时间:2014-06-30 15:43:11

标签: python django django-haystack whoosh

我有一个带有注释字段的对象,上面写着“WV Test Two”

当我搜索“WV”,“测试”,“两个”或其中任何一个的组合时,我想提出这个问题。我正在使用Haystack和Whoosh后端。似乎只要“WV”包含在搜索中,即使其中有另一个关键字,它也不会返回任何内容。

>>> from haystack.query import SearchQuerySet as sqs
>>> results = sqs().filter(content='wv')
>>> results
[]
>>> results = sqs().filter(content='wv test')
>>> results
[]
>>> results = sqs().filter(content='test') # this works
>>> results
[<SearchResult: drives.files ... ]
>>> results = sqs().filter(content='two') # this also works
>>> results
[<SearchResult: drives.files ... ]
>>> results = sqs().filter(content='test two') # as does this
>>> results
[<SearchResult: drives.files ... ]
>>> results = sqs().filter(content='wv two')
>>> results
[]
>>> results = sqs().filter(content='wv test two')
>>> results
[]

我假设它是因为它只有2个字符。有没有什么办法解决这一问题?我希望所有这些查询都包含“WV Test Two”。

class Drives(models.Model):
    serial = models.CharField(primary_key=True, max_length=100)
    notes = models.TextField(blank=True)
    username = models.CharField(max_length=20, blank=True)

在我的search_indexes.py中:

class DrivesIndex(indexes.SearchIndex, indexes.Indexable):
    text = indexes.NgramField(document=True, use_template=True)

drives_text.txt:

{{ object.serial }}
{{ object.notes }}

0 个答案:

没有答案