Commits

Thomas Wanschik  committed 1423f33

fixed remaining bugs remaining from the last refactoring

  • Participants
  • Parent commits 5abb2ef

Comments (0)

Files changed (2)

File search/backends/gae_background_tasks.py

 def update_relation_index(search_manager, parent_pk, delete):
     # pass only the field / model names to the background task to transfer less
     # data
-    app_label = search_manager.model_class._meta.app_label
-    object_name = search_manager.model_class._meta.object_name
+    app_label = search_manager.model._meta.app_label
+    object_name = search_manager.model._meta.object_name
     deferred.defer(update, app_label, object_name, search_manager.name,
         parent_pk, delete, _queue=default_search_queue)
 
-def update(app_label, object_name, field_name, parent_pk, delete):
+def update(app_label, object_name, manager_name, parent_pk, delete):
     model = models.get_model(app_label, object_name)
-    update_property = model._meta.get_field_by_name(field_name)[0]
-    update_property.update_relation_index(parent_pk, delete)
+    manager = getattr(model, manager_name)
+    manager.update_relation_index(parent_pk, delete)

File search/core.py

     def __getitem__(self, key):
         return getattr(self.data, key)
 
-# IndexField is a StringListField storing indexed fields of a model_instance
+# IndexField is a (string) ListField storing indexed fields of a model_instance
 class IndexField(ListField):
     def __init__(self, self_manager, *args, **kwargs):
         self.search_manager = self_manager
             language = language(model_instance, property=self)
 
         index = []
-        for field in self.search_manager.fields_to_index:
-            values = getattr_by_path(model_instance, field, None)
+        for field_name in self.search_manager.fields_to_index:
+            values = getattr_by_path(model_instance, field_name, None)
             if not values:
                 values = ()
             elif not isinstance(values, (list, tuple)):
 
 class SearchManager(models.Manager):
     """
-    Simple full-text search manager for the given fields.
+    Simple full-text manager adding a search function.
 
     If "relation_index" is True the index will be stored in a separate entity.
 
         self.relation_index = relation_index
         if len(fields_to_index) == 0:
             raise ValueError('No fields specified for index!')
-        self.serach_list_field_name = ''
+        # search_list_field_name will be set if no relation_index is used that is
+        # for relation_index=False or for the relation_index_model itself
+        self.search_list_field_name = ''
         super(SearchManager, self).__init__(**kwargs)
 
     def contribute_to_class(self, model, name):
         super(SearchManager, self).contribute_to_class(model, name)
         # set default_manager to None such that the default_manager will be set
-        # to 'objects'
+        # to 'objects' via the class-prepared signal calling
+        # ensure_default_manager
         setattr(model, '_default_manager', None)
         self.name = name
+        # add IndexField to the model if we do not use the relation_index
         if not self.relation_index:
-#            print model, name
             self.search_list_field_name = "%s_search_list_field" %name
             # Add field to class dynamically
             setattr(model, self.search_list_field_name, IndexField(self))
                 model, self.search_list_field_name)
 
     def filter(self, values):
-        """Returns a query for the given values (creates '=' filters for this
-        field. Additionally filters can be applied afterwoods via chaining."""
-
+        """
+        Returns a query for the given values (creates '=' filters for the
+        IndexField. Additionally filters can be applied afterwoods via chaining.
+        """
         if not isinstance(values, (tuple, list)):
             values = (values,)
         filtered = self.model.objects.all()
     # TODO: add keys_only query
 #    def values(self, fields):
 #        pass
-#
+
+# backwards compatibility
 #class SearchIndexField():
 #    def __init__(self, fields_to_index, indexer=None, splitter=default_splitter,
 #            relation_index=True, integrate='*', filters={},