[GMG-Devel] [PATCH 12/83] Add IndexRegistry class to maintain the search indices.

Alon Levy alon at pobox.com
Tue Feb 25 14:57:55 EST 2014


From: Praveen Kumar <praveen97uma at gmail.com>

---
 mediagoblin/plugins/search/base.py | 37 +++++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)
 create mode 100644 mediagoblin/plugins/search/base.py

diff --git a/mediagoblin/plugins/search/base.py b/mediagoblin/plugins/search/base.py
new file mode 100644
index 0000000..2636fef
--- /dev/null
+++ b/mediagoblin/plugins/search/base.py
@@ -0,0 +1,37 @@
+
+class IndexRegistry(object):
+    _registry = {}
+
+    @staticmethod
+    def register(search_index_obj):
+        """
+        Registers an index object.
+        """
+        identifier = search_index_obj.__tablename__
+        IndexRegistry._registry[identifier] = search_index_obj
+    
+    @staticmethod
+    def indices():
+        """
+        Return all the index objects registered.
+        """
+        return IndexRegistry._registry
+
+    @staticmethod
+    def get(identifier, not_found=None):
+        """
+        Return an index identified bu the `identifier`.
+
+        Returns `not_found` if the index object was not found.
+        in the regstered indices.
+        """
+        index = IndexRegistry._registry.get(identifier, not_found)
+        return index
+
+    @staticmethod
+    def get_index_for_object(db_object, not_found=None):
+        """
+        Returns the index object for the given db model object.
+        """
+        identifier = db_object.__tablename__
+        return IndexRegistry.get(identifier, not_found)
-- 
1.8.5.3



More information about the devel mailing list