def handle(self, *items, **options): self.verbosity = int(options['verbosity']) # Clean all of the indexes when no apps/models have been specified. # The superclass does this differently and gets duplicates. if not items: items = set() unified_index = get_unified_index() unified_index.build() models = unified_index.indexes.keys() for model in models: items.add(model_label(model)) items = tuple(sorted(items)) return super(Command, self).handle(*items, **options)
def model_search(*models): """Create the basic combined search for the specified models.""" if not models: index = get_unified_index() index.build() models = index.indexes.keys() search = SearchQuerySet().models(*models) filters = {} for model in models: for lookup, value in get_index(model).filters().items(): # Make the lookup values optional, meaning that it # will only apply to documents containing the field. filters[lookup] = Optional(value) if filters: search = search.filter(**filters) return search
def handle(self, *items, **options): index_options = getattr(settings, 'HAYSTACK_PARTIAL_INDEX_OPTIONS', None) if not index_options: raise ImproperlyConfigured( 'settings.HAYSTACK_PARTIAL_INDEX_OPTIONS is not defined.') unified_index = get_unified_index(build=True) # Update all of the indexes when no apps/models have been specified. # The superclass does this differently and gets duplicates. if not items: items = set() models = unified_index.indexes.keys() for model in models: items.add(model_label(model)) items = tuple(sorted(items)) # Decorate the index_queryset method of any index that has a limit # defined in settings.HAYSTACK_PARTIAL_INDEX_OPTIONS for model, index in unified_index.indexes.iteritems(): label = model_label(model) limit_definition = index_options.get(label) if limit_definition: index.index_queryset = limit_index_queryset( index_queryset=index.index_queryset, limit_definition=limit_definition, verbosity=int(options['verbosity']), ) if not options.get('batchsize'): options['batchsize'] = 500 # Now run the update_index command as usual. with do_not_print(r'Skipping .+ - no index.'): with green_text: return super(Command, self).handle(*items, **options)
def handle(self, *items, **options): index_options = getattr(settings, 'HAYSTACK_PARTIAL_INDEX_OPTIONS', None) if not index_options: raise ImproperlyConfigured('settings.HAYSTACK_PARTIAL_INDEX_OPTIONS is not defined.') unified_index = get_unified_index(build=True) # Update all of the indexes when no apps/models have been specified. # The superclass does this differently and gets duplicates. if not items: items = set() models = unified_index.indexes.keys() for model in models: items.add(model_label(model)) items = tuple(sorted(items)) # Decorate the index_queryset method of any index that has a limit # defined in settings.HAYSTACK_PARTIAL_INDEX_OPTIONS for model, index in unified_index.indexes.iteritems(): label = model_label(model) limit_definition = index_options.get(label) if limit_definition: index.index_queryset = limit_index_queryset( index_queryset=index.index_queryset, limit_definition=limit_definition, verbosity=int(options['verbosity']), ) if not options.get('batchsize'): options['batchsize'] = 500 # Now run the update_index command as usual. with do_not_print(r'Skipping .+ - no index.'): with green_text: return super(Command, self).handle(*items, **options)