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) {
|
function formatTitleResult(hit) {
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
|
@ -649,23 +660,31 @@ function Editor(holder, input) {
|
||||||
|
|
||||||
let query = $input.val()
|
let query = $input.val()
|
||||||
|
|
||||||
match(query, /{{query(!?):\s*([^}]+)}}/)
|
match(query, /{{query([!@]?):\s*([^}]+)}}/)
|
||||||
.then(res => {
|
.then(res => {
|
||||||
if (res[1] === '!') {
|
if (res[1] === '@') {
|
||||||
return search.startQuery(res[2])
|
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(hits => _.uniqBy(_.flatMap(hits, formatTitleResult), _.property('text')))
|
||||||
.then(results => editor.replaceChildren(id, results))
|
.then(results => editor.replaceChildren(id, results))
|
||||||
.catch(e => console.log('search query', e))
|
.catch(e => console.log('search query', e))
|
||||||
.finally(() => editor.render())
|
.finally(() => editor.render())
|
||||||
} else {
|
} else {
|
||||||
return search.startQuery(res[2])
|
return search.startQuery(res[2], {internal: false})
|
||||||
.then(hits => _.groupBy(hits, (it) => it.title))
|
.then(hits => _.groupBy(hits, (it) => it.title))
|
||||||
.then(hits => _.flatMap(hits, formatLineResult))
|
.then(hits => _.flatMap(hits, formatLineResult))
|
||||||
.then(results => editor.replaceChildren(id, results))
|
.then(results => editor.replaceChildren(id, results))
|
||||||
.catch(e => console.log('search query', e))
|
.catch(e => console.log('search query', e))
|
||||||
.finally(() => editor.render())
|
.finally(() => editor.render())
|
||||||
}
|
}
|
||||||
}).catch(e => {})
|
}).catch(e => {
|
||||||
|
console.log(e)
|
||||||
|
})
|
||||||
});
|
});
|
||||||
return editor
|
return editor
|
||||||
})
|
})
|
||||||
|
|
|
@ -17,11 +17,13 @@ function search(element) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function startQuery(query) {
|
function startQuery(query, opt) {
|
||||||
|
opt ||= {internal:true}
|
||||||
return fetch('/search/?' + qs.encode({q: query}))
|
return fetch('/search/?' + qs.encode({q: query}))
|
||||||
.then(res => res.json())
|
.then(res => res.json())
|
||||||
.then(data => {
|
.then(data => {
|
||||||
let actualResult = [];
|
let actualResult = [];
|
||||||
|
if (opt.internal) {
|
||||||
actualResult.push({
|
actualResult.push({
|
||||||
ref: query,
|
ref: query,
|
||||||
title: 'Create new page "' + query + '"',
|
title: 'Create new page "' + query + '"',
|
||||||
|
@ -38,6 +40,7 @@ function startQuery(query) {
|
||||||
text: 'Suggested page'
|
text: 'Suggested page'
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
}
|
||||||
$.each(data.hits, (key, value) => {
|
$.each(data.hits, (key, value) => {
|
||||||
actualResult.push({
|
actualResult.push({
|
||||||
ref: value.fields.page,
|
ref: value.fields.page,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user