diff options
author | Giovane <giovaneliberato@gmail.com> | 2015-11-03 17:59:07 -0200 |
---|---|---|
committer | Giovane <giovaneliberato@gmail.com> | 2015-11-03 17:59:41 -0200 |
commit | 0f84c6354a116fd53628b23a56c1528c5dd3e8ef (patch) | |
tree | d20846b7b47dd613fffce87ce8a43b686d658819 | |
parent | af7631369c96d3da54abb4e1cab44ea61151c481 (diff) |
[#508] Making search also work with substrings - pairing w/ @pereiragislene
-rw-r--r-- | service/pixelated/adapter/mailstore/leap_mailstore.py | 2 | ||||
-rw-r--r-- | service/pixelated/adapter/search/__init__.py | 10 | ||||
-rw-r--r-- | web-ui/app/js/search/results_highlighter.js | 2 | ||||
-rw-r--r-- | web-ui/test/spec/search/results_highlighter.spec.js | 4 |
4 files changed, 9 insertions, 9 deletions
diff --git a/service/pixelated/adapter/mailstore/leap_mailstore.py b/service/pixelated/adapter/mailstore/leap_mailstore.py index 2754c624..519b124a 100644 --- a/service/pixelated/adapter/mailstore/leap_mailstore.py +++ b/service/pixelated/adapter/mailstore/leap_mailstore.py @@ -223,7 +223,7 @@ class LeapMailStore(MailStore): def get_mails(self, mail_ids): deferreds = [] for mail_id in mail_ids: - deferreds.append(self.get_mail(mail_id)) + deferreds.append(self.get_mail(mail_id, include_body=True)) return defer.gatherResults(deferreds, consumeErrors=True) diff --git a/service/pixelated/adapter/search/__init__.py b/service/pixelated/adapter/search/__init__.py index 56ab2255..065dd5e5 100644 --- a/service/pixelated/adapter/search/__init__.py +++ b/service/pixelated/adapter/search/__init__.py @@ -23,7 +23,7 @@ import time from pixelated.adapter.model.status import Status from pixelated.adapter.search.contacts import contacts_suggestions from whoosh.index import FileIndex -from whoosh.fields import Schema, ID, KEYWORD, TEXT, NUMERIC +from whoosh.fields import Schema, ID, KEYWORD, TEXT, NUMERIC, NGRAMWORDS from whoosh.qparser import QueryParser from whoosh.qparser import MultifieldParser from whoosh.writing import AsyncWriter @@ -103,9 +103,9 @@ class SearchEngine(object): to=KEYWORD(stored=False, commas=True), cc=KEYWORD(stored=False, commas=True), bcc=KEYWORD(stored=False, commas=True), - subject=TEXT(stored=False), + subject=NGRAMWORDS(stored=False), date=NUMERIC(stored=False, sortable=True, bits=64, signed=False), - body=TEXT(stored=False), + body=NGRAMWORDS(stored=False), tag=KEYWORD(stored=True, commas=True), flags=KEYWORD(stored=True, commas=True), raw=TEXT(stored=False)) @@ -116,7 +116,7 @@ class SearchEngine(object): def index_mail(self, mail): with AsyncWriter(self._index) as writer: - self._index_mail(writer, mail) + self._index_mail(writer, mail) def _index_mail(self, writer, mail): mdict = mail.as_dict() @@ -197,7 +197,7 @@ class SearchEngine(object): .replace('-in:', 'AND NOT tag:') .replace('in:all', '*') ) - return MultifieldParser(['raw', 'body'], self._index.schema).parse(query) + return MultifieldParser(['body', 'subject', 'raw'], self._index.schema).parse(query) def remove_from_index(self, mail_id): with AsyncWriter(self._index) as writer: diff --git a/web-ui/app/js/search/results_highlighter.js b/web-ui/app/js/search/results_highlighter.js index 2c7d1cc7..9e3ba167 100644 --- a/web-ui/app/js/search/results_highlighter.js +++ b/web-ui/app/js/search/results_highlighter.js @@ -40,7 +40,7 @@ define( var domIdent = data.where; if(this.attr.keywords) { _.each(this.attr.keywords, function (keyword) { - $(domIdent).highlightRegex(new RegExp('\\b' + keyword, 'i'), { + $(domIdent).highlightRegex(new RegExp(keyword, 'i'), { tagType: 'em', className: 'search-highlight' }); diff --git a/web-ui/test/spec/search/results_highlighter.spec.js b/web-ui/test/spec/search/results_highlighter.spec.js index 523c3599..cfb61e9c 100644 --- a/web-ui/test/spec/search/results_highlighter.spec.js +++ b/web-ui/test/spec/search/results_highlighter.spec.js @@ -1,7 +1,7 @@ describeComponent('search/results_highlighter', function () { 'use strict'; - it('highlights only words that matches with the keywords given', function () { + it('highlights words or parts of words that match with the keywords given', function () { this.setupComponent('<div id="text">Any one seeing too many open bugs</div>'); this.component.attr = {keywords: ['any']}; @@ -9,7 +9,7 @@ describeComponent('search/results_highlighter', function () { var highlightedWords = this.component.$node.find('.search-highlight').length; - expect(highlightedWords).toEqual(1); + expect(highlightedWords).toEqual(2); }); it('resets highlights when a new search is performed', function() { |