Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Commit

Permalink
Allow searching for parts of the URL (bug 572109)
Browse files Browse the repository at this point in the history
  • Loading branch information
Fred Wenzel committed Jun 16, 2010
1 parent a4f383e commit df9272d
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions apps/search/search_indexes.py
@@ -1,3 +1,5 @@
from urlparse import urlparse

from haystack.indexes import *
from haystack import site

Expand All @@ -14,4 +16,22 @@ class OpinionIndex(SearchIndex):
os = CharField(model_attr='os')
locale = CharField(model_attr='locale')

def prepare_text(self, obj):
"""Include URL parts in searchable text."""
indexable = [obj.description]
if obj.url:
parsed = urlparse(obj.url)
# Domain
domain_split = parsed.netloc.split('.')
if domain_split and domain_split[0] == 'www':
indexable += domain_split[1:]
indexable.append('.'.join(domain_split[1:]))
else:
indexable += domain_split
indexable.append(parsed.netloc)

# Path
indexable += parsed.path.split('/')
return "\n".join(indexable)

site.register(Opinion, OpinionIndex)

0 comments on commit df9272d

Please sign in to comment.