def search(self, location, live=True): query = flask.request.args.get('q') if live: search_controller = 'search' else: search_controller = 'search_qa' if query: # Run the query and send the results. results = Library.search(self._db, location, query, production=live) this_url = self.app.url_for(search_controller, q=query) catalog = OPDSCatalog(self._db, unicode(_('Search results for "%s"')) % query, this_url, results, annotator=self.annotator, live=live) return catalog_response(catalog) else: # Send the search form. body = self.OPENSEARCH_TEMPLATE % dict( name=_("Find your library"), description=_("Search by ZIP code, city or library name."), tags="", url_template=self.app.url_for(search_controller) + "?q={searchTerms}") headers = {} headers['Content-Type'] = OPENSEARCH_MEDIA_TYPE headers['Cache-Control'] = "public, no-transform, max-age: %d" % ( 3600 * 24 * 30) return Response(body, 200, headers)
def search_details(self): name = flask.request.form.get("name") search_results = Library.search(self._db, {}, name, production=False) if search_results: info = [ self.library_details(lib.internal_urn.split("uuid:")[1], lib) for lib in search_results ] return dict(libraries=info) else: return LIBRARY_NOT_FOUND
def run(self, cmd_args=None, stdout=sys.stdout): parsed = self.parse_command_line(self._db, cmd_args) for library in Library.search(self._db, None, parsed.query[0]): stdout.write("%s: %s" % (library.name, library.opds_url)) stdout.write("\n")