Skip to content

Commit

Permalink
Changes for better relevancy score in haystack search.
Browse files Browse the repository at this point in the history
  • Loading branch information
wkarpeta committed Jan 28, 2014
1 parent e051225 commit 172e48d
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
7 changes: 7 additions & 0 deletions apps/gcd/search_indexes.py
Expand Up @@ -14,6 +14,7 @@ def get_updated_field(self):

class IssueIndex(ObjectIndex, indexes.SearchIndex, indexes.Indexable):
text = indexes.CharField(document=True, use_template=True)
title = indexes.CharField(model_attr="title", boost=15.0)
facet_model_name = indexes.CharField(faceted=True)

def get_model(self):
Expand All @@ -25,6 +26,7 @@ def prepare_facet_model_name(self, obj):

class SeriesIndex(ObjectIndex, indexes.SearchIndex, indexes.Indexable):
text = indexes.CharField(document=True, use_template=True)
name = indexes.CharField(model_attr="name", boost=15.0)
facet_model_name = indexes.CharField(faceted=True)

def get_model(self):
Expand All @@ -36,6 +38,7 @@ def prepare_facet_model_name(self, obj):

class StoryIndex(ObjectIndex, indexes.SearchIndex, indexes.Indexable):
text = indexes.CharField(document=True, use_template=True)
title = indexes.CharField(model_attr="title", boost=15.0)
facet_model_name = indexes.CharField(faceted=True)

def get_model(self):
Expand All @@ -50,6 +53,7 @@ class PublisherIndex(ObjectIndex, indexes.SearchIndex, indexes.Indexable):
use_template=True,
template_name=
'search/indexes/gcd/publisher_text.txt')
name = indexes.CharField(model_attr="name", boost=15.0)
facet_model_name = indexes.CharField(faceted=True)

def get_model(self):
Expand All @@ -65,6 +69,7 @@ class IndiciaPublisherIndex(ObjectIndex, indexes.SearchIndex,
use_template=True,
template_name=
'search/indexes/gcd/publisher_text.txt')
name = indexes.CharField(model_attr="name", boost=15.0)
facet_model_name = indexes.CharField(faceted=True)

def get_model(self):
Expand All @@ -79,6 +84,7 @@ class BrandIndex(ObjectIndex, indexes.SearchIndex, indexes.Indexable):
use_template=True,
template_name=
'search/indexes/gcd/publisher_text.txt')
name = indexes.CharField(model_attr="name", boost=15.0)
facet_model_name = indexes.CharField(faceted=True)

def get_model(self):
Expand All @@ -93,6 +99,7 @@ class BrandGroupIndex(ObjectIndex, indexes.SearchIndex, indexes.Indexable):
use_template=True,
template_name=
'search/indexes/gcd/publisher_text.txt')
name = indexes.CharField(model_attr="name", boost=15.0)
facet_model_name = indexes.CharField(faceted=True)

def get_model(self):
Expand Down
7 changes: 3 additions & 4 deletions apps/gcd/urls.py
Expand Up @@ -3,9 +3,8 @@
from django.conf import settings
from django.views.generic.simple import direct_to_template
from haystack.forms import FacetedSearchForm
from haystack.query import SearchQuerySet
from haystack.views import FacetedSearchView, search_view_factory
from apps.gcd.views.search_haystack import PaginatedFacetedSearchView
from haystack.views import search_view_factory
from apps.gcd.views.search_haystack import PaginatedFacetedSearchView, GcdSearchQuerySet


urlpatterns = patterns('',
Expand Down Expand Up @@ -238,7 +237,7 @@
)

# haystack search
sqs = SearchQuerySet().facet('facet_model_name')
sqs = GcdSearchQuerySet().facet('facet_model_name')

urlpatterns += patterns('haystack.views',
url(r'^searchNew/', search_view_factory(
Expand Down
7 changes: 7 additions & 0 deletions apps/gcd/views/search_haystack.py
@@ -1,13 +1,20 @@
from haystack.views import FacetedSearchView
from apps.gcd.views import ResponsePaginator
from haystack.query import SearchQuerySet

class GcdSearchQuerySet(SearchQuerySet):
def auto_query(self, query_string, fieldname='content'):
return self

class PaginatedFacetedSearchView(FacetedSearchView):
def __call__(self, request):
self.request = request

self.form = self.build_form()
self.query = self.get_query()
#TODO List of fields to add in filter_or should be gathered automatically from our SearchIndex classes
self.form.searchqueryset = self.form.searchqueryset.filter_or(content=self.query).filter_or(name=self.query).filter_or(title=self.query)

self.results = self.get_results()

self.paginator = ResponsePaginator(self.results,
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Expand Up @@ -17,6 +17,6 @@ git+git://github.com/GrandComicsDatabase/django-mobile.git
python-stdnum
wsgiref
pyelasticsearch
django-haystack
django-haystack<2.1.0
python-dateutil
git+git://github.com/bennylope/elasticstack.git
git+git://github.com/bennylope/elasticstack.git

0 comments on commit 172e48d

Please sign in to comment.