Commit 1d321265 authored by fred's avatar fred

improve search results by boosting some parts

parent e204655e
import datetime
from haystack import indexes
from .models import Emission, Episode, NewsItem
class EmissionIndex(indexes.SearchIndex, indexes.Indexable):
title = indexes.CharField(model_attr='title', boost=1.5)
text = indexes.CharField(document=True, use_template=True)
categories = indexes.MultiValueField(faceted=True)
def prepare(self, obj):
data = super(EmissionIndex, self).prepare(obj)
data['boost'] = 1.3
return data
def get_model(self):
return Emission
......@@ -15,6 +23,7 @@ class EmissionIndex(indexes.SearchIndex, indexes.Indexable):
class EpisodeIndex(indexes.SearchIndex, indexes.Indexable):
title = indexes.CharField(model_attr='title', boost=1.5)
text = indexes.CharField(document=True, use_template=True)
tags = indexes.MultiValueField(faceted=True)
......@@ -26,9 +35,21 @@ class EpisodeIndex(indexes.SearchIndex, indexes.Indexable):
class NewsItemIndex(indexes.SearchIndex, indexes.Indexable):
title = indexes.CharField(model_attr='title', boost=1.5)
text = indexes.CharField(document=True, use_template=True)
tags = indexes.MultiValueField(faceted=True)
def prepare(self, obj):
data = super(NewsItemIndex, self).prepare(obj)
today = datetime.datetime.today()
if obj.datetime < today - datetime.timedelta(weeks=15):
# push older news in later pages
data['boost'] = 0.8
elif obj.datetime > today - datetime.timedelta(weeks=3):
# pull recent news
data['boost'] = 1.5
return data
def get_model(self):
return NewsItem
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment