Parser for search results in connectors

This commit is contained in:
Mouse Reeve 2020-05-08 17:56:24 -07:00
parent c8bb717634
commit bb01834a31
5 changed files with 18 additions and 2 deletions

View file

@ -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 '''

View file

@ -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(

View file

@ -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,

View file

@ -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,

View file

@ -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')