Re: Partial word search with Haystack and Whoosh

1,047 views
Skip to first unread message

titlei...@gmail.com

unread,
Feb 10, 2013, 2:15:11 PM2/10/13
to django-...@googlegroups.com

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

1...@a1b0n.com

unread,
Mar 1, 2013, 3:18:56 PM3/1/13
to django-...@googlegroups.com
had the same problem, changing the field to NgramField fixed it and returns partial matches. Whoosh==2.4.1

Aivis Ābele

unread,
Jul 20, 2016, 2:01:49 PM7/20/16
to django-haystack, titlei...@gmail.com
The same problem with Whoosh==2.6.0 Using NgramField didn't help.
Reply all
Reply to author
Forward
0 new messages