Commit 22d32922 authored by Jörg Richter's avatar Jörg Richter

Support single letter search if space is appended

See dmx-platform/dmx-platform#274
parent 545e35dc
Pipeline #7987 passed with stage
in 2 seconds
This diff is collapsed.
......@@ -6,7 +6,7 @@ import typeCache from './type-cache'
import permCache from './permission-cache'
import utils from './utils'
console.log('[DMX] Client API 2019/08/23')
console.log('[DMX] Client API 2019/08/24')
export default {
......
......@@ -117,6 +117,10 @@ function containsLuceneSymbol (input) {
/**
* Transforms user input into a Lucene query that can be used for an incremental search.
*
* @param allowSingleLetterSearch optional; if trueish a search for a single letter as *word begin* is allowed.
* Note: a search for a single letter as *whole word* (that is when followed by
* space) is always allowed.
*
* @return a Lucene query.
* If input is a single character returns empty string to signalize the caller no search should be triggered.
*/
......@@ -124,10 +128,12 @@ function fulltextQuery (input, allowSingleLetterSearch) {
let query = input.trim()
if (!containsLuceneSymbol(input)) {
query = query.split(/ +/).join(' AND ')
if (query.length === 1 && !allowSingleLetterSearch) {
query = ''
} else if (query && !input.endsWith(' ')) {
query += '*'
if (!input.endsWith(' ')) {
if (query.length === 1 && !allowSingleLetterSearch) {
query = ''
} else if (query) {
query += '*'
}
}
}
return query
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment