You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by br...@apache.org on 2019/10/01 15:50:29 UTC

[allura] 02/03: [#8335] Strong search test

This is an automated email from the ASF dual-hosted git repository.

brondsem pushed a commit to branch db/8335
in repository https://gitbox.apache.org/repos/asf/allura.git

commit 0a1817f871158426a1936f6aeb89cdf33314660e
Author: Dave Brondsema <da...@brondsema.net>
AuthorDate: Mon Sep 30 17:27:27 2019 -0400

    [#8335] Strong search test
---
 Allura/allura/ext/search/search_main.py       |  7 ++-----
 Allura/allura/lib/solr.py                     | 10 +++++++++-
 Allura/allura/tests/functional/test_search.py | 10 +++++++---
 3 files changed, 18 insertions(+), 9 deletions(-)

diff --git a/Allura/allura/ext/search/search_main.py b/Allura/allura/ext/search/search_main.py
index 91bb1da..0c54021 100644
--- a/Allura/allura/ext/search/search_main.py
+++ b/Allura/allura/ext/search/search_main.py
@@ -74,11 +74,8 @@ class SearchController(BaseController):
     def index(self, q=None, history=None, **kw):
         c.search_results = SearchResults()
         c.help_modal = SearchHelp(comments=False)
-        pids = [c.project._id] + [
-            p._id for p in c.project.subprojects]
-        project_match = ' OR '.join(
-            'project_id_s:%s' % pid
-            for pid in pids)
+        pids = [c.project._id] + [p._id for p in c.project.subprojects]
+        project_match = ' OR '.join(map(str, pids))
         search_params = kw
         search_params.update({
             'q': q,
diff --git a/Allura/allura/lib/solr.py b/Allura/allura/lib/solr.py
index b74a4ab..222fdef 100644
--- a/Allura/allura/lib/solr.py
+++ b/Allura/allura/lib/solr.py
@@ -165,6 +165,8 @@ class MockSOLR(object):
                 continue
             if ':' in part:
                 field, value = part.split(':', 1)
+                if value.startswith('(') and value.endswith(')'):
+                    value = value[1:-1]
                 preds.append((field, value))
             else:
                 preds.append(('text', part))
@@ -172,17 +174,23 @@ class MockSOLR(object):
         for obj in self.db.values():
             for field, value in preds:
                 neg = False
-                if field[0] == '!':
+                if field[0] in ('!', '-'):
                     neg = True
                     field = field[1:]
                 if field == 'text' or field.endswith('_t'):
                     if (value not in str(obj.get(field, ''))) ^ neg:
                         break
+                elif field.endswith('_b'):
+                    if (asbool(value) != obj.get(field, False)) ^ neg:
+                        break
                 else:
                     if (value != str(obj.get(field, ''))) ^ neg:
                         break
             else:
                 result.append(obj)
+
+        if asbool(kw.get('hl')):
+            result.highlighting = {}
         return result
 
     def delete(self, *args, **kwargs):
diff --git a/Allura/allura/tests/functional/test_search.py b/Allura/allura/tests/functional/test_search.py
index 118c0f0..fe0cb46 100644
--- a/Allura/allura/tests/functional/test_search.py
+++ b/Allura/allura/tests/functional/test_search.py
@@ -14,9 +14,10 @@
 #       KIND, either express or implied.  See the License for the
 #       specific language governing permissions and limitations
 #       under the License.
-
 from mock import patch
+
 from allura.tests import TestController
+from allura.tests.decorators import with_tool
 
 
 class TestSearch(TestController):
@@ -28,6 +29,9 @@ class TestSearch(TestController):
         self.app.get('/search/', params=dict(q='Root'))
         assert search.called, search.called
 
+    # use test2 project since 'test' project has a subproject and MockSOLR can't handle "OR" (caused by subproject)
+    @with_tool('test2', 'Wiki', 'wiki')
     def test_project_search_controller(self):
-        self.app.get('/p/test/search/')
-        self.app.get('/p/test/search/', params=dict(q='Root'))
+        self.app.get('/p/test2/search/')
+        resp = self.app.get('/p/test2/search/', params=dict(q='wiki'))
+        resp.mustcontain('Welcome to your wiki! This is the default page')