0

My SearchIndex looks like this:

class AccountIndex(indexes.SearchIndex)
    account=indexes.CharField(model_attr='account_number')
    name=indexes.CharField(model_attr='business_name')

An account number has 7 numeric characters. I can seem to do a partial search on "name", but not on "account":

In [20]: SearchQuerySet().filter(name='Cjns, LLC')
Out[20]: [<SearchResult: accounts.soldtoaccount (pk=u'367')>]

In [21]: SearchQuerySet().filter(name='Cjns')
Out[21]: [<SearchResult: accounts.soldtoaccount (pk=u'367')>]

In [22]: SearchQuerySet().filter(account='11836052')
Out[22]: [<SearchResult: accounts.soldtoaccount (pk=u'367')>]

In [23]: SearchQuerySet().filter(account='118360')
Out[23]: []

In [24]: SearchQuerySet().filter(account='11836052')[0].account
Out[24]: u'11836052'

I know can use account__startswith in filter(), but I'd also like to be able to search partial account numbers using auto_query:

In [14]: SearchQuerySet().auto_query('Cjn')
Out[14]: [<SearchResult: accounts.soldtoaccount (pk=u'367')>]

In [15]: SearchQuerySet().auto_query('11836052')
Out[15]: [<SearchResult: accounts.soldtoaccount (pk=u'367')>]

In [16]: SearchQuerySet().auto_query('118360')
Out[16]: []

Do I need to use a different type of index field for the account number?

Ben Davis
  • 13,112
  • 10
  • 50
  • 65

1 Answers1

0

Use NgramField or EdgeNgramField rather than CharField.

http://django-haystack.readthedocs.org/en/latest/autocomplete.html

Nagra
  • 466
  • 3
  • 8