2

我正在研究人员姓名的搜索功能,该功能可以按他们开展业务的州进行过滤。有些人在多个地区做生意,所以我的问题是,如何在一个字段中存储一个州列表,以便我可以对该字段中的任何州进行精确搜索?

示例数据:

| 人名 | 国家 |
|==============|=============|
| 约翰·多伊 | 加利福尼亚州、内华达州、亚利桑那州 |
| 约翰·史密斯 | 纽约州,新泽西州 |
| ... |
|==============|=============|

这是我现在的代码:# search_indexes.py

class ProfileIndex(RealTimeSearchIndex):
    text = indexes.CharField(document=True) # the person's name
    state = indexes.CharField(faceted=True)


    def prepare_text(self, profile):
        return profile.display_name

    def prepare_state(self, profile):
        return ???????


# search code
search_string = "John"
search_state = "CA"
search_results = SearchQuerySet().models(Profile) \
            .filter(text=search_string, state=search_state) \
            .load_all()

# Should only return John Doe because of the search_state constraint...

我希望 solr 准确地解析州名,而不做任何 solr 魔术,比如词干/模糊匹配/等等...

这似乎是一个基本要求,我没有看到什么?

谢谢!

4

1 回答 1

2
state = indexes.MultiValueField()

    def prepare_state(self, obj):
        return [g.pk for g in obj.state_set.all()]
于 2012-04-24T20:15:35.513 回答