mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-09-13 16:14:36 +08:00
feat(subject-search): Use basic LIKE query and date ordering to find likely emails
Summary: Begins to fix T1866, but for now only doing a LIKE instead of FTS4, because there are many, many other things to think about there. Test Plan: No new tests. I still want to rewrite the whole search bar. Reviewers: evan Reviewed By: evan Maniphest Tasks: T1866 Differential Revision: https://phab.nylas.com/D1634
This commit is contained in:
parent
646e159a69
commit
e090dd428a
3 changed files with 63 additions and 16 deletions
|
@ -64,6 +64,8 @@ class SearchBar extends React.Component
|
||||||
<Menu.Item divider={item.divider} />
|
<Menu.Item divider={item.divider} />
|
||||||
else if item.contact
|
else if item.contact
|
||||||
<Menu.NameEmailItem name={item.contact.name} email={item.contact.email} />
|
<Menu.NameEmailItem name={item.contact.name} email={item.contact.email} />
|
||||||
|
else if item.thread
|
||||||
|
item.thread.subject
|
||||||
else
|
else
|
||||||
item.label
|
item.label
|
||||||
|
|
||||||
|
@ -73,7 +75,7 @@ class SearchBar extends React.Component
|
||||||
headerComponents={headerComponents}
|
headerComponents={headerComponents}
|
||||||
items={@state.suggestions}
|
items={@state.suggestions}
|
||||||
itemContent={itemContentFunc}
|
itemContent={itemContentFunc}
|
||||||
itemKey={ (item) -> item.label }
|
itemKey={ (item) -> item.id ? item.label }
|
||||||
onSelect={@_onSelectSuggestion}
|
onSelect={@_onSelectSuggestion}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
@ -109,6 +111,10 @@ class SearchBar extends React.Component
|
||||||
@_onClearSearch()
|
@_onClearSearch()
|
||||||
|
|
||||||
_onSelectSuggestion: (item) =>
|
_onSelectSuggestion: (item) =>
|
||||||
|
if item.thread?
|
||||||
|
Actions.searchQueryCommitted(null)
|
||||||
|
Actions.setFocus({collection: 'thread', item: item.thread})
|
||||||
|
else
|
||||||
Actions.searchQueryCommitted(item.value)
|
Actions.searchQueryCommitted(item.value)
|
||||||
|
|
||||||
_onClearSearch: (event) =>
|
_onClearSearch: (event) =>
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
Reflux = require 'reflux'
|
Reflux = require 'reflux'
|
||||||
{Actions,
|
{Actions,
|
||||||
Contact,
|
Contact,
|
||||||
|
Thread,
|
||||||
|
DatabaseStore,
|
||||||
ContactStore} = require 'nylas-exports'
|
ContactStore} = require 'nylas-exports'
|
||||||
_ = require 'underscore'
|
_ = require 'underscore'
|
||||||
|
|
||||||
|
@ -11,9 +13,9 @@ _ = require 'underscore'
|
||||||
|
|
||||||
SearchSuggestionStore = Reflux.createStore
|
SearchSuggestionStore = Reflux.createStore
|
||||||
init: ->
|
init: ->
|
||||||
@_suggestions = []
|
|
||||||
@_query = ""
|
@_query = ""
|
||||||
@_committedQuery = ""
|
@_committedQuery = ""
|
||||||
|
@_clearResults()
|
||||||
|
|
||||||
@listenTo Actions.searchQueryChanged, @onSearchQueryChanged
|
@listenTo Actions.searchQueryChanged, @onSearchQueryChanged
|
||||||
@listenTo Actions.searchQueryCommitted, @onSearchQueryCommitted
|
@listenTo Actions.searchQueryCommitted, @onSearchQueryCommitted
|
||||||
|
@ -21,38 +23,69 @@ SearchSuggestionStore = Reflux.createStore
|
||||||
|
|
||||||
onSearchQueryChanged: (query) ->
|
onSearchQueryChanged: (query) ->
|
||||||
@_query = query
|
@_query = query
|
||||||
@repopulate()
|
@_rebuildResults()
|
||||||
|
|
||||||
onSearchQueryCommitted: (query) ->
|
onSearchQueryCommitted: (query) ->
|
||||||
@_query = query
|
@_query = query
|
||||||
@_committedQuery = query
|
@_committedQuery = query
|
||||||
@_suggestions = []
|
@_clearResults()
|
||||||
@trigger()
|
@trigger()
|
||||||
|
|
||||||
onSearchBlurred: ->
|
onSearchBlurred: ->
|
||||||
@_suggestions = []
|
@_clearResults()
|
||||||
@trigger()
|
@trigger()
|
||||||
|
|
||||||
repopulate: ->
|
_clearResults: ->
|
||||||
|
@_threadResults = null
|
||||||
|
@_contactResults = null
|
||||||
@_suggestions = []
|
@_suggestions = []
|
||||||
term = @_query?[0]
|
|
||||||
return @trigger(@) unless term
|
|
||||||
|
|
||||||
key = Object.keys(term)[0]
|
_rebuildResults: ->
|
||||||
val = term[key]
|
{key, val} = @queryKeyAndVal()
|
||||||
return @trigger(@) unless val
|
return @trigger(@) unless key and val
|
||||||
|
|
||||||
contactResults = ContactStore.searchContacts(val, limit:10)
|
@_contactResults = ContactStore.searchContacts(val, limit:10)
|
||||||
|
@_rebuildThreadResults()
|
||||||
|
@_compileSuggestions()
|
||||||
|
|
||||||
|
_rebuildThreadResults: ->
|
||||||
|
{key, val} = @queryKeyAndVal()
|
||||||
|
|
||||||
|
# Don't update thread results if a previous query is still running, it'll
|
||||||
|
# just make performance even worse. When the old result comes in, re-run
|
||||||
|
return if @_threadQueryInFlight
|
||||||
|
|
||||||
|
@_threadQueryInFlight = true
|
||||||
|
DatabaseStore.findAll(Thread, [Thread.attributes.subject.like(val)])
|
||||||
|
.order(Thread.attributes.lastMessageTimestamp.descending())
|
||||||
|
.limit(4)
|
||||||
|
.then (results) =>
|
||||||
|
@_threadQueryInFlight = false
|
||||||
|
if val is @queryKeyAndVal().val
|
||||||
|
@_threadResults = results
|
||||||
|
@_compileSuggestions()
|
||||||
|
else
|
||||||
|
@_rebuildThreadResults()
|
||||||
|
|
||||||
|
_compileSuggestions: ->
|
||||||
|
{key, val} = @queryKeyAndVal()
|
||||||
|
return unless key and val
|
||||||
|
|
||||||
|
@_suggestions = []
|
||||||
@_suggestions.push
|
@_suggestions.push
|
||||||
label: "Message Contains: #{val}"
|
label: "Message Contains: #{val}"
|
||||||
value: [{"all": val}]
|
value: [{"all": val}]
|
||||||
|
|
||||||
if contactResults.length
|
if @_threadResults?.length
|
||||||
|
@_suggestions.push
|
||||||
|
divider: 'Threads'
|
||||||
|
_.each @_threadResults, (thread) =>
|
||||||
|
@_suggestions.push({thread: thread})
|
||||||
|
|
||||||
|
if @_contactResults?.length
|
||||||
@_suggestions.push
|
@_suggestions.push
|
||||||
divider: 'People'
|
divider: 'People'
|
||||||
|
_.each @_contactResults, (contact) =>
|
||||||
_.each contactResults, (contact) =>
|
|
||||||
@_suggestions.push
|
@_suggestions.push
|
||||||
contact: contact
|
contact: contact
|
||||||
value: [{"participants": contact.email}]
|
value: [{"participants": contact.email}]
|
||||||
|
@ -63,6 +96,13 @@ SearchSuggestionStore = Reflux.createStore
|
||||||
|
|
||||||
query: -> @_query
|
query: -> @_query
|
||||||
|
|
||||||
|
queryKeyAndVal: ->
|
||||||
|
return {} unless @_query and @_query.length > 0
|
||||||
|
term = @_query[0]
|
||||||
|
key = Object.keys(term)[0]
|
||||||
|
val = term[key]
|
||||||
|
{key, val}
|
||||||
|
|
||||||
committedQuery: -> @_committedQuery
|
committedQuery: -> @_committedQuery
|
||||||
|
|
||||||
suggestions: ->
|
suggestions: ->
|
||||||
|
|
|
@ -47,6 +47,7 @@ class Thread extends Model
|
||||||
modelKey: 'snippet'
|
modelKey: 'snippet'
|
||||||
|
|
||||||
'subject': Attributes.String
|
'subject': Attributes.String
|
||||||
|
queryable: true
|
||||||
modelKey: 'subject'
|
modelKey: 'subject'
|
||||||
|
|
||||||
'unread': Attributes.Boolean
|
'unread': Attributes.Boolean
|
||||||
|
|
Loading…
Add table
Reference in a new issue