[bug 1013495] Stop showing archived questions in default search.

This commit is contained in:
Ricky Rosario 2014-06-05 16:00:56 -04:00
Родитель 6dc4950fe9
Коммит f557f47223
6 изменённых файлов: 32 добавлений и 83 удалений

Просмотреть файл

@ -332,7 +332,7 @@ Regular search does the following:
5. (filter) support forum posts tagged with the product
(e.g. "desktop")
6. (filter) support forum posts must have an answer marked as helpful
7. (filter) support forum posts must be from the past 180 days
7. (filter) support forum posts must not be archived
It scores as specified above.

Просмотреть файл

@ -73,31 +73,20 @@ class AAQTests(ElasticTestCase):
assert 'CupcakesQuestion' in response.content
assert 'CupcakesKB' in response.content
def test_search_suggestion_question_age(self):
"""Verifies the view doesn't return old questions."""
p = product(slug=u'firefox', save=True)
topic(title='Fix problems', slug='fix-problems', product=p, save=True)
q1 = question(title='Fresh Cupcakes', save=True)
q1.products.add(p)
max_age = settings.SEARCH_DEFAULT_MAX_QUESTION_AGE
too_old = datetime.now() - timedelta(seconds=max_age * 2)
q2 = question(title='Stale Cupcakes', created=too_old, updated=too_old,
save=True)
q2.products.add(p)
# Verify that archived articles and questions aren't shown...
# Archive both and they shouldn't appear anymore.
q.is_archived = True
q.save()
d.is_archived = True
d.save()
self.refresh()
url = urlparams(
reverse('questions.aaq_step4', args=['desktop', 'fix-problems']),
search='cupcakes')
response = self.client.get(url, follow=True)
eq_(200, response.status_code)
self.assertContains(response, q1.title)
self.assertNotContains(response, q2.title)
assert 'CupcakesQuestion' not in response.content
assert 'CupcakesKB' not in response.content
@override_settings(AAQ_LANGUAGES=['en-US', 'pt-BR', 'de'])
def test_search_suggestion_questions_locale(self):
@ -132,34 +121,6 @@ class AAQTests(ElasticTestCase):
sub_test('pt-BR', 'cupcakes?', 'donuts?', 'pies?')
sub_test('de', 'cupcakes?', 'donuts?', 'pastries?')
def test_search_suggestions_archived_articles(self):
"""Verifies that archived articles aren't shown."""
p = product(slug=u'firefox', save=True)
topic(title='Fix problems', slug='fix-problems', product=p, save=True)
d1 = document(title=u'document donut', category=10, save=True)
d1.products.add(p)
revision(document=d1, is_approved=True, save=True)
d2 = document(title=u'document cupcake', category=10, is_archived=True,
save=True)
d2.products.add(p)
revision(document=d1, is_approved=True, save=True)
self.refresh()
url = urlparams(
reverse('questions.aaq_step4', args=['desktop', 'fix-problems']),
search='document')
response = self.client.get(url, follow=True)
eq_(200, response.status_code)
doc = pq(response.content)
eq_(len(doc('.result.document')), 1)
assert 'donut' in doc('.result.document h3 a').text()
assert 'cupcake' not in doc('.result.document h3 a').text()
def test_ratelimit(self):
"""Make sure posting new questions is ratelimited"""
data = {'title': 'A test question',

Просмотреть файл

@ -1629,7 +1629,6 @@ def _search_suggestions(request, text, locale, product_slugs):
query.update(dict(('%s__match_phrase' % field, text)
for field in QuestionMappingType.get_query_fields()))
max_age = int(time.time()) - settings.SEARCH_DEFAULT_MAX_QUESTION_AGE
# Filter questions by language. Questions should be either in English
# or in the locale's language. This is because we have some questions
# marked English that are really in other languages. The assumption
@ -1638,7 +1637,7 @@ def _search_suggestions(request, text, locale, product_slugs):
# better, so questions incorrectly marked as english can be found too.
question_filter = F(question_locale=locale)
question_filter |= F(question_locale=settings.WIKI_DEFAULT_LANGUAGE)
question_filter &= F(updated__gte=max_age)
question_filter &= F(question_is_archived=False)
raw_results = (question_s.query(or_=query)
.filter(question_filter)

Просмотреть файл

@ -189,6 +189,23 @@ class ElasticSearchUnifiedViewTests(ElasticTestCase):
content = json.loads(response.content)
eq_(content['total'], 2)
# Archive the article and question. They should no longer appear
# in default search results.
ques.is_archived = True
ques.save()
doc.is_archived = True
doc.save()
self.refresh()
response = self.client.get(reverse('search'), {
'q': 'audio', 'format': 'json'})
eq_(200, response.status_code)
content = json.loads(response.content)
eq_(content['total'], 0)
def test_advanced_search_for_wiki_no_query(self):
"""Tests advanced search with no query"""
doc = document(locale=u'en-US', category=10, save=True)
@ -584,31 +601,6 @@ class ElasticSearchUnifiedViewTests(ElasticTestCase):
results = json.loads(response.content)['results']
eq_([q2.get_absolute_url()], [r['url'] for r in results])
def test_created_default(self):
"""Questions older than 180 days aren't returned by default."""
max_age_days = settings.SEARCH_DEFAULT_MAX_QUESTION_AGE / 60 / 60 / 24
# Older than max_age_days:
created = datetime.now() - timedelta(days=max_age_days + 1)
q1 = question(title=u'q1 audio', created=created, save=True)
q1.tags.add(u'desktop')
ans = answer(question=q1, save=True)
answervote(answer=ans, helpful=True, save=True)
# Younger than max_age_days:
created = datetime.now() - timedelta(days=max_age_days - 1)
q2 = question(title=u'q2 audio', created=created, save=True)
q2.tags.add(u'desktop')
ans = answer(question=q2, save=True)
answervote(answer=ans, helpful=True, save=True)
self.refresh()
qs = {'format': 'json', 'q': 'audio'}
response = self.client.get(reverse('search'), qs)
results = json.loads(response.content)['results']
eq_([q2.get_absolute_url()], [r['url'] for r in results])
def test_sortby_invalid(self):
"""Invalid created_date is ignored."""
qs = {'a': 1, 'w': 4, 'format': 'json', 'sortby': ''}

Просмотреть файл

@ -173,10 +173,14 @@ def search(request, template=None):
# Start - support questions filters
if cleaned['w'] & constants.WHERE_SUPPORT:
# Solved is set by default if using basic search
# Has helpful answers is set by default if using basic search
if a == '0' and not cleaned['has_helpful']:
cleaned['has_helpful'] = constants.TERNARY_YES
# No archived questions in default search.
if a == '0' and not cleaned['is_archived']:
cleaned['is_archived'] = constants.TERNARY_NO
# These filters are ternary, they can be either YES, NO, or OFF
ternary_filters = ('is_locked', 'is_solved', 'has_answers',
'has_helpful', 'is_archived')
@ -258,12 +262,6 @@ def search(request, template=None):
discussion_f &= F(**after)
question_f &= F(**after)
# In basic search, we limit questions from the last
# SEARCH_DEFAULT_MAX_QUESTION_AGE seconds.
if a == '0':
start_date = unix_now - settings.SEARCH_DEFAULT_MAX_QUESTION_AGE
question_f &= F(created__gte=start_date)
# Note: num_voted (with a d) is a different field than num_votes
# (with an s). The former is a dropdown and the latter is an
# integer value.

Просмотреть файл

@ -665,7 +665,6 @@ SEARCH_RESULTS_PER_PAGE = 10
# Search default settings
SEARCH_DEFAULT_CATEGORIES = (10, 20,)
SEARCH_DEFAULT_MAX_QUESTION_AGE = 180 * 24 * 60 * 60 # seconds
# IA default settings
IA_DEFAULT_CATEGORIES = (10, 20,)