allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brond...@apache.org
Subject [10/26] git commit: [#7656] ticket:648 Move translate_query to SearchIndexable
Date Fri, 19 Sep 2014 20:04:24 GMT
[#7656] ticket:648 Move translate_query to SearchIndexable


Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/04b0016e
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/04b0016e
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/04b0016e

Branch: refs/heads/master
Commit: 04b0016e13186317c238012debf1edf4a57cab8c
Parents: 6c7ca9a
Author: Igor Bondarenko <jetmind2@gmail.com>
Authored: Tue Sep 9 13:15:17 2014 +0300
Committer: Dave Brondsema <dbrondsema@slashdotmedia.com>
Committed: Fri Sep 19 19:35:39 2014 +0000

----------------------------------------------------------------------
 Allura/allura/lib/search.py     | 18 ++++++++++++++++++
 Allura/allura/model/artifact.py | 18 ------------------
 Allura/allura/model/project.py  |  5 -----
 3 files changed, 18 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/04b0016e/Allura/allura/lib/search.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/search.py b/Allura/allura/lib/search.py
index 49a3ad5..f4f177a 100644
--- a/Allura/allura/lib/search.py
+++ b/Allura/allura/lib/search.py
@@ -100,6 +100,24 @@ class SearchIndexable(object):
         doc['text'] = jinja2.Markup.escape(text).striptags()
         return doc
 
+    @classmethod
+    def translate_query(cls, q, fields):
+        """Return a translated Solr query (``q``), where generic field
+        identifiers are replaced by the 'strongly typed' versions defined in
+        ``fields``.
+
+        """
+        # Replace longest fields first to avoid problems when field names have
+        # the same suffixes, but different field types. E.g.:
+        # query 'shortname:test' with fields.keys() == ['name_t', 'shortname_s']
+        # will be translated to 'shortname_t:test', which makes no sense
+        fields = sorted(fields.keys(), key=len, reverse=True)
+        for f in fields:
+            if '_' in f:
+                base, typ = f.rsplit('_', 1)
+                q = q.replace(base + ':', f + ':')
+        return q
+
 
 class SearchError(SolrError):
     pass

http://git-wip-us.apache.org/repos/asf/allura/blob/04b0016e/Allura/allura/model/artifact.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/artifact.py b/Allura/allura/model/artifact.py
index 2639021..ccb6b42 100644
--- a/Allura/allura/model/artifact.py
+++ b/Allura/allura/model/artifact.py
@@ -130,24 +130,6 @@ class Artifact(MappedClass, SearchIndexable):
     def attachment_class(cls):
         raise NotImplementedError, 'attachment_class'
 
-    @classmethod
-    def translate_query(cls, q, fields):
-        """Return a translated Solr query (``q``), where generic field
-        identifiers are replaced by the 'strongly typed' versions defined in
-        ``fields``.
-
-        """
-        # Replace longest fields first to avoid problems when field names have
-        # the same suffixes, but different field types. E.g.:
-        # query 'shortname:test' with fields.keys() == ['name_t', 'shortname_s']
-        # will be translated to 'shortname_t:test', which makes no sense
-        fields = sorted(fields.keys(), key=len, reverse=True)
-        for f in fields:
-            if '_' in f:
-                base, typ = f.rsplit('_', 1)
-                q = q.replace(base + ':', f + ':')
-        return q
-
     @LazyProperty
     def ref(self):
         """Return :class:`allura.model.index.ArtifactReference` for this

http://git-wip-us.apache.org/repos/asf/allura/blob/04b0016e/Allura/allura/model/project.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/project.py b/Allura/allura/model/project.py
index d8c3180..2ecb530 100644
--- a/Allura/allura/model/project.py
+++ b/Allura/allura/model/project.py
@@ -252,11 +252,6 @@ class Project(SearchIndexable, MappedClass, ActivityNode, ActivityObject):
     # transient properties
     notifications_disabled = False
 
-    @classmethod
-    def translate_query(cls, q, fields):
-        from .artifact import Artifact
-        return Artifact.translate_query(q, fields)
-
     @property
     def activity_name(self):
         return self.name


Mime
View raw message