git ssb

0+

mixmix / ssb-meme



Commit 06b7d90bbe07c6d38c6ad24e196ba7d3d08108ec

allow search term to be a phrase

mix irving committed on 5/28/2018, 10:44:59 PM
Parent: 1f83e2637d5e118ea1d1ee4f5b59c81359d321c5

Files changed

index.jschanged
index.jsView
@@ -4,8 +4,9 @@
44
55 const isBlobMention = Validator(require('./schema/mention'))
66
77 const INDEX_VERSION = 2
8 +const SEARCH_TERM_MIN = 3
89
910 module.exports = {
1011 name: 'meme',
1112 version: require('./package.json').version,
@@ -13,9 +14,9 @@
1314 query: 'source',
1415 search: 'async'
1516 },
1617 init: (sbot) => {
17- const view = sbot._flumeUse('meme', FlumeView(INDEX_VERSION, 3, map))
18 + const view = sbot._flumeUse('meme', FlumeView(INDEX_VERSION, SEARCH_TERM_MIN, map))
1819
1920 return {
2021 query: view.query,
2122 search
@@ -23,8 +24,9 @@
2324
2425 function search (opts, cb) {
2526 if (typeof opts === 'string') opts = { query: opts }
2627 opts.query = opts.query.toLowerCase()
28 + const validTerms = opts.query.split(' ').filter(s => s.length >= SEARCH_TERM_MIN)
2729
2830 pull(
2931 view.query(opts),
3032 pull.collect((err, data) => {
@@ -32,9 +34,9 @@
3234
3335 const result = data.reduce((soFar, msg) => {
3436 getMentions(msg)
3537 .filter(isBlobMention)
36- .filter(m => m.name.toLowerCase().indexOf(opts.query) > -1) // only mentions relevant to the query
38 + .filter(containsSearchTerms)
3739 .forEach(({ link, name }) => {
3840 if (!soFar[link]) soFar[link] = []
3941
4042 soFar[link].push({ name, author: getAuthor(msg), msg: msg.key })
@@ -45,8 +47,13 @@
4547
4648 cb(null, result)
4749 })
4850 )
51 +
52 + function containsSearchTerms (mention) {
53 + const name = mention.name.toLowerCase()
54 + return validTerms.every(term => name.indexOf(term) > -1)
55 + }
4956 }
5057 }
5158 }
5259

Built with git-ssb-web