mediagoblin-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


From: Alon Levy
Subject: [GMG-Devel] [PATCH 12/83] Add IndexRegistry class to maintain the search indices.
Date: Tue, 25 Feb 2014 21:57:55 +0200

From: Praveen Kumar <address@hidden>

---
 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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]