Skip to content
This repository has been archived by the owner on Mar 15, 2018. It is now read-only.

Commit

Permalink
Fixed app lookup search for multi-word queries (bug 767571)
Browse files Browse the repository at this point in the history
Fuzzy searches use Levenshtein distance and don't tokenize the input. So
in the case of this bug, searching for "mozilla marketplace" tried to
compare the edit distance of "mozilla marketplace" to "mozilla" (and
"marketplace" separately). But the edit distance of both of these was
more than the default minimum of smallest word in the query string
("mozilla" = 7 words). So it assumed these were too far apart.

This patch adds a text query so either should match for a result.
  • Loading branch information
robhudson authored and cvan committed Jul 11, 2012
1 parent 5a5374f commit 60e5c72
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
7 changes: 7 additions & 0 deletions mkt/lookup/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,13 @@ def test_by_name_part(self):
data = self.search('steamcube')
self.verify_result(data)

def test_multiword(self):
self.app.name = 'Mozilla Marketplace'
self.app.save()
self.refresh()
data = self.search('mozilla marketplace')
self.verify_result(data)

def test_by_stem_name(self):
self.app.name = 'Instigation'
self.app.save()
Expand Down
4 changes: 3 additions & 1 deletion mkt/lookup/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,9 @@ def app_search(request):
qs = Addon.objects.filter(guid=query).values(*non_es_fields)
if not qs.count():
# Give up on GUID, assume it's a search.
qs = Addon.search().query(name__fuzzy=query).values_dict(*fields)
qs = (Addon.search().query(or_=dict(name__text=query,
name__fuzzy=query))
.values_dict(*fields))
for app in qs:
app['url'] = reverse('lookup.app_summary', args=[app['id']])
# ES returns a list of localized names but database queries do not.
Expand Down

0 comments on commit 60e5c72

Please sign in to comment.