forked from mirrors/bookwyrm
Re-sorts search results after deduplication
This commit is contained in:
parent
a413c87963
commit
d3c181cacb
2 changed files with 8 additions and 3 deletions
|
@ -23,6 +23,7 @@ class Connector(AbstractConnector):
|
||||||
search_results.append(self.format_search_result(result))
|
search_results.append(self.format_search_result(result))
|
||||||
if len(search_results) >= 10:
|
if len(search_results) >= 10:
|
||||||
break
|
break
|
||||||
|
search_results.sort(key=lambda r: r.confidence, reverse=True)
|
||||||
return search_results
|
return search_results
|
||||||
|
|
||||||
|
|
||||||
|
@ -75,10 +76,10 @@ def search_identifiers(query):
|
||||||
|
|
||||||
def search_title_author(query, min_confidence):
|
def search_title_author(query, min_confidence):
|
||||||
''' searches for title and author '''
|
''' searches for title and author '''
|
||||||
print('DON"T BOTHER')
|
|
||||||
vector = SearchVector('title', weight='A') +\
|
vector = SearchVector('title', weight='A') +\
|
||||||
SearchVector('subtitle', weight='B') +\
|
SearchVector('subtitle', weight='B') +\
|
||||||
SearchVector('authors__name', weight='C')
|
SearchVector('authors__name', weight='C') +\
|
||||||
|
SearchVector('series', weight='D')
|
||||||
|
|
||||||
results = models.Edition.objects.annotate(
|
results = models.Edition.objects.annotate(
|
||||||
search=vector
|
search=vector
|
||||||
|
|
|
@ -48,6 +48,7 @@ class SelfConnector(TestCase):
|
||||||
edition = models.Edition.objects.create(
|
edition = models.Edition.objects.create(
|
||||||
title='Edition of Example Work',
|
title='Edition of Example Work',
|
||||||
published_date=datetime.datetime(1980, 5, 10, tzinfo=timezone.utc),
|
published_date=datetime.datetime(1980, 5, 10, tzinfo=timezone.utc),
|
||||||
|
parent_work=models.Work.objects.create(title='')
|
||||||
)
|
)
|
||||||
# author text is rank C
|
# author text is rank C
|
||||||
edition.authors.add(author)
|
edition.authors.add(author)
|
||||||
|
@ -55,18 +56,21 @@ class SelfConnector(TestCase):
|
||||||
# series is rank D
|
# series is rank D
|
||||||
models.Edition.objects.create(
|
models.Edition.objects.create(
|
||||||
title='Another Edition',
|
title='Another Edition',
|
||||||
series='Anonymous'
|
series='Anonymous',
|
||||||
|
parent_work=models.Work.objects.create(title='')
|
||||||
)
|
)
|
||||||
# subtitle is rank B
|
# subtitle is rank B
|
||||||
models.Edition.objects.create(
|
models.Edition.objects.create(
|
||||||
title='More Editions',
|
title='More Editions',
|
||||||
subtitle='The Anonymous Edition',
|
subtitle='The Anonymous Edition',
|
||||||
|
parent_work=models.Work.objects.create(title='')
|
||||||
)
|
)
|
||||||
# title is rank A
|
# title is rank A
|
||||||
models.Edition.objects.create(title='Anonymous')
|
models.Edition.objects.create(title='Anonymous')
|
||||||
# doesn't rank in this search
|
# doesn't rank in this search
|
||||||
edition = models.Edition.objects.create(
|
edition = models.Edition.objects.create(
|
||||||
title='An Edition',
|
title='An Edition',
|
||||||
|
parent_work=models.Work.objects.create(title='')
|
||||||
)
|
)
|
||||||
|
|
||||||
results = self.connector.search('Anonymous')
|
results = self.connector.search('Anonymous')
|
||||||
|
|
Loading…
Reference in a new issue