Table of contents
No headers
/***
USAGE: buildAdvancedLuceneQuery(all, exact, any, notwords)
Builds advanced lucene query from various variables
all : str/list
The search query must contain all of the following terms.
exact : str
The search query must match the string exactly.
any : str/list
The search query must contain any of the these terms.
notwords : str/list
The search query must NOT contain any of these words.
***/
var all = $all ?? $0;
var exact = $exact ?? $1;
var any = $any ?? $2;
var notwords = $notwords ?? $3;
var termModifier = nil;
var andTerms = [ ];
var orTerms = [ ];
var notTerms = [ ];
if(typeof(all) != 'list') {
all = string.contains(',') ? string.split(all, ',') : string.split(all, ' ');
}
if(typeof(any) != 'list') {
any = string.contains(',') ? string.split(any, ',') : string.split(any, ' ');
}
if(typeof(notwords) != 'list') {
notwords = string.contains(',') ? string.split(notwords, ',') : string.split(notwords, ' ');
}
if(#all > 0) {
andTerms ..= all;
}
if(#exact > 0) {
andTerms ..= [exact];
}
if(#any > 0) {
orTerms ..= any;
}
if(#notwords > 0) {
notTerms ..= notwords;
}
// Build query
var subQueryBuilder = import['MindTouch/Functions/BuildAdvancedLuceneQuery/BuildSubQuery'];
var query = '';
query ..= subQueryBuilder(andTerms, 'AND', true, termModifier);
query ..= subQueryBuilder(orTerms, 'OR', true, termModifier);
query ..= subQueryBuilder(notTerms, 'AND', false, termModifier);
export = query;
Comments