def _determine_backend(self): from haystack import connections # A backend has been manually selected. Use it instead. if self._using is not None: self.query = connections[self._using].get_query() return # No backend, so rely on the routers to figure out what's right. hints = {} if self.query: hints['models'] = self.query.models backend_alias = connection_router.for_read(**hints) if isinstance(backend_alias, (list, tuple)) and len(backend_alias): # We can only effectively read from one engine. backend_alias = backend_alias[0] # The ``SearchQuery`` might swap itself out for a different variant # here. if self.query: self.query = self.query.using(backend_alias) else: self.query = connections[backend_alias].get_query()
def _determine_backend(self): # A backend has been manually selected. Use it instead. using = self.original_kwargs.get("using", None) if using is not None: connection = connections[using] else: # No backend, so rely on the routers to figure out what's right. hints = {"models": self.original_kwargs.get("models", None)} backend_alias = connection_router.for_read(**hints) connection = connections[backend_alias] backend = connection.get_backend() if not self.implementation: if hasattr(connection, "solr_paginator") and self.original_kwargs.get( "group", "false") == "true": self.implementation = connection.solr_paginator( backend=backend, **self.original_kwargs) elif hasattr(connection, "solr_paginator") and self.original_kwargs.get( "percent_score", False): self.implementation = connection.solr_paginator( backend=backend, **self.original_kwargs) elif hasattr(connection, "solr_paginator") and self.original_kwargs.get( "json_facets", None): self.implementation = connection.solr_paginator( backend=backend, **self.original_kwargs) else: self.implementation = connection.paginator( backend=backend, **self.original_kwargs) self.backend = backend
def _determine_backend(self): """This is a hack somehow connection_router got wrong values from setting and did not loaded the LanguageRouter""" from haystack import connections, connection_router # A backend has been manually selected. Use it instead. if self._using is not None: self.query = connections[self._using].get_query() return # No backend, so rely on the routers to figure out what's right. hints = {} if self.query: hints["models"] = self.query.models backend_alias = connection_router.for_read(**hints) if isinstance(backend_alias, (list, tuple)) and len(backend_alias): # We can only effectively read from one engine. backend_alias = backend_alias[0] # The ``SearchQuery`` might swap itself out for a different variant # here. if self.query: self.query = self.query.using(backend_alias) else: self.query = connections[backend_alias].get_query()
def _determine_backend(self): # A backend has been manually selected. Use it instead. if self.using is not None: self.backend = connections[self.using].get_backend() return # No backend, so rely on the routers to figure out what's right. hints = {'models': self.models} backend_alias = connection_router.for_read(**hints) self.backend = connections[backend_alias].get_backend()
def _determine_backend(self): # A backend has been manually selected. Use it instead. if self._using is not None: self.query = connections[self._using].get_query() return # No backend, so rely on the routers to figure out what's right. hints = {} if self.query: hints['models'] = self.query.models backend_alias = connection_router.for_read(**hints) # The ``SearchQuery`` might swap itself out for a different variant # here. if self.query: self.query = self.query.using(backend_alias) else: self.query = connections[backend_alias].get_query()
def _determine_backend(self): # A backend has been manually selected. Use it instead. if self._using is not None: return self._using # No backend, so rely on the routers to figure out what's right. from haystack import connections hints = {} if self.query: hints['models'] = self.query.models backend_alias = connection_router.for_read(**hints) # The ``SearchQuery`` might swap itself out for a different variant # here. if self.query: self.query = self.query.using(backend_alias) else: self.query = connections[backend_alias].get_query()
def basic_search(source, target, language, start=0, rows=10, stopword_list=None): if language != 'latin': raise Exception('Only latin is supported for now. Sorry.') conn_alias = connection_router.for_read() if isinstance(conn_alias, (list, tuple)) and len(conn_alias): # We can only effectively read from one engine conn_alias = conn_alias[0] hs_info = settings.HAYSTACK_CONNECTIONS[conn_alias] solr_url = hs_info['URL'] get_params = { 'wt': 'python', # bitchin 'tess.sq': 'volume_id:{0}'.format(source.id), 'tess.sf': 'text', 'tess.sfl': 'volume,author,text,title', 'tess.tq': 'volume_id:{0}'.format(target.id), 'tess.tf': 'text', 'tess.tfl': 'volume,author,text,title', 'start': str(start), 'rows': str(rows) } if stopword_list is not None: if _is_sequence(stopword_list): stopword_list = ','.join(stopword_list) elif not isinstance(stopword_list, (str, unicode)): raise ValueError('invalid type for stopword_list, expected a string or something iterable') get_params['tess.sl'] = str(stopword_list) response = requests.get(COMPARE_URL.format(solr_url), params=get_params) response.raise_for_status() # This couldn't possibly be abused... cough return eval(str(response.text))
def is_whoosh_backend(): backend_alias = connection_router.for_read() return connections[backend_alias].__class__.__name__ == "WhooshEngine"