search: don't duplicate external link title as contents (#21026)
This commit is contained in:
parent
e66675775d
commit
7a410dbd78
|
@ -53,10 +53,13 @@ class Command(UpdateIndexCommand):
|
|||
# create an entry for that link.
|
||||
links[link_data['url']] = {}
|
||||
links[link_data['url']]['title'] = link_data['title']
|
||||
links[link_data['url']]['all_titles'] = []
|
||||
# all titles and additional texts will be assembled and indexed
|
||||
links[link_data['url']]['all_titles'].append(link_data['title'])
|
||||
links[link_data['url']]['all_titles'].append(link_data.get('text') or '')
|
||||
links[link_data['url']]['all_texts'] = []
|
||||
else:
|
||||
# if that link already exists, just keep the title as
|
||||
# text.
|
||||
links[link_data['url']]['all_texts'].append(link_data['title'])
|
||||
# additional texts will be assembled and indexed
|
||||
links[link_data['url']]['all_texts'].append(link_data.get('text') or '')
|
||||
|
||||
# save data as ExternalLinkSearchItem objects
|
||||
for link_url, link_data in links.items():
|
||||
|
@ -64,7 +67,7 @@ class Command(UpdateIndexCommand):
|
|||
url=link_url,
|
||||
defaults={'title': link_data['title']})
|
||||
link_object.title = link_data['title']
|
||||
link_object.text = '\n'.join(link_data['all_titles'])
|
||||
link_object.text = '\n'.join(link_data['all_texts'])
|
||||
link_object.save()
|
||||
|
||||
# remove obsolete objects
|
||||
|
|
|
@ -253,3 +253,15 @@ def test_update_index_command(app):
|
|||
resp = app.get('/api/search/?q=baz', status=200)
|
||||
assert len(resp.json['data']) == 1
|
||||
assert resp.json['data'][0]['url'] == 'http://example.net'
|
||||
|
||||
# add a second link with the same target
|
||||
LinkCell(title='bar', url='http://example.net', page=page, order=0).save()
|
||||
call_command('update_index')
|
||||
|
||||
resp = app.get('/api/search/?q=baz', status=200)
|
||||
assert len(resp.json['data']) == 1
|
||||
assert resp.json['data'][0]['url'] == 'http://example.net'
|
||||
|
||||
resp = app.get('/api/search/?q=bar', status=200)
|
||||
assert len(resp.json['data']) == 1
|
||||
assert resp.json['data'][0]['url'] == 'http://example.net'
|
||||
|
|
Loading…
Reference in New Issue