gpt4 book ai didi

django - 干草堆:仅突出显示一个字段

转载 作者:行者123 更新时间:2023-12-02 22:51:28 25 4
gpt4 key购买 nike

我正在使用 Haystack 2.3.0 ,并且具有类似以下的搜索索引:

class MyModelIndex(indexes.SearchIndex, indexes.Indexable):
text = indexes.CharField(document=True, use_template=True)
name = indexes.EdgeNgramField(model_attr='name', boost=1.250)
short_description = indexes.CharField(model_attr='short_description', null=True, boost=1.125)
description = indexes.CharField(model_attr='description', null=True, boost=1.125)
detail_description = indexes.CharField(model_attr='detail_description', null=True)

def get_model(self):
return MyModel

我只想突出显示字段 detail_description 。我已经在 official documentation中阅读了以下示例:
sqs = SearchQuerySet().filter(content='foo').highlight()
result = sqs[0]
result.highlighted['text'][0]

但是,当我尝试这样做时,不会得到相同的结果。在上面的示例中, result.highlighted似乎是 字典,您可以在其中访问 每个字段的突出显示:
result.highlighted['text'][0]

但是在我的示例中,当我执行相同操作时, result.highlighted不是字典,而是列表,并且仅返回 text字段的突出显示。
  • 如何将突出显示设置为具体字段?
  • 最佳答案

    If the number_of_fragments value is set to 0 then no fragments are produced, instead the whole content of the field is returned, and of course it is highlighted. This can be very handy if short texts (like document title or address) need to be highlighted but no fragmentation is required. Note that fragment_size is ignored in this case.





    链接- http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-request-highlighting.html

    您需要查看如何在haystack中更改此参数。

    关于django - 干草堆:仅突出显示一个字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27655369/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com