Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions apps/search/tests/test_es.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,45 @@ def test_tasks_squashed(self, index_fun):
eq_(index_fun.call_count, 1)


class ElasticSearchViewPagingTests(ElasticTestCase):
client_class = LocalizingClient

def test_front_age_search_paging(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you accidentally a p.

# Create 30 documents
for i in range(30):
doc = document(
title=u'How to fix your audio %d' % i,
locale=u'en-US',
category=10,
save=True)
doc.tags.add(u'desktop')
rev = revision(document=doc, is_approved=True, save=True)

# Create 20 questions
for i in range(20):
ques = question(title=u'audio', content=u'audio bad.', save=True)
ques.tags.add(u'desktop')
ans = answer(question=ques, save=True)
ansvote = answervote(answer=ans, helpful=True, save=True)

self.refresh()

response = self.client.get(reverse('search'), {
'q_tags': 'desktop', 'product': 'desktop', 'q': 'audio',
'format': 'json'
})
eq_(200, response.status_code)
content = json.loads(response.content)

# Make sure there are 20 results.
eq_(content['total'], 20)

# Make sure only 10 of them are kb.
docs = [mem for mem in content['results']
if mem['type'] == 'document']
eq_(len(docs), 10)


class ElasticSearchViewTests(ElasticTestCase):
client_class = LocalizingClient

Expand Down
13 changes: 10 additions & 3 deletions apps/search/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ def search_with_es(request, template=None):
r['language'] = language
r['a'] = '1'

# TODO: Rewrite so SearchForm is unbound initially and we can use `initial`
# on the form fields.
# TODO: Rewrite so SearchForm is unbound initially and we can use
# `initial` on the form fields.
if 'include_archived' not in r:
r['include_archived'] = False

Expand Down Expand Up @@ -234,8 +234,15 @@ def search_with_es(request, template=None):
if cleaned['w'] & constants.WHERE_WIKI:
if cleaned_q:
wiki_s = wiki_s.query(cleaned_q)

# For a front-page non-advanced search, we want to cap the kb
# at 10 results.
if a == '0':
wiki_max_results = 10
else:
wiki_max_results = max_results
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That wasn't as painful as I thought it might be.

documents.set_count(('wiki', wiki_s),
min(wiki_s.count(), max_results))
min(wiki_s.count(), wiki_max_results))

if cleaned['w'] & constants.WHERE_SUPPORT:
# Sort results by
Expand Down
2 changes: 1 addition & 1 deletion settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ def JINJA_CONFIG():
TEST_SPHINXQL_PORT = 3418

SEARCH_MAX_RESULTS = 1000
SEARCH_RESULTS_PER_PAGE = 10
SEARCH_RESULTS_PER_PAGE = 20

# Search default settings
# comma-separated tuple of included category IDs. Negative IDs are excluded.
Expand Down