Adds fulltext search of postgres
This commit is contained in:
parent
6e218a85de
commit
e3525b13f5
2 changed files with 61 additions and 5 deletions
|
@ -1,8 +1,9 @@
|
|||
''' using a fedireads instance as a source of book data '''
|
||||
from django.contrib.postgres.search import SearchVector
|
||||
from django.core.exceptions import ObjectDoesNotExist
|
||||
|
||||
from fedireads import models
|
||||
from .abstract_connector import AbstractConnector
|
||||
from .abstract_connector import AbstractConnector, SearchResult
|
||||
|
||||
|
||||
class Connector(AbstractConnector):
|
||||
|
@ -14,7 +15,33 @@ class Connector(AbstractConnector):
|
|||
def search(self, query):
|
||||
''' right now you can't search fedireads sorry, but when
|
||||
that gets implemented it will totally rule '''
|
||||
return []
|
||||
results = models.Edition.objects.annotate(
|
||||
search=SearchVector('title', weight='A') +\
|
||||
SearchVector('subtitle', weight='B') +\
|
||||
SearchVector('author_text', weight='A') +\
|
||||
SearchVector('isbn_13', weight='A') +\
|
||||
SearchVector('isbn_10', weight='A') +\
|
||||
SearchVector('openlibrary_key', weight='B') +\
|
||||
SearchVector('goodreads_key', weight='B') +\
|
||||
SearchVector('source_url', weight='B') +\
|
||||
SearchVector('asin', weight='B') +\
|
||||
SearchVector('oclc_number', weight='B') +\
|
||||
SearchVector('description', weight='C') +\
|
||||
SearchVector('series', weight='C')
|
||||
).filter(search=query)
|
||||
|
||||
search_results = []
|
||||
for book in results[:10]:
|
||||
search_results.append(
|
||||
SearchResult(
|
||||
book.title,
|
||||
book.fedireads_key,
|
||||
book.author_text,
|
||||
book.published_date.year if book.published_date else None,
|
||||
None
|
||||
)
|
||||
)
|
||||
return search_results
|
||||
|
||||
|
||||
def get_or_create_book(self, fedireads_key):
|
||||
|
@ -38,3 +65,7 @@ class Connector(AbstractConnector):
|
|||
|
||||
def update_book(self, book_obj):
|
||||
pass
|
||||
|
||||
|
||||
def expand_book_data(self, book):
|
||||
pass
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue