Problem: you can not search for lines without grouping
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
Solution: add search operator "query@" to find lines without grouping on titles.
This commit is contained in:
parent
cba1d002d9
commit
fa9f34e42f
|
@ -176,6 +176,17 @@ function formatLineResult(hits, key) {
|
|||
]
|
||||
}
|
||||
|
||||
function formatLineWithoutTitleResult(hit, key) {
|
||||
if (hit.line.match(/query[!@]?:/)) return []
|
||||
return [{
|
||||
text: hit.line,
|
||||
indented: 0,
|
||||
fold: 'open',
|
||||
hidden: false,
|
||||
fleeting: true
|
||||
}]
|
||||
}
|
||||
|
||||
function formatTitleResult(hit) {
|
||||
return [
|
||||
{
|
||||
|
@ -649,23 +660,31 @@ function Editor(holder, input) {
|
|||
|
||||
let query = $input.val()
|
||||
|
||||
match(query, /{{query(!?):\s*([^}]+)}}/)
|
||||
match(query, /{{query([!@]?):\s*([^}]+)}}/)
|
||||
.then(res => {
|
||||
if (res[1] === '!') {
|
||||
return search.startQuery(res[2])
|
||||
if (res[1] === '@') {
|
||||
return search.startQuery(res[2], {internal: false})
|
||||
.then(hits => _.flatMap(hits, formatLineWithoutTitleResult))
|
||||
.then(results => editor.replaceChildren(id, results))
|
||||
.catch(e => console.log('search query', e))
|
||||
.finally(() => editor.render())
|
||||
} else if (res[1] === '!') {
|
||||
return search.startQuery(res[2], {internal: false})
|
||||
.then(hits => _.uniqBy(_.flatMap(hits, formatTitleResult), _.property('text')))
|
||||
.then(results => editor.replaceChildren(id, results))
|
||||
.catch(e => console.log('search query', e))
|
||||
.finally(() => editor.render())
|
||||
} else {
|
||||
return search.startQuery(res[2])
|
||||
return search.startQuery(res[2], {internal: false})
|
||||
.then(hits => _.groupBy(hits, (it) => it.title))
|
||||
.then(hits => _.flatMap(hits, formatLineResult))
|
||||
.then(results => editor.replaceChildren(id, results))
|
||||
.catch(e => console.log('search query', e))
|
||||
.finally(() => editor.render())
|
||||
}
|
||||
}).catch(e => {})
|
||||
}).catch(e => {
|
||||
console.log(e)
|
||||
})
|
||||
});
|
||||
return editor
|
||||
})
|
||||
|
|
|
@ -17,26 +17,29 @@ function search(element) {
|
|||
}
|
||||
}
|
||||
|
||||
function startQuery(query) {
|
||||
function startQuery(query, opt) {
|
||||
opt ||= {internal:true}
|
||||
return fetch('/search/?' + qs.encode({q: query}))
|
||||
.then(res => res.json())
|
||||
.then(data => {
|
||||
let actualResult = [];
|
||||
actualResult.push({
|
||||
ref: query,
|
||||
title: 'Create new page "' + query + '"',
|
||||
line: 'New page',
|
||||
text: 'New page',
|
||||
})
|
||||
let parseResult = chrono.nl.casual.parse(query)
|
||||
if (parseResult.length) {
|
||||
let m = moment(parseResult[0].start.date())
|
||||
if (opt.internal) {
|
||||
actualResult.push({
|
||||
ref: m.format('LL').replace(/\s+/g, '_'),
|
||||
title: m.format('LL'),
|
||||
line: 'Suggested page',
|
||||
text: 'Suggested page'
|
||||
ref: query,
|
||||
title: 'Create new page "' + query + '"',
|
||||
line: 'New page',
|
||||
text: 'New page',
|
||||
})
|
||||
let parseResult = chrono.nl.casual.parse(query)
|
||||
if (parseResult.length) {
|
||||
let m = moment(parseResult[0].start.date())
|
||||
actualResult.push({
|
||||
ref: m.format('LL').replace(/\s+/g, '_'),
|
||||
title: m.format('LL'),
|
||||
line: 'Suggested page',
|
||||
text: 'Suggested page'
|
||||
})
|
||||
}
|
||||
}
|
||||
$.each(data.hits, (key, value) => {
|
||||
actualResult.push({
|
||||
|
|
Loading…
Reference in New Issue
Block a user