incubator-allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tvansteenbu...@apache.org
Subject [1/2] git commit: [#2053] Add config switch to control use of new solr fields
Date Tue, 07 May 2013 20:47:09 GMT
Updated Branches:
  refs/heads/tv/2053 6eaba047d -> 455c0b254


[#2053] Add config switch to control use of new solr fields

Signed-off-by: Tim Van Steenburgh <tvansteenburgh@gmail.com>


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

Branch: refs/heads/tv/2053
Commit: 618685eef89520283b940f30eaf636e7e3c02cee
Parents: 6eaba04
Author: Tim Van Steenburgh <tvansteenburgh@gmail.com>
Authored: Tue May 7 16:11:33 2013 -0400
Committer: Tim Van Steenburgh <tvansteenburgh@gmail.com>
Committed: Tue May 7 16:11:33 2013 -0400

----------------------------------------------------------------------
 Allura/allura/lib/utils.py                |   11 +++++++-
 Allura/allura/tests/test_utils.py         |   22 +++++++++++++++-
 Allura/development.ini                    |    5 +++
 ForgeTracker/forgetracker/model/ticket.py |   32 ++++++++++++------------
 4 files changed, 52 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/618685ee/Allura/allura/lib/utils.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/utils.py b/Allura/allura/lib/utils.py
index c60f33b..2424930 100644
--- a/Allura/allura/lib/utils.py
+++ b/Allura/allura/lib/utils.py
@@ -37,6 +37,7 @@ from formencode import Invalid
 from tg.decorators import before_validate
 from pylons import response
 from pylons import tmpl_context as c
+from paste.deploy.converters import asbool
 from paste.httpheaders import CACHE_CONTROL, EXPIRES
 from webhelpers.html import literal
 from webob import exc
@@ -64,6 +65,7 @@ def guess_mime_type(filename):
         content_type = 'application/octet-stream'
     return content_type
 
+
 class ConfigProxy(object):
     '''Wrapper for loading config values at module-scope so we don't
     have problems when a module is imported before tg.config is initialized
@@ -73,7 +75,14 @@ class ConfigProxy(object):
         self._kw = kw
 
     def __getattr__(self, k):
-        return tg.config[self._kw[k]]
+        return self.get(k)
+
+    def get(self, key, default=None):
+        return tg.config.get(self._kw.get(key, key), default)
+
+    def get_bool(self, key):
+        return asbool(self.get(key))
+
 
 class lazy_logger(object):
     '''Lazy instatiation of a logger, to ensure that it does not get

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/618685ee/Allura/allura/tests/test_utils.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/test_utils.py b/Allura/allura/tests/test_utils.py
index d20aa55..bd44ca2 100644
--- a/Allura/allura/tests/test_utils.py
+++ b/Allura/allura/tests/test_utils.py
@@ -23,7 +23,7 @@ from os import path
 
 import pylons
 from webob import Request
-from mock import Mock
+from mock import Mock, patch
 from nose.tools import assert_equal
 from pygments import highlight
 from pygments.lexers import get_lexer_for_filename
@@ -34,6 +34,26 @@ from allura import model as M
 from allura.lib import utils
 
 
+@patch.dict('allura.lib.utils.tg.config', clear=True, foo='bar', baz='true')
+class TestConfigProxy(unittest.TestCase):
+    def setUp(self):
+        self.cp = utils.ConfigProxy(mybaz="baz")
+
+    def test_getattr(self):
+        self.assertEqual(self.cp.foo, "bar")
+        self.assertEqual(self.cp.mybaz, "true")
+
+    def test_get(self):
+        self.assertEqual(self.cp.get("foo"), "bar")
+        self.assertEqual(self.cp.get("mybaz"), "true")
+        self.assertEqual(self.cp.get("fake"), None)
+        self.assertEqual(self.cp.get("fake", "default"), "default")
+
+    def test_get_bool(self):
+        self.assertEqual(self.cp.get_bool("mybaz"), True)
+        self.assertEqual(self.cp.get_bool("fake"), False)
+
+
 class TestChunkedIterator(unittest.TestCase):
 
     def setUp(self):

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/618685ee/Allura/development.ini
----------------------------------------------------------------------
diff --git a/Allura/development.ini b/Allura/development.ini
index 737a08b..f485d17 100644
--- a/Allura/development.ini
+++ b/Allura/development.ini
@@ -182,6 +182,11 @@ solr.server = http://localhost:8983/solr
 solr.commit = false
 # commit add operations within N ms
 solr.commitWithin = 10000
+# Use improved data types for labels and custom fields?
+# New Allura deployments should leave this set to true. Existing deployments
+# should set to false until existing data has been reindexed. Reindexing will
+# convert existing label and custom field data to more appropriate solr types.
+solr.use_new_types = true
 
 # Forgemail server
 forgemail.host = 0.0.0.0

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/618685ee/ForgeTracker/forgetracker/model/ticket.py
----------------------------------------------------------------------
diff --git a/ForgeTracker/forgetracker/model/ticket.py b/ForgeTracker/forgetracker/model/ticket.py
index 10259d0..3e2fde2 100644
--- a/ForgeTracker/forgetracker/model/ticket.py
+++ b/ForgeTracker/forgetracker/model/ticket.py
@@ -50,7 +50,8 @@ log = logging.getLogger(__name__)
 CUSTOM_FIELD_SOLR_TYPES = dict(boolean='_b', number='_i')
 
 config = utils.ConfigProxy(
-    common_suffix='forgemail.domain')
+    common_suffix='forgemail.domain',
+    new_solr='solr.use_new_types')
 
 class Globals(MappedClass):
 
@@ -201,10 +202,10 @@ class Globals(MappedClass):
 
     def sortable_custom_fields_shown_in_search(self):
         def solr_type(field_name):
-            # TODO POST-SOLR-REINDEX: Remove the following line. It temporarily
-            # forces the solr field type to string (_s) until the new index
-            # (with newly typed fields) is built.
-            return '_s'
+            # Pre solr-4.2.1 code indexed all custom fields as strings, so
+            # they must be searched as such.
+            if not config.get_bool('new_solr'):
+                return '_s'
             return self.get_custom_field_solr_type(field_name) or '_s'
 
         return [dict(
@@ -365,13 +366,12 @@ class Ticket(VersionedArtifact, ActivityObject, VotableArtifact):
             )
         for k, v in self.custom_fields.iteritems():
             field_value = unicode(v)
-            # Index all custom fields as Solr strings. This is actually wrong,
-            # but it's what the current code expects.
-            # TODO POST-SOLR-REINDEX: remove this line
-            result[k + '_s'] = field_value
+            # Pre solr-4.2.1 code expects all custom fields to be indexed
+            # as strings.
+            if not config.get_bool('new_solr'):
+                result[k + '_s'] = field_value
 
-            # Now let's also index with proper Solr types. After reindexing to
-            # add these, remove the catch-all string-type indexing above.
+            # Now let's also index with proper Solr types.
             solr_type = self.app.globals.get_custom_field_solr_type(k)
             if solr_type:
                 result[k + solr_type] = field_value
@@ -397,11 +397,11 @@ class Ticket(VersionedArtifact, ActivityObject, VotableArtifact):
         solr_field = '{0}{1}'
         solr_type = '_s'
         for f in cf:
-            # TODO POST-SOLR-REINDEX: uncomment this line to enable searching
-            # on new properly typed solr fields instead of the old catch-all
-            # string fields.
-            # solr_type = (c.app.globals.get_custom_field_solr_type(f)
-                    # or solr_type)
+            # Solr 4.2.1 index contains properly typed custom fields, so we
+            # can search on those instead of the old string-type solr fields.
+            if config.get_bool('new_solr'):
+                solr_type = (c.app.globals.get_custom_field_solr_type(f)
+                        or solr_type)
             actual = solr_field.format(f, solr_type)
             q = q.replace(f + ':', actual + ':')
         return q


Mime
View raw message