modules/page/html/render/search.jsView |
---|
3 | 3 | var TextNodeSearcher = require('text-node-searcher') |
4 | 4 | var whitespace = /\s+/ |
5 | 5 | var pullAbortable = require('pull-abortable') |
6 | 6 | var Scroller = require('../../../../lib/scroller') |
7 | | -var nextStepper = require('../../../../lib/next-stepper') |
8 | 7 | var nest = require('depnest') |
9 | 8 | var Proxy = require('mutant/proxy') |
10 | 9 | |
11 | 10 | exports.needs = nest({ |
21 | 20 | const i18n = api.intl.sync.i18n |
22 | 21 | return nest('page.html.render', function channel (path) { |
23 | 22 | if (path[0] !== '?') return |
24 | 23 | |
25 | | - var queryStr = path.substr(1).trim() |
26 | | - var query = queryStr.split(whitespace) |
| 24 | + var query = path.substr(1).trim() |
27 | 25 | var done = Value(false) |
28 | 26 | var loading = Proxy(true) |
29 | 27 | var count = Value(0) |
30 | 28 | var updates = Value(0) |
31 | 29 | var aborter = null |
32 | 30 | |
33 | 31 | const searchHeader = h('div', {className: 'PageHeading'}, [ |
34 | | - h('h1', [h('strong', i18n('Search Results:')), ' ', query.join(' ')]) |
| 32 | + h('h1', [h('strong', i18n('Search Results:')), ' ', query]) |
35 | 33 | ]) |
36 | 34 | |
37 | 35 | var updateLoader = h('a Notifier -loader', { href: '#', 'ev-click': refresh }, [ |
38 | 36 | 'Show ', h('strong', [updates]), ' ', plural(updates, i18n('update'), i18n('updates')) |
58 | 56 | |
59 | 57 | var realtimeAborter = pullAbortable() |
60 | 58 | |
61 | 59 | pull( |
62 | | - api.sbot.pull.stream(sbot => sbot.patchwork.linearSearch({old: false, query})), |
| 60 | + api.sbot.pull.stream(sbot => sbot.patchwork.linearSearch({old: false, query: query.split(whitespace)})), |
63 | 61 | realtimeAborter, |
64 | 62 | pull.drain(msg => { |
65 | 63 | updates.set(updates() + 1) |
66 | 64 | }) |
102 | 100 | done.set(true) |
103 | 101 | }) |
104 | 102 | |
105 | 103 | pull( |
106 | | - api.sbot.pull.stream(sbot => nextStepper(getStream, { |
107 | | - reverse: true, |
108 | | - limit: 5, |
109 | | - query |
110 | | - })), |
| 104 | + api.sbot.pull.stream(sbot => sbot.search.query({query})), |
111 | 105 | pull.through(() => count.set(count() + 1)), |
112 | 106 | aborter, |
113 | 107 | pull.filter(msg => msg.value), |
114 | 108 | scroller |
118 | 112 | return !done && queue < 5 |
119 | 113 | })) |
120 | 114 | } |
121 | 115 | |
122 | | - function getStream (opts) { |
123 | | - if (opts.lt != null && !opts.lt.marker) { |
124 | | - |
125 | | - return pull.empty() |
126 | | - } else { |
127 | | - return api.sbot.pull.stream(sbot => sbot.patchwork.linearSearch(opts)) |
128 | | - } |
129 | | - } |
130 | | - |
131 | 116 | function renderMsg (msg) { |
132 | 117 | var el = h('FeedEvent', api.message.html.render(msg)) |
133 | | - highlight(el, createOrRegExp(query)) |
| 118 | + highlight(el, createOrRegExp(query.split(whitespace))) |
134 | 119 | return el |
135 | 120 | } |
136 | 121 | }) |
137 | 122 | } |