You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by jo...@apache.org on 2013/05/10 23:01:06 UTC

[11/11] git commit: [#4321] Change solr type of 'labels' field

[#4321] Change solr type of 'labels' field

Change to white-space-tokenized string field instead of text
field to get exact whole-word matching without stemming.

Copyfield added to solr schema to create new _ws on the fly
during reindexing, while still allowing the existing code
to work with the existing _t field.

After reindexing is complete, do a global
s/labels_t/labels_ws/ on the project (already tested).

Signed-off-by: Tim Van Steenburgh <tv...@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/16ea2661
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/16ea2661
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/16ea2661

Branch: refs/heads/master
Commit: 16ea2661b75dbeb0677ae2cc25f9c188e54058c7
Parents: 8a76480
Author: Tim Van Steenburgh <tv...@gmail.com>
Authored: Thu May 2 08:12:28 2013 -0400
Committer: Cory Johns <cj...@slashdotmedia.com>
Committed: Fri May 10 20:34:01 2013 +0000

----------------------------------------------------------------------
 Allura/allura/model/artifact.py                    |    7 ++--
 Allura/allura/tests/unit/test_artifact.py          |   29 +++++++++++++++
 ForgeTracker/forgetracker/tracker_main.py          |    4 +-
 ForgeTracker/forgetracker/widgets/ticket_search.py |    2 +-
 solr_config/schema.xml                             |    2 +
 vagrant/start_allura                               |    2 +-
 6 files changed, 38 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/16ea2661/Allura/allura/model/artifact.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/artifact.py b/Allura/allura/model/artifact.py
index 681ac26..2acd9d8 100644
--- a/Allura/allura/model/artifact.py
+++ b/Allura/allura/model/artifact.py
@@ -111,10 +111,9 @@ class Artifact(MappedClass):
     @classmethod
     def translate_query(cls, q, fields):
         for f in fields:
-            if f[-2] == '_':
-                base = f[:-2]
-                actual = f
-                q = q.replace(base+':', actual+':')
+            if '_' in f:
+                base, typ = f.rsplit('_', 1)
+                q = q.replace(base + ':', f + ':')
         return q
 
     @LazyProperty

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/16ea2661/Allura/allura/tests/unit/test_artifact.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/unit/test_artifact.py b/Allura/allura/tests/unit/test_artifact.py
new file mode 100644
index 0000000..6e470c0
--- /dev/null
+++ b/Allura/allura/tests/unit/test_artifact.py
@@ -0,0 +1,29 @@
+#       Licensed to the Apache Software Foundation (ASF) under one
+#       or more contributor license agreements.  See the NOTICE file
+#       distributed with this work for additional information
+#       regarding copyright ownership.  The ASF licenses this file
+#       to you under the Apache License, Version 2.0 (the
+#       "License"); you may not use this file except in compliance
+#       with the License.  You may obtain a copy of the License at
+#
+#         http://www.apache.org/licenses/LICENSE-2.0
+#
+#       Unless required by applicable law or agreed to in writing,
+#       software distributed under the License is distributed on an
+#       "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+#       KIND, either express or implied.  See the License for the
+#       specific language governing permissions and limitations
+#       under the License.
+
+import unittest
+
+from allura import model as M
+
+
+class TestArtifact(unittest.TestCase):
+
+    def test_translate_query(self):
+        fields = ['foo_s', 'bar_ws']
+        query = 'foo:1 AND bar:2 AND foo_bar_baz:3'
+        q = M.Artifact.translate_query(query, fields)
+        self.assertEqual(q, 'foo_s:1 AND bar_ws:2 AND foo_bar_baz:3')

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/16ea2661/ForgeTracker/forgetracker/tracker_main.py
----------------------------------------------------------------------
diff --git a/ForgeTracker/forgetracker/tracker_main.py b/ForgeTracker/forgetracker/tracker_main.py
index 3f64528..f76cf74 100644
--- a/ForgeTracker/forgetracker/tracker_main.py
+++ b/ForgeTracker/forgetracker/tracker_main.py
@@ -113,7 +113,7 @@ def _mongo_col_to_solr_col(name):
     elif name == 'mod_date':
         return 'mod_date_dt'
     elif name == 'labels':
-        return 'labels_s'
+        return 'labels_t'
     else:
         for field in c.app.globals.sortable_custom_fields_shown_in_search():
             if name == field['name']:
@@ -458,7 +458,7 @@ def solr_columns():
                     label='Updated',
                     active=c.app.globals.show_in_search['mod_date']),
                dict(name='labels',
-                   sort_name='labels_s',
+                   sort_name='labels_t',
                    label='Labels',
                    active=c.app.globals.show_in_search['labels']),
                ]

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/16ea2661/ForgeTracker/forgetracker/widgets/ticket_search.py
----------------------------------------------------------------------
diff --git a/ForgeTracker/forgetracker/widgets/ticket_search.py b/ForgeTracker/forgetracker/widgets/ticket_search.py
index 0417094..4444a60 100644
--- a/ForgeTracker/forgetracker/widgets/ticket_search.py
+++ b/ForgeTracker/forgetracker/widgets/ticket_search.py
@@ -122,7 +122,7 @@ class SearchHelp(ffw.Lightbox):
 <h2>Sorting search results</h2>
 <p>Ticket search results can be sorted by clicking the header of the column you want to sort by. The first click will sort the results in ascending order. Clicking the header again will sort the column in descending order. In addition to sorting by the column headers, you can manually sort on these properties:</p>
 <ul>
-<li>Labels assigned to the ticket - labels_s</li>
+<li>Labels assigned to the ticket - labels_t</li>
 <li>Milestone the ticket is assigned to - _milestone_s</li>
 <li>Last modified date - mod_date_dt</li>
 <li>Body of the ticket - text_s</li>

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/16ea2661/solr_config/schema.xml
----------------------------------------------------------------------
diff --git a/solr_config/schema.xml b/solr_config/schema.xml
index 45aca76..005eab0 100644
--- a/solr_config/schema.xml
+++ b/solr_config/schema.xml
@@ -203,6 +203,7 @@
    <dynamicField name="*_f"  type="float"  indexed="true"  stored="true"/>
    <dynamicField name="*_d"  type="double" indexed="true"  stored="true"/>
    <dynamicField name="*_dt" type="date"    indexed="true"  stored="true"/>
+   <dynamicField name="*_ws" type="text_ws" indexed="true"  stored="true"/>
 
  </fields>
 
@@ -240,6 +241,7 @@
 
    <!-- copy name to alphaNameSort, a field designed for sorting by name -->
    <!-- <copyField source="name" dest="alphaNameSort"/> -->
+   <copyField source="labels_t" dest="labels_ws"/>
 
   <types>
     <!-- field type definitions. The "name" attribute is

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/16ea2661/vagrant/start_allura
----------------------------------------------------------------------
diff --git a/vagrant/start_allura b/vagrant/start_allura
index c396f7a..c3f7016 100755
--- a/vagrant/start_allura
+++ b/vagrant/start_allura
@@ -31,7 +31,7 @@ fi
 echo "Logs are in /var/log/allura"
 
 # Start solr
-if pgrep -f solr.*start.jar >/dev/null
+if pgrep -f start.jar >/dev/null
 then
     echo "Solr is running."
 else