Django haystack: increasing search results if a search engine appears in a specific field

I use django-haystack to search on my site. My problem is that if a search query were found in a specific field, I would like to get the search results. Let's say I'm looking for blog entries, then I would like to show these results at the top where the search query was found in the header field.

I read the Senate documentation on field extension, but I don't understand how this should work.

+6
source share
1 answer

You can:

Change the index index file, for example.

class BlogEntryIndex(SearchIndex): text = CharField(document=True, use_template=True) title = CharField(model_attr='title', boost=1.125) 

NOTE. As stated in the comments, below will only be the title of the term, not the field, use the above.

or you can pass the promotion to SearchQuerySet, for example, in your haystack url file.

 sqs = SearchQuerySet().boost('title', 1.125) urlpatterns = patterns('haystack.views', url(r'^$', SearchView(searchqueryset=sqs), name='haystack_search'), ) 
+4
source

Source: https://habr.com/ru/post/901292/


All Articles