I’m working on a search feature for people names, that is filterable by the state in which they do business. Some people do business in multiple regions, so my question is, how do store a list of states in a field in a way that allows me to do an exact search on any states in that field?
Example Data:
| Person Name | States | |=============|============| | John Doe | CA, NV, AZ | | John Smith | NY, NJ | | ... | |=============|============|
Here’s my code now:
# 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...
I’d like solr to parse the state names exactly, without doing any solr magic like stemming/fuzzy matching/etc…
This seems like a basic request, what am I not seeing?
Thanks!
1 Answer