mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-12-20 07:06:41 +00:00
Parser for search results in connectors
This commit is contained in:
parent
c8bb717634
commit
bb01834a31
5 changed files with 18 additions and 2 deletions
|
@ -49,7 +49,7 @@ class AbstractConnector(ABC):
|
|||
data = resp.json()
|
||||
results = []
|
||||
|
||||
for doc in data['docs'][:10]:
|
||||
for doc in self.parse_search_data(data)[:10]:
|
||||
results.append(self.format_search_result(doc))
|
||||
return results
|
||||
|
||||
|
@ -82,6 +82,11 @@ class AbstractConnector(ABC):
|
|||
return book
|
||||
|
||||
|
||||
@abstractmethod
|
||||
def parse_search_data(self, data):
|
||||
''' turn the result json from a search into a list '''
|
||||
|
||||
|
||||
@abstractmethod
|
||||
def format_search_result(self, search_result):
|
||||
''' create a SearchResult obj from json '''
|
||||
|
|
|
@ -26,6 +26,10 @@ class Connector(AbstractConnector):
|
|||
return SearchResult(**search_result)
|
||||
|
||||
|
||||
def parse_search_data(self, data):
|
||||
return data
|
||||
|
||||
|
||||
def get_or_create_book(self, remote_id):
|
||||
''' pull up a book record by whatever means possible '''
|
||||
book = models.Book.objects.select_subclasses().filter(
|
||||
|
|
|
@ -47,6 +47,10 @@ class Connector(AbstractConnector):
|
|||
)
|
||||
|
||||
|
||||
def parse_search_data(self, data):
|
||||
return data.get('docs')
|
||||
|
||||
|
||||
def get_or_create_book(self, olkey):
|
||||
''' pull up a book record by whatever means possible.
|
||||
if you give a work key, it should give you the default edition,
|
||||
|
|
|
@ -39,6 +39,10 @@ class Connector(AbstractConnector):
|
|||
return search_results
|
||||
|
||||
|
||||
def parse_search_data(self, data):
|
||||
return data
|
||||
|
||||
|
||||
def format_search_result(self, book):
|
||||
return SearchResult(
|
||||
book.title,
|
||||
|
|
|
@ -143,7 +143,6 @@ def get_activity_feed(user, filter_level, model=models.Status):
|
|||
return activities
|
||||
|
||||
|
||||
@login_required
|
||||
def search(request):
|
||||
''' that search bar up top '''
|
||||
query = request.GET.get('q')
|
||||
|
|
Loading…
Reference in a new issue