search: boost title value (#21025)

This commit is contained in:
Frédéric Péters 2018-01-06 17:22:33 +01:00
parent ba95fb474f
commit 2efc30d897
3 changed files with 4 additions and 6 deletions

View File

@ -1,6 +1,4 @@
{% autoescape off %}
{{object.title}}
{% for cell in object.get_cells %}
{{ cell.render_for_search }}
{% endfor %}

View File

@ -35,7 +35,8 @@ from django.views.decorators.csrf import csrf_exempt
from django.utils.translation import ugettext as _
from django.forms.widgets import Media
from haystack.query import SearchQuerySet
from haystack.inputs import AutoQuery
from haystack.query import SearchQuerySet, SQ
if 'mellon' in settings.INSTALLED_APPS:
from mellon.utils import get_idps
@ -405,8 +406,8 @@ def api_search(request):
else:
raise Http404()
query = request.GET.get('q') or ''
searchqueryset = SearchQuerySet()
sqs = searchqueryset.auto_query(query).highlight()
sqs = SearchQuerySet().filter(SQ(content=AutoQuery(query)) | SQ(title=AutoQuery(query)))
sqs = sqs.highlight()
sqs.load_all()
hits = []
for hit in sqs:

View File

@ -187,7 +187,6 @@ def test_search_contents_index():
cell.save()
prepared_data = page_index.prepare(page)
assert page.title in prepared_data['text']
assert 'foobar' in prepared_data['text']
def test_search_api(app):