2
我正在研究人名的搜索功能,該功能可以由他們開展業務的州進行篩選。有些人在多個地區開展業務,所以我的問題是,如何在域中存儲一個狀態列表,以便我可以對該域中的任何狀態進行精確搜索?Django Haystack/Solr:根據包含狀態列表的字段篩選結果
示例數據:
| Person Name | States | |=============|============| | John Doe | CA, NV, AZ | | John Smith | NY, NJ | | ... | |=============|============|
這裏是我現在的代碼: #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的魔法一樣詞幹/模糊匹配/等...
這似乎是一個基本要求,我沒有看到什麼?
謝謝!
完美,謝謝你的幫助! – 2012-04-24 21:54:22
不用客氣 – bmihelac 2012-04-25 05:43:55