I'm using django-haystack for searching on my site. My problem is, I would like to have search results on top if the search term was found in a specific field. Let's say I search for blog-entries, then I would like to show those results on top where the search term was found in the title field.
I read the haystack documentation about field-boosting but i don't understand how it should work.
You can either:
Amend your search index file e.g.
class BlogEntryIndex(SearchIndex):
text = CharField(document=True, use_template=True)
title = CharField(model_attr='title', boost=1.125)
NOTE: As pointed out in the comments the below would only boost the term title not the field, use the above.
or you can pass the boost to your SearchQuerySet e.g in your haystack urls file.
sqs = SearchQuerySet().boost('title', 1.125)
urlpatterns = patterns('haystack.views',
url(r'^$', SearchView(searchqueryset=sqs), name='haystack_search'),
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With