diff options
-rw-r--r-- | service/pixelated/adapter/search.py | 9 | ||||
-rw-r--r-- | service/pixelated/controllers/mails_controller.py | 2 | ||||
-rw-r--r-- | service/test/integration/search_test.py | 30 | ||||
-rw-r--r-- | service/test/support/integration_helper.py | 4 | ||||
-rw-r--r-- | web-ui/app/js/mail_list_actions/ui/pagination_trigger.js | 2 | ||||
-rw-r--r-- | web-ui/app/js/services/mail_service.js | 8 | ||||
-rw-r--r-- | web-ui/test/spec/mail_list_actions/ui/pagination_trigger.spec.js | 2 | ||||
-rw-r--r-- | web-ui/test/spec/services/mail_service.spec.js | 18 |
8 files changed, 53 insertions, 22 deletions
diff --git a/service/pixelated/adapter/search.py b/service/pixelated/adapter/search.py index 72e714e9..6b579d87 100644 --- a/service/pixelated/adapter/search.py +++ b/service/pixelated/adapter/search.py @@ -116,16 +116,17 @@ class SearchEngine(object): results = searcher.search(query, **options) return results - def search(self, query): - options = {'limit': 100} + def search(self, query, window, page): + page = int(page) if (page is not None and int(page) > 0) else 1 + window = int(window) or 25 query = query.replace('\"', '') query = query.replace('-in:', 'AND NOT tag:') query = query.replace('in:all', '*') with self._index.searcher() as searcher: - query = QueryParser('body', self._index.schema).parse(query) - results = searcher.search(query, **options) + query = QueryParser('raw', self._index.schema).parse(query) + results = searcher.search_page(query, page, pagelen=window) return [mail['ident'] for mail in results] def remove_from_index(self, mail_id): diff --git a/service/pixelated/controllers/mails_controller.py b/service/pixelated/controllers/mails_controller.py index 6765fc78..6bd2fe99 100644 --- a/service/pixelated/controllers/mails_controller.py +++ b/service/pixelated/controllers/mails_controller.py @@ -29,7 +29,7 @@ class MailsController: self._search_engine = search_engine def mails(self, _request=request): - mail_ids = self._search_engine.search(_request.args.get('q')) + mail_ids = self._search_engine.search(_request.args.get('q'), _request.args.get('w'), _request.args.get('p')) mails = self._mail_service.mails(mail_ids) mails = sorted(mails, key=lambda mail: dateparser.parse(mail.date), reverse=True) diff --git a/service/test/integration/search_test.py b/service/test/integration/search_test.py index 7323866d..81d1fad2 100644 --- a/service/test/integration/search_test.py +++ b/service/test/integration/search_test.py @@ -58,3 +58,33 @@ class SearchTest(unittest.TestCase, SoledadTestBase): all_tag_names = [t['name'] for t in all_tags] self.assertEqual(1, len(all_tag_names)) self.assertTrue('sometag' in all_tag_names) + + def test_search_mails_different_window(self): + input_mail = MailBuilder().build_input_mail() + input_mail2 = MailBuilder().build_input_mail() + self.add_mail_to_inbox(input_mail) + self.add_mail_to_inbox(input_mail2) + + first_page = self.get_mails_by_tag('inbox', page=1, window=1) + + self.assertEqual(len(first_page), 1) + + def test_search_mails_with_multiple_pages(self): + input_mail = MailBuilder().build_input_mail() + input_mail2 = MailBuilder().build_input_mail() + self.add_mail_to_inbox(input_mail) + self.add_mail_to_inbox(input_mail2) + + first_page = self.get_mails_by_tag('inbox', page=1, window=1) + second_page = self.get_mails_by_tag('inbox', page=2, window=1) + + idents = [input_mail.ident, input_mail2.ident] + + self.assertIn(first_page[0].ident, idents) + self.assertIn(second_page[0].ident, idents) + + def test_page_zero_fetches_first_page(self): + input_mail = MailBuilder().build_input_mail() + self.add_mail_to_inbox(input_mail) + page = self.get_mails_by_tag('inbox', page=0, window=1) + self.assertEqual(page[0].ident, input_mail.ident) diff --git a/service/test/support/integration_helper.py b/service/test/support/integration_helper.py index 268eb812..f0f3b02a 100644 --- a/service/test/support/integration_helper.py +++ b/service/test/support/integration_helper.py @@ -173,8 +173,8 @@ class SoledadTestBase: app_factory._setup_routes(self.client.application, home_controller, mails_controller, tags_controller, features_controller) - def get_mails_by_tag(self, tag): - response = json.loads(self.client.get("/mails?q=tag:" + tag).data) + def get_mails_by_tag(self, tag, page=1, window=100): + response = json.loads(self.client.get("/mails?q=tag:%s&w=%s&p=%s" % (tag, window, page)).data) return [ResponseMail(m) for m in response['mails']] def post_mail(self, data): diff --git a/web-ui/app/js/mail_list_actions/ui/pagination_trigger.js b/web-ui/app/js/mail_list_actions/ui/pagination_trigger.js index f9d531a4..3bc13d40 100644 --- a/web-ui/app/js/mail_list_actions/ui/pagination_trigger.js +++ b/web-ui/app/js/mail_list_actions/ui/pagination_trigger.js @@ -46,7 +46,7 @@ define( }; this.updatePageDisplay = function(event, data) { - this.renderWithPageNumber(data.currentPage + 1); + this.renderWithPageNumber(data.currentPage); }; this.previousPage = function(event) { diff --git a/web-ui/app/js/services/mail_service.js b/web-ui/app/js/services/mail_service.js index 2e877a2c..b773bd8b 100644 --- a/web-ui/app/js/services/mail_service.js +++ b/web-ui/app/js/services/mail_service.js @@ -38,8 +38,8 @@ define( singleMailResource: '/mail', currentTag: '', lastQuery: '', - currentPage: 0, - numPages: 0, + currentPage: 1, + numPages: 1, w: 25 }); @@ -150,7 +150,7 @@ define( this.fetchByTag = function (ev, data) { this.attr.currentTag = data.tag; - this.updateCurrentPageNumber(0); + this.updateCurrentPageNumber(1); this.fetchMail(compileQuery(data), this.attr.currentTag, false, data); }; @@ -223,7 +223,7 @@ define( }; this.previousPage = function () { - if (this.attr.currentPage > 0) { + if (this.attr.currentPage > 1) { this.updateCurrentPageNumber(this.attr.currentPage - 1); this.refreshResults(); } diff --git a/web-ui/test/spec/mail_list_actions/ui/pagination_trigger.spec.js b/web-ui/test/spec/mail_list_actions/ui/pagination_trigger.spec.js index bf47794a..d23c2839 100644 --- a/web-ui/test/spec/mail_list_actions/ui/pagination_trigger.spec.js +++ b/web-ui/test/spec/mail_list_actions/ui/pagination_trigger.spec.js @@ -21,6 +21,6 @@ describeComponent('mail_list_actions/ui/pagination_trigger', function () { it('re-renders with current page number when page changes', function () { this.component.trigger(document, Pixelated.events.ui.page.changed, {currentPage: 0}); - expect(this.component.select('currentPage').text()).toBe('1'); + expect(this.component.select('currentPage').text()).toBe('0'); }); }); diff --git a/web-ui/test/spec/services/mail_service.spec.js b/web-ui/test/spec/services/mail_service.spec.js index bce54857..85680cb6 100644 --- a/web-ui/test/spec/services/mail_service.spec.js +++ b/web-ui/test/spec/services/mail_service.spec.js @@ -210,21 +210,21 @@ describeComponent('services/mail_service', function () { }); it('changes to the previous page and refetch email when ui:page:previous is fired', function() { - this.component.attr.currentPage = 1; + this.component.attr.currentPage = 2; this.component.trigger(Pixelated.events.ui.page.previous); expect(this.component.fetchMail).toHaveBeenCalled(); - expect(this.component.attr.currentPage).toEqual(0); + expect(this.component.attr.currentPage).toEqual(1); }); it('won\'t change the page if it was already at the first page and trying to go to previous', function() { - this.component.attr.currentPage = 0; + this.component.attr.currentPage = 1; this.component.trigger(Pixelated.events.ui.page.previous); expect(this.component.fetchMail).not.toHaveBeenCalled(); - expect(this.component.attr.currentPage).toEqual(0); + expect(this.component.attr.currentPage).toEqual(1); }); it('changes to the next page and refetch email when ui:page:next is fired', function() { @@ -252,15 +252,15 @@ describeComponent('services/mail_service', function () { this.component.attr.numPages = 10; this.component.trigger(Pixelated.events.ui.page.next); - expect(pageChangedEvent).toHaveBeenTriggeredOnAndWith(document, {currentPage: 1, numPages: 10}); + expect(pageChangedEvent).toHaveBeenTriggeredOnAndWith(document, {currentPage: 2, numPages: 10}); }); it('triggers pageChanged event when going to previous page', function() { this.component.attr.numPages = 10; - this.component.attr.currentPage = 1; + this.component.attr.currentPage = 2; this.component.trigger(Pixelated.events.ui.page.previous); - expect(pageChangedEvent).toHaveBeenTriggeredOnAndWith(document, {currentPage: 0, numPages: 10}); + expect(pageChangedEvent).toHaveBeenTriggeredOnAndWith(document, {currentPage: 1, numPages: 10}); }); it('resets currentPage when fetching mails by tag', function() { @@ -268,8 +268,8 @@ describeComponent('services/mail_service', function () { this.component.attr.currentPage = 999; this.component.trigger(Pixelated.events.ui.mails.fetchByTag, {tag: 'inbox'}); - expect(this.component.attr.currentPage).toEqual(0); - expect(pageChangedEvent).toHaveBeenTriggeredOnAndWith(document, {currentPage: 0, numPages: 10}); + expect(this.component.attr.currentPage).toEqual(1); + expect(pageChangedEvent).toHaveBeenTriggeredOnAndWith(document, {currentPage: 1, numPages: 10}); }); describe('total page numbers', function() { |