allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brond...@apache.org
Subject [07/38] git commit: [#4019] ticket:481 Switch mongo/solr query based on filter
Date Wed, 30 Apr 2014 18:15:39 GMT
[#4019] ticket:481 Switch mongo/solr query based on filter


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

Branch: refs/heads/master
Commit: f3eb719ab93d2f299c8ffdd646d619e801924b44
Parents: bd7767d
Author: Igor Bondarenko <jetmind2@gmail.com>
Authored: Thu Dec 19 11:54:14 2013 +0200
Committer: Dave Brondsema <dbrondsema@slashdotmedia.com>
Committed: Wed Apr 30 15:55:09 2014 +0000

----------------------------------------------------------------------
 ForgeTracker/forgetracker/model/ticket.py | 24 ++++++++++++
 ForgeTracker/forgetracker/tracker_main.py | 51 ++++++++++++++++++--------
 2 files changed, 59 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/f3eb719a/ForgeTracker/forgetracker/model/ticket.py
----------------------------------------------------------------------
diff --git a/ForgeTracker/forgetracker/model/ticket.py b/ForgeTracker/forgetracker/model/ticket.py
index 72cc23a..3c2e7a6 100644
--- a/ForgeTracker/forgetracker/model/ticket.py
+++ b/ForgeTracker/forgetracker/model/ticket.py
@@ -1191,6 +1191,30 @@ class Ticket(VersionedArtifact, ActivityObject, VotableArtifact):
                     filter=json.dumps(filter),
                     solr_error=solr_error, **kw)
 
+    @classmethod
+    def paged_query_or_search(cls, app_config, user, query, search_query, filter,
+                              limit=None, page=0, sort=None, **kw):
+        """Switch between paged_query and paged_search based on filter.
+
+        query - query in mongo syntax
+        search_query - query in solr syntax
+        """
+        solr_sort = None
+        if sort:
+            from forgetracker.tracker_main import _mongo_col_to_solr_col
+            sort_split = sort.split(' ')
+            solr_col = _mongo_col_to_solr_col(sort_split[0])
+            solr_sort = '%s %s' % (solr_col, sort_split[1])
+        if not filter:
+            result = cls.paged_query(app_config, user, query, sort=sort, limit=limit, page=page,
**kw)
+        else:
+            result = cls.paged_search(app_config, user, search_query, filter=filter,
+                                      sort=solr_sort, limit=limit, page=page, **kw)
+
+        result['sort'] = sort
+        result['url_sort'] = solr_sort if solr_sort else ''
+        return result
+
     def get_mail_footer(self, notification, toaddr):
         if toaddr and toaddr == self.monitoring_email:
             return MailFooter.monitored(

http://git-wip-us.apache.org/repos/asf/allura/blob/f3eb719a/ForgeTracker/forgetracker/tracker_main.py
----------------------------------------------------------------------
diff --git a/ForgeTracker/forgetracker/tracker_main.py b/ForgeTracker/forgetracker/tracker_main.py
index e149af5..eb9de0f 100644
--- a/ForgeTracker/forgetracker/tracker_main.py
+++ b/ForgeTracker/forgetracker/tracker_main.py
@@ -638,18 +638,23 @@ class RootController(BaseController, FeedController):
     @with_trailing_slash
     @h.vardec
     @expose('jinja:forgetracker:templates/tracker/index.html')
-    @validate(dict(deleted=validators.StringBool(if_empty=False)))
-    def index(self, limit=25, columns=None, page=0, sort='ticket_num desc', deleted=False,
**kw):
+    @validate(dict(deleted=validators.StringBool(if_empty=False),
+                   filter=V.JsonConverter(if_empty={})))
+    def index(self, limit=25, columns=None, page=0, sort='ticket_num desc', deleted=False,
filter=None, **kw):
         show_deleted = [False]
         if deleted and has_access(c.app, 'delete'):
             show_deleted = [False, True]
 
         # it's just our original query mangled and sent back to us
         kw.pop('q', None)
-        result = TM.Ticket.paged_query(c.app.config, c.user,
-                                       c.app.globals.not_closed_mongo_query,
-                                       sort=sort, limit=int(limit),
-                                       page=page, deleted={'$in': show_deleted}, **kw)
+        result = TM.Ticket.paged_query_or_search(c.app.config, c.user,
+                                                 c.app.globals.not_closed_mongo_query,
+                                                 c.app.globals.not_closed_query,
+                                                 filter,
+                                                 sort=sort, limit=int(limit), page=page,
+                                                 deleted={'$in': show_deleted},
+                                                 show_deleted=deleted, **kw)
+
         result['columns'] = columns or mongo_columns()
         result[
             'sortable_custom_fields'] = c.app.globals.sortable_custom_fields_shown_in_search()
@@ -659,12 +664,7 @@ class RootController(BaseController, FeedController):
         result['help_msg'] = c.app.config.options.get(
             'TicketHelpSearch', '').strip()
         result['url_q'] = c.app.globals.not_closed_query
-        result['url_sort'] = ''
         result['deleted'] = deleted
-        if sort:
-            sort_split = sort.split(' ')
-            solr_col = _mongo_col_to_solr_col(sort_split[0])
-            result['url_sort'] = '%s %s' % (solr_col, sort_split[1])
         c.subscribe_form = W.subscribe_form
         c.ticket_search_results = TicketSearchResults()
         return result
@@ -1805,24 +1805,48 @@ class MilestoneController(BaseController):
         self.milestone = m
         self.progress_key = '%s:%s' % (fld.name, m.name.replace(':', '\:'))
         self.mongo_query = {
+<<<<<<< HEAD
             'custom_fields.%s' % fld.name: m.name}
+=======
+            'custom_fields.%s' % fld.name: m.name }
+        self.solr_query = '%s:%s' % (_mongo_col_to_solr_col(fld.name), m.name)
+>>>>>>> [#4019] ticket:481 Switch mongo/solr query based on filter
 
     @with_trailing_slash
     @h.vardec
     @expose('jinja:forgetracker:templates/tracker/milestone.html')
     @validate(validators=dict(
+<<<<<<< HEAD
         limit=validators.Int(if_invalid=None),
         page=validators.Int(if_empty=0, if_invalid=0),
         sort=validators.UnicodeString(if_empty=None),
         deleted=validators.StringBool(if_empty=False)))
     def index(self, q=None, columns=None, page=0, query=None, sort=None, deleted=False, **kw):
+=======
+            limit=validators.Int(if_invalid=None),
+            page=validators.Int(if_empty=0, if_invalid=0),
+            sort=validators.UnicodeString(if_empty=''),
+            filter=V.JsonConverter(if_empty={}),
+            deleted=validators.StringBool(if_empty=False)))
+    def index(self, q=None, columns=None, page=0, query=None, sort=None,
+              deleted=False, filter=None, **kw):
+>>>>>>> [#4019] ticket:481 Switch mongo/solr query based on filter
         require(has_access(c.app, 'read'))
         show_deleted = [False]
         if deleted and has_access(c.app, 'delete'):
             show_deleted = [False, True]
 
+<<<<<<< HEAD
         result = TM.Ticket.paged_query(c.app.config, c.user,
                                        self.mongo_query, page=page, sort=sort, deleted={'$in':
show_deleted}, **kw)
+=======
+        result = TM.Ticket.paged_query_or_search(c.app.config, c.user,
+                                                 self.mongo_query,
+                                                 self.solr_query,
+                                                 filter, sort=sort, page=page,
+                                                 deleted={'$in': show_deleted},
+                                                 show_deleted=deleted, **kw)
+>>>>>>> [#4019] ticket:481 Switch mongo/solr query based on filter
         result['columns'] = columns or mongo_columns()
         result[
             'sortable_custom_fields'] = c.app.globals.sortable_custom_fields_shown_in_search()
@@ -1839,11 +1863,6 @@ class MilestoneController(BaseController):
             total=progress['hits'],
             closed=progress['closed'],
             q=self.progress_key)
-        result['url_sort'] = ''
-        if sort:
-            sort_split = sort.split(' ')
-            solr_col = _mongo_col_to_solr_col(sort_split[0])
-            result['url_sort'] = '%s %s' % (solr_col, sort_split[1])
         c.ticket_search_results = TicketSearchResults()
         c.auto_resize_textarea = W.auto_resize_textarea
         return result


Mime
View raw message