0

I'm tring to understand how haystack search works.

I hava a model Order with field Order.no where the order number is stored in a form 'ABC/2013/11/1', 'ABC/2013/11/2' ...

I want to implement autocomplete on this field using Haystack with Whoosh backend (django-haystack 2.1.0, celery-haystack 0.7.2, Whoosh 2.5.5, Django 1.6). My search_index.py looks like this:

class OrderIndex(CelerySearchIndex, indexes.Indexable):
    text = indexes.CharField(document=True, use_template=True)
    name_auto = indexes.EdgeNgramField(model_attr='name')

    def get_model(self):
        return Order

When I try

SearchQuerySet().autocomplete(name_auto='ABC/2013')

I recieve both ABC/2013/11/1 and ABC/2013/11/2 and it's ok

When I try

SearchQuerySet().autocomplete(name_auto='ABC/2013/11')

I still recieve both ABC/2013/11/1 and ABC/2013/11/2 and it's also ok but when I try

SearchQuerySet().autocomplete(name_auto='ABC/2013/11/1')

I still recieve both ABC/2013/11/1 and ABC/2013/11/2 I don't understand why.

I also notice that when I change the number format for the whole project for '1/ABC/2013/10' ... query like

SearchQuerySet().autocomplete(name_auto='1/')

doesn't return any results and query like

SearchQuerySet().autocomplete(name_auto='1/ABC')

return both '1/ABC/2013/10' and '2/ABC/2013/10'.

Maybe I'm missing something related to numbers and/or special characters in Haystack queries/ search strings. Thanks for any help.

no1
  • 925
  • 2
  • 9
  • 9

1 Answers1

0

The reason is two-fold actually: First is that the forward-slash ("/") is a reserved character in Whoosh, so it is ignored. Second is that Whoosh also ignores single character search terms.

So your query,

'ABC/2013/11/1'

if stripped off the slashes,

'ABC 2013 11 1'

and then single characters,

'ABC 2013 11'

Looks just as if you are searching for

'ABC/2013/11' -> 'ABC 2013 11'

Funny the documentation seems to be mum about this strange behavior.

bratface
  • 76
  • 4