I should have put my full model in the original post, here it is, so that you don't think i'm referencing an unknown field (modified_date). Sorry about that.
class Building(models.Model):
created_date = models.DateTimeField(default=datetime.now(), blank=False, editable=False)
modified_date = AutoDateTimeField(blank=True, editable=False)
created_by = models.ForeignKey(User)
lastmodified_by = models.ForeignKey(User, blank=True, null=True, related_name="%(app_label)s_%(class)s_related")
number = models.CharField(max_length=25, unique=True)
description = models.CharField(max_length=50, blank=True)
In my search_indexes.py file, I tried changing the field type for both number and description between CharField, EdgeNgramField, and NgramField, but none of those changed the results. I still can't match partial words.
Should I try an older version of Whoosh? I've seen a few posts that mentioned that helped.
Thanks,
-jay
On Sunday, February 10, 2013 1:23:33 AM UTC-6,
titlei...@gmail.com wrote:
Hello,
I'm trying to get the following stack setup to do partial word searching. I was following the basic tutorial in the Haystack documentation, just to get started.
Django 1.4.3
Haystack 2.0.0 (latest from git)
Whoosh 2.4.1
I've got a really simple model setup for testing.
class Building(models.Model):
number = models.CharField(max_length=25, unique=True)
description = models.CharField(max_length=50, blank=True)
My search_indexes.py file is this
class BuildingIndex(indexes.SearchIndex, indexes.Indexable):
text = indexes.CharField(document=True, use_template=True)
number = indexes.EdgeNgramField(model_attr='number')
description = indexes.EdgeNgramField(model_attr='description')
def get_model(self):
return Building
def index_queryset(self, using=None):
"""Used when the entire index for model is updated."""
return self.get_model().objects.filter(modified_date__lte=datetime.now())
Like I mentioned, full word matches work perfectly. No problems there. However, a partial search does not return any results. I've tried matching 1, 2, 3 characters and up. I completely removed my indexes and rebuilt them, multiple times, and partial matching still doesn't work. I don't need autocomplete support, just partial matches.
Is there something simple that I have missed? Or is this a lot more complicated than I realize.
Appreciate any help.
Thanks,
-jay