def reload_indexes(sender, *args, **kwargs): from haystack import connections for conn in connections.all(): ui = conn.get_unified_index() # Note: Unlike above, we're resetting the ``UnifiedIndex`` here. # Thi gives us a clean slate. ui.reset()
def haystack_init_before_syncdb(self, migrate_all=False, **options): """ Alternative workaround, that initialises Haystack first, so that fixtures can be indexed. """ # breakpoint() from haystack import connections for conn in connections.all(): conn.get_unified_index().setup_indexes()
def haystack_reset_after_syncdb(self, migrate_all=False, **options): """ Work around https://github.com/toastdriven/django-haystack/issues/495 and http://south.aeracode.org/ticket/1023 by resetting the UnifiedIndex after South's syncdb has run. """ from haystack import connections for conn in connections.all(): conn.get_unified_index().teardown_indexes() conn.get_unified_index().reset() conn.get_unified_index().setup_indexes()
def get_context(self): query_list = [] if haystack_version == 1: query_list = [q for q in queries] else: query_list = [q for conn in connections.all() for q in conn.queries] query_list.sort(key=lambda q: q['start']) return { 'queries': query_list, 'debug': getattr(settings, 'DEBUG', False), }
def ready(self): """Perform application initialization.""" from haystack import connections for connection in connections.all(): if connection.__class__.__name__ == 'ElasticsearchSearchEngine': # Modify elastic search schema. The default mapping for edge_ngram is incorrect # as it also uses the edgengram_analyzer during querying. from haystack.backends.elasticsearch_backend import FIELD_MAPPINGS FIELD_MAPPINGS['edge_ngram'] = { 'type': 'string', 'analyzer': 'edgengram_analyzer', 'search_analyzer': 'standard', } break
def process_documents(self, doclist, raw_results): # TODO: tame import spaghetti from haystack import connections # luisf # engine = connections["en"] engine = connections.all()[0] conn = engine.get_backend().conn unified_index = engine.get_unified_index() indexed_models = unified_index.get_indexed_models() for raw_result in doclist: app_label, model_name = raw_result[DJANGO_CT].split('.') additional_fields = {} model = get_model(app_label, model_name) if model and model in indexed_models: for key, value in raw_result.items(): index = unified_index.get_index(model) string_key = str(key) if string_key in index.fields and \ hasattr(index.fields[string_key], 'convert'): additional_fields[string_key] = index.fields[ string_key].convert(value) else: additional_fields[string_key] = conn._to_python(value) del(additional_fields[DJANGO_CT]) del(additional_fields[DJANGO_ID]) del(additional_fields['score']) if raw_result[ID] in getattr(raw_results, 'highlighting', {}): additional_fields['highlighted'] = \ raw_results.highlighting[raw_result[ID]] result = SearchResult( app_label, model_name, raw_result[DJANGO_ID], raw_result['score'], **additional_fields) yield result
def _get_query_count(self): if haystack_version == 1: return len(queries) else: return sum(map(lambda conn: len(conn.queries), connections.all()))
def load_indexes(sender, *args, **kwargs): from haystack import connections for conn in connections.all(): ui = conn.get_unified_index() ui.setup_indexes()