git ssb

16+

Dominic / patchbay



Commit 3ff4af2891a16a2ac8dec9e3186a34bc1b842aa6

Merge branch 'master' into sort-network

mix irving committed on 2/7/2017, 11:40:27 AM
Parent: 83f0a729646d2a27162cb77fe27d448dc3f62568
Parent: a26dc85417ea413b52beecacaa45a025bc07cf51

Files changed

README.mdchanged
manifest.jsonchanged
modules_core/sbot.jschanged
modules_extra/search.jschanged
package.jsonchanged
README.mdView
@@ -22,12 +22,13 @@
2222 sbot server
2323 # if you are already running patchwork, that also works.
2424 # (must have at least >= 2.8)
2525
26-# then in another tab (these must be 3 separate commands)
26 +# then in another tab (these must be separate commands)
2727 sbot plugins.install ssb-links
2828 sbot plugins.install ssb-query
2929 sbot plugins.install ssb-ws
30 +sbot plugins.install ssb-fulltext # for faster searches (optional)
3031 # restart sbot server (go back to previous tab and kill it)
3132 ```
3233 now clone and run patchbay.
3334 ```
manifest.jsonView
@@ -103,8 +103,11 @@
103103 "push": "async",
104104 "changes": "source",
105105 "createWants": "source"
106106 },
107 + "fulltext": {
108 + "search": "source"
109 + },
107110 "links2": {
108111 "read": "source",
109112 "dump": "source"
110113 },
modules_core/sbot.jsView
@@ -42,8 +42,9 @@
4242 sbot_blobs_add: true,
4343 sbot_links: true,
4444 sbot_links2: true,
4545 sbot_query: true,
46 + sbot_fulltext_search: true,
4647 sbot_get: true,
4748 sbot_log: true,
4849 sbot_user_feed: true,
4950 sbot_gossip_peers: true,
@@ -140,8 +141,11 @@
140141 }),
141142 sbot_user_feed: rec.source(function (opts) {
142143 return sbot.createUserStream(opts)
143144 }),
145 + sbot_fulltext_search: rec.source(function (opts) {
146 + return sbot.fulltext.search(opts)
147 + }),
144148 sbot_get: rec.async(function (key, cb) {
145149 if('function' !== typeof cb)
146150 throw new Error('cb must be function')
147151 if(CACHE[key]) cb(null, CACHE[key])
modules_extra/search.jsView
@@ -1,16 +1,17 @@
11 const h = require('../h')
22 const fs = require('fs')
3-const { Value } = require('@mmckegg/mutant')
3 +const { Struct, Value, when, computed } = require('@mmckegg/mutant')
44 const u = require('../util')
55 const pull = require('pull-stream')
66 const Scroller = require('pull-scroll')
77 const TextNodeSearcher = require('text-node-searcher')
88
99 exports.needs = {
1010 build_scroller: 'first',
1111 message_render: 'first',
12- sbot_log: 'first'
12 + sbot_log: 'first',
13 + sbot_fulltext_search: 'first'
1314 }
1415
1516 exports.gives = {
1617 screen_view: true,
@@ -55,8 +56,25 @@
5556 searcher.highlight()
5657 return el
5758 }
5859
60 +function fallback(reader) {
61 + var fallbackRead
62 + return function (read) {
63 + return function (abort, cb) {
64 + read(abort, function next(end, data) {
65 + if (end && reader && (fallbackRead = reader(end))) {
66 + reader = null
67 + read = fallbackRead
68 + read(abort, next)
69 + } else {
70 + cb(end, data)
71 + }
72 + })
73 + }
74 + }
75 +}
76 +
5977 exports.create = function (api) {
6078
6179 return {
6280 screen_view,
@@ -65,31 +83,42 @@
6583
6684 function screen_view (path) {
6785 if (path[0] !== '?') return
6886
69- var query = path.substr(1).trim().split(whitespace)
70- var _matches = searchFilter(query)
87 + var queryStr = path.substr(1).trim()
88 + var query = queryStr.split(whitespace)
89 + var matchesQuery = searchFilter(query)
7190
72- const searched = Value(0)
73- const matches = Value(0)
91 + const search = Struct({
92 + isLinear: Value(false),
93 + linear: Struct({
94 + checked: Value(0)
95 + }),
96 + fulltext: Struct({
97 + isDone: Value(false)
98 + }),
99 + matches: Value(0)
100 + })
101 + const hasNoFulltextMatches = computed([search.fulltext.isDone, search.matches],
102 + (done, matches) => done && matches === 0)
103 +
104 +
74105 const searchHeader = h('Search', [
75- h('header', h('h1', query)),
76- h('section.details', [
77- h('div.searched', ['Searched: ', searched]),
78- h('div.matches', [matches, ' matches'])
79- ])
106 + h('header', h('h1', query.join(' '))),
107 + when(search.isLinear,
108 + h('section.details', [
109 + h('div.searched', ['Searched: ', search.linear.checked]),
110 + h('div.matches', [search.matches, ' matches'])
111 + ]),
112 + h('section.details', [
113 + h('div.searched'),
114 + when(hasNoFulltextMatches, h('div.matches', 'No matches'))
115 + ])
116 + )
80117 ])
81118 var { container, content } = api.build_scroller({ prepend: searchHeader })
82119 container.id = path // helps tabs find this tab
83120
84- function matchesQuery (data) {
85- searched.set(searched() + 1)
86- var m = _matches(data)
87- if(m) matches.set(matches() +1 )
88-
89- return m
90- }
91-
92121 function renderMsg(msg) {
93122 var el = api.message_render(msg)
94123 highlight(el, createOrRegExp(query))
95124 return el
@@ -101,10 +130,22 @@
101130 Scroller(container, content, renderMsg, true, false)
102131 )
103132
104133 pull(
105- u.next(api.sbot_log, {reverse: true, limit: 500, live: false}),
106- pull.filter(matchesQuery),
134 + u.next(api.sbot_fulltext_search, {query: queryStr, reverse: true, limit: 500, live: false}),
135 + fallback((err) => {
136 + if (err === true) {
137 + search.fulltext.isDone.set(true)
138 + } else if (/^no source/.test(err.message)) {
139 + search.isLinear.set(true)
140 + return pull(
141 + u.next(api.sbot_log, {reverse: true, limit: 500, live: false}),
142 + pull.through(() => searched.set(searched()+1)),
143 + pull.filter(matchesQuery)
144 + )
145 + }
146 + }),
147 + pull.through(() => search.matches.set(search.matches()+1)),
107148 Scroller(container, content, renderMsg, false, false)
108149 )
109150
110151 return container
package.jsonView
@@ -1,8 +1,8 @@
11 {
22 "name": "patchbay",
33 "description": "a pluggable patchwork",
4- "version": "6.8.0",
4 + "version": "6.9.0",
55 "homepage": "https://github.com/ssbc/patchbay",
66 "repository": {
77 "type": "git",
88 "url": "git://github.com/ssbc/patchbay.git"

Built with git-ssb-web