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

asf-gitbox-commits pushed a commit to branch db/8607
in repository https://gitbox.apache.org/repos/asf/allura.git

commit ec1c4303b5bf7e009f3d91b8b955a82690ce5fe3
Author: Dave Brondsema <[email protected]>
AuthorDate: Tue May 26 13:07:13 2026 -0400

    [#8607] solr: move **kw to specific params for all other tools using common 
search_app helper
---
 Allura/allura/controllers/search.py                | 17 +++++++-------
 Allura/allura/ext/search/search_main.py            | 19 +++++++--------
 Allura/allura/lib/search.py                        | 18 +++++++--------
 Allura/allura/tests/unit/test_solr.py              |  8 +++----
 ForgeBlog/forgeblog/main.py                        | 27 +++++++++++-----------
 ForgeChat/forgechat/main.py                        | 19 ++++++++-------
 .../forgediscussion/controllers/root.py            | 21 ++++++++---------
 ForgeShortUrl/forgeshorturl/main.py                | 23 +++++++++---------
 ForgeWiki/forgewiki/wiki_main.py                   | 25 ++++++++++----------
 9 files changed, 89 insertions(+), 88 deletions(-)

diff --git a/Allura/allura/controllers/search.py 
b/Allura/allura/controllers/search.py
index 31c5f1e48..a0dc62a5d 100644
--- a/Allura/allura/controllers/search.py
+++ b/Allura/allura/controllers/search.py
@@ -41,15 +41,16 @@ class SearchController(BaseController):
     @validate(dict(q=V.UnicodeString(),
                    history=V.StringBool(if_empty=False)))
     @with_trailing_slash
-    def index(self, q=None, history=False, **kw):
+    def index(self, q=None, history=False, limit=None, page=0, sort='score 
desc'):
         c.search_results = W.search_results
-        search_params = kw
-        search_params.update({
-            'q': q,
-            'history': history,
-            'app': False,
-        })
-        d = search_app(**search_params)
+        d = search_app(
+            q=q,
+            history=history,
+            app=False,
+            limit=limit,
+            page=page,
+            sort=sort,
+        )
         d['search_comments_disable'] = True
         d['hide_app_project_switcher'] = True
         return d
diff --git a/Allura/allura/ext/search/search_main.py 
b/Allura/allura/ext/search/search_main.py
index 72c0c58e0..b95f17a60 100644
--- a/Allura/allura/ext/search/search_main.py
+++ b/Allura/allura/ext/search/search_main.py
@@ -70,22 +70,23 @@ class SearchController(BaseController):
     @validate(dict(q=V.UnicodeString(),
                    history=V.StringBool(if_empty=False)))
     @with_trailing_slash
-    def index(self, q=None, history=None, **kw):
+    def index(self, q=None, history=None, limit=None, page=0, sort='score 
desc'):
         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(map(str, pids))
-        search_params = kw
-        search_params.update({
-            'q': q,
-            'history': history,
-            'app': False,
-            'fq': [
+        d = search_app(
+            q=q,
+            history=history,
+            app=False,
+            fq=[
                 'project_id_s:(%s)' % project_match,
                 '-deleted_b:true',
             ],
-        })
-        d = search_app(**search_params)
+            limit=limit,
+            page=page,
+            sort=sort,
+        )
         d['search_comments_disable'] = True
         d['hide_app_project_switcher'] = True
         return d
diff --git a/Allura/allura/lib/search.py b/Allura/allura/lib/search.py
index 147c30c47..6dd6693db 100644
--- a/Allura/allura/lib/search.py
+++ b/Allura/allura/lib/search.py
@@ -239,7 +239,9 @@ def site_admin_search(model, q, field, **kw):
     return search(q, fq=fq, ignore_errors=False, **kw)
 
 
-def search_app(q='', fq=None, app=True, **kw):
+def search_app(q='', fq=None, app: bool = True, history: bool = False, 
project: bool = False,
+               search_comments: bool = False, limit=None, page=0, default=25,
+               allowed_types: list | None = None, parser=None, sort='score 
desc'):
     """Helper for app/project search.
 
     Uses dismax query parser. Matches on `title` and `text`. Handles paging, 
sorting, etc
@@ -247,19 +249,15 @@ def search_app(q='', fq=None, app=True, **kw):
     from allura.model import ArtifactReference
     from allura.lib.security import has_access
 
-    history = kw.pop('history', None)
-    if app and kw.pop('project', False):
+    if app and project:
         # Used from app's search controller. If `project` is True, redirect to
         # 'entire project search' page
         redirect(c.project.url() + 'search/?' +
                  urlencode(dict(q=q, history=history)))
-    search_comments = kw.pop('search_comments', None)
-    limit = kw.pop('limit', None)
-    page = kw.pop('page', 0)
-    default = kw.pop('default', 25)
-    allowed_types = kw.pop('allowed_types', [])
-    parser = kw.pop('parser', None)
-    sort = kw.pop('sort', 'score desc')
+    if allowed_types is None:
+        allowed_types = []
+    if app and not allowed_types:
+        raise ValueError('app search requires allowed_types')
     fq = fq if fq else []
     search_error = None
     results = []
diff --git a/Allura/allura/tests/unit/test_solr.py 
b/Allura/allura/tests/unit/test_solr.py
index 83d6b167f..06c45f285 100644
--- a/Allura/allura/tests/unit/test_solr.py
+++ b/Allura/allura/tests/unit/test_solr.py
@@ -177,10 +177,10 @@ def test_basic(self, req, url_fn):
         req.path = '/test/search'
         url_fn.side_effect = ['the-score-url', 'the-date-url']
         with h.push_context('test', 'wiki', neighborhood='Projects'):
-            resp = search_app(q='foo bar')
+            resp = search_app(q='foo bar', allowed_types=['WikiPage', 
'WikiPage Snapshot'])
         assert resp == dict(
             q='foo bar',
-            history=None,
+            history=False,
             results=[],
             count=0,
             limit=25,
@@ -216,11 +216,11 @@ def test_escape_solr_text(self, req, url_fn, solr_search):
         results.__len__ = lambda self: len(results.docs)
         solr_search.return_value = results
         with h.push_context('test', 'wiki', neighborhood='Projects'):
-            resp = search_app(q='foo bar')
+            resp = search_app(q='foo bar', allowed_types=['WikiPage', 
'WikiPage Snapshot'])
 
         assert resp == dict(
             q='foo bar',
-            history=None,
+            history=False,
             count=2,
             limit=25,
             page=0,
diff --git a/ForgeBlog/forgeblog/main.py b/ForgeBlog/forgeblog/main.py
index 15614b7ec..9dce9b057 100644
--- a/ForgeBlog/forgeblog/main.py
+++ b/ForgeBlog/forgeblog/main.py
@@ -296,21 +296,22 @@ def index(self, page=0, limit=None, **kw):
                    history=validators.StringBool(if_empty=False),
                    search_comments=validators.StringBool(if_empty=False),
                    project=validators.StringBool(if_empty=False)))
-    def search(self, q=None, history=None, search_comments=None, project=None, 
limit=None, page=0, **kw):
+    def search(self, q=None, history=None, search_comments=None, project=None,
+               limit=None, page=0, sort='score desc', parser=None):
         c.search_results = W.search_results
         c.help_modal = W.help_modal
-        search_params = kw
-        search_params.update({
-            'q': q or '',
-            'history': history,
-            'search_comments': search_comments,
-            'project': project,
-            'limit': limit,
-            'page': page,
-            'allowed_types': ['Blog Post', 'Blog Post Snapshot'],
-            'fq': ['state_s:published']
-        })
-        return search_app(**search_params)
+        return search_app(
+            q=q or '',
+            history=history,
+            search_comments=search_comments,
+            project=project,
+            limit=limit,
+            page=page,
+            sort=sort,
+            parser=parser,
+            allowed_types=['Blog Post', 'Blog Post Snapshot'],
+            fq=['state_s:published'],
+        )
 
     @expose('jinja:forgeblog:templates/blog/edit_post.html')
     @without_trailing_slash
diff --git a/ForgeChat/forgechat/main.py b/ForgeChat/forgechat/main.py
index 8d7ccdeec..b09d0b31d 100644
--- a/ForgeChat/forgechat/main.py
+++ b/ForgeChat/forgechat/main.py
@@ -151,21 +151,20 @@ def index(self, **kw):
     @expose('jinja:forgechat:templates/chat/search.html')
     @validate(dict(q=v.UnicodeString(if_empty=None),
                    project=validators.StringBool(if_empty=False)))
-    def search(self, q=None, project=None, limit=None, page=0, **kw):
+    def search(self, q=None, project=None, limit=None, page=0, sort='score 
desc'):
         c.search_results = SearchResults()
         c.help_modal = SearchHelp(comments=False, history=False,
                                   fields={'sender_t': 'username',
                                           'text': '"Message text"',
                                           })
-        search_params = kw
-        search_params.update({
-            'q': q or '',
-            'project': project,
-            'limit': limit,
-            'page': page,
-            'allowed_types': ['Chat Message'],
-        })
-        d = search_app(**search_params)
+        d = search_app(
+            q=q or '',
+            project=project,
+            limit=limit,
+            page=page,
+            sort=sort,
+            allowed_types=['Chat Message'],
+        )
         d['search_comments_disable'] = True
         d['search_history_disable'] = True
         return d
diff --git a/ForgeDiscussion/forgediscussion/controllers/root.py 
b/ForgeDiscussion/forgediscussion/controllers/root.py
index bac7196ce..5caaa9c4d 100644
--- a/ForgeDiscussion/forgediscussion/controllers/root.py
+++ b/ForgeDiscussion/forgediscussion/controllers/root.py
@@ -163,19 +163,18 @@ def save_new_topic(self, subject=None, text=None, 
forum=None, subscribe=False, *
                    project=validators.StringBool(if_empty=False),
                    limit=validators.Int(if_empty=None, if_invalid=None),
                    page=validators.Int(if_empty=0, if_invalid=0)))
-    def search(self, q=None, history=None, project=None, limit=None, page=0, 
**kw):
+    def search(self, q=None, history=None, project=None, limit=None, page=0, 
sort='score desc'):
         c.search_results = self.W.search_results
         c.help_modal = self.W.search_help
-        search_params = kw
-        search_params.update({
-            'q': q or '',
-            'history': history,
-            'project': project,
-            'limit': limit,
-            'page': page,
-            'allowed_types': ['Post', 'Post Snapshot', 'Discussion', 'Thread'],
-        })
-        d = search_app(**search_params)
+        d = search_app(
+            q=q or '',
+            history=history,
+            project=project,
+            limit=limit,
+            page=page,
+            sort=sort,
+            allowed_types=['Post', 'Post Snapshot', 'Discussion', 'Thread'],
+        )
         d['search_comments_disable'] = True
         return d
 
diff --git a/ForgeShortUrl/forgeshorturl/main.py 
b/ForgeShortUrl/forgeshorturl/main.py
index 72dbaf277..904a5bc89 100644
--- a/ForgeShortUrl/forgeshorturl/main.py
+++ b/ForgeShortUrl/forgeshorturl/main.py
@@ -160,20 +160,21 @@ def index(self, page=0, limit=None, **kw):
     @expose('jinja:forgeshorturl:templates/search.html')
     @validate(dict(q=v.UnicodeString(if_empty=None),
                    project=validators.StringBool(if_empty=False)))
-    def search(self, q=None, project=None, limit=None, page=0, **kw):
+    def search(self, q=None, project=None, limit=None, page=0, sort='score 
desc'):
         c.search_results = W.search_results
         c.help_modal = W.search_help
-        search_params = kw
-        search_params.update({
-            'q': q or '',
-            'project': project,
-            'limit': limit,
-            'page': page,
-            'allowed_types': ['ShortUrl'],
-        })
+        fq = None
         if not has_access(c.app, 'view_private'):
-            search_params['fq'] = ['private_b:False']
-        d = search_app(**search_params)
+            fq = ['private_b:False']
+        d = search_app(
+            q=q or '',
+            project=project,
+            limit=limit,
+            page=page,
+            sort=sort,
+            allowed_types=['ShortUrl'],
+            fq=fq,
+        )
         d['search_comments_disable'] = True
         d['search_history_disable'] = True
         d['url_len'] = len(ShortUrl.build_short_url(c.app, short_name=''))
diff --git a/ForgeWiki/forgewiki/wiki_main.py b/ForgeWiki/forgewiki/wiki_main.py
index 4843b4758..d93d56feb 100644
--- a/ForgeWiki/forgewiki/wiki_main.py
+++ b/ForgeWiki/forgewiki/wiki_main.py
@@ -438,21 +438,22 @@ def new_page(self, title):
                    history=validators.StringBool(if_empty=False),
                    search_comments=validators.StringBool(if_empty=False),
                    project=validators.StringBool(if_empty=False)))
-    def search(self, q=None, history=None, search_comments=None, project=None, 
limit=None, page=0, **kw):
+    def search(self, q=None, history=None, search_comments=None, project=None,
+               limit=None, page=0, sort='score desc', parser=None):
         'local wiki search'
         c.search_results = W.search_results
         c.help_modal = W.help_modal
-        search_params = kw
-        search_params.update({
-            'q': q or '',
-            'history': history,
-            'search_comments': search_comments,
-            'project': project,
-            'limit': limit,
-            'page': page,
-            'allowed_types': ['WikiPage', 'WikiPage Snapshot'],
-        })
-        return search_app(**search_params)
+        return search_app(
+            q=q or '',
+            history=history,
+            search_comments=search_comments,
+            project=project,
+            limit=limit,
+            page=page,
+            sort=sort,
+            parser=parser,
+            allowed_types=['WikiPage', 'WikiPage Snapshot'],
+        )
 
     @with_trailing_slash
     @expose('jinja:forgewiki:templates/wiki/browse.html')

Reply via email to