Commit 914ec763 authored by Iker Hurtado's avatar Iker Hurtado
Browse files

Complex search logic implementation (5)

parent 6cf300ea
......@@ -7917,21 +7917,27 @@
_getESQueryFromSearchQuery(searchQuery, queryTypes){
// Query structure analysis - looking for parentheses (only one level supported)
let openIndex = -1;
let nestedQueries = []; // Queries into parentheses
let esQueries = [];
searchQuery.forEach( (item, i) => {
if ( searchQuery[i] === '(' ) openIndex = i;
else if ( openIndex >= 0 && searchQuery[i] === ')' ){
//nestedQueries.push(searchQuery.slice(openIndex+1, i));
esQueries.push(this._getESQueryFromSearchQuery(
searchQuery.slice(openIndex+1, i), queryTypes.slice(openIndex+1, i)));
}
});
if ( esQueries.length > 0){ // Recursion
console.log('esQueries', JSON.stringify(esQueries));
if ( searchQuery.indexOf('(') >= 0){ // Recursion
let openIndex = -1;
let prodQuery = [];
let prodTypes = [];
//let prodQueryIndex = 0;
for (let i = 0; i < searchQuery.length; i++) {
if ( searchQuery[i] === '(' ) openIndex = i;
else if ( searchQuery[i] === ')' ){
prodQuery.push(this._getESQueryFromSearchQuery(
searchQuery.slice(openIndex+1, i), queryTypes.slice(openIndex+1, i)));
prodTypes.push('Q');
openIndex = -1;
}else if (openIndex < 0){ // outside a parentheses
prodQuery.push(searchQuery[i]);
prodTypes.push(queryTypes[i]);
}
}
console.log('prodQuery', prodQuery, prodTypes);
return this._getESQueryFromSearchQuery(prodQuery, prodTypes);
}else{ // BASE CASE: there is no parentheses
......@@ -7970,16 +7976,15 @@
//else // Regular search, Not allowing other elements -> the elements inserted must be sorted for this to work
// queryObj.bool.must.push(this._getESSimpleMatch('atom_labels_keyword', this._sortElements(elements) )); ///elements.join('')));
}else if (queryTypes[i] === 'Q'){
queryObj.push(item);
}
});
return rootQueryObj;
} // else
}
}
} // _getESQueryFromSearchQuery()
_sortElements(elements){
......
......@@ -310,21 +310,27 @@ class NewSearchMod {
_getESQueryFromSearchQuery(searchQuery, queryTypes){
// Query structure analysis - looking for parentheses (only one level supported)
let openIndex = -1;
let nestedQueries = []; // Queries into parentheses
let esQueries = [];
searchQuery.forEach( (item, i) => {
if ( searchQuery[i] === '(' ) openIndex = i;
else if ( openIndex >= 0 && searchQuery[i] === ')' ){
//nestedQueries.push(searchQuery.slice(openIndex+1, i));
esQueries.push(this._getESQueryFromSearchQuery(
searchQuery.slice(openIndex+1, i), queryTypes.slice(openIndex+1, i)));
}
});
if ( esQueries.length > 0){ // Recursion
console.log('esQueries', JSON.stringify(esQueries));
if ( searchQuery.indexOf('(') >= 0){ // Recursion
let openIndex = -1;
let prodQuery = [];
let prodTypes = [];
//let prodQueryIndex = 0;
for (let i = 0; i < searchQuery.length; i++) {
if ( searchQuery[i] === '(' ) openIndex = i;
else if ( searchQuery[i] === ')' ){
prodQuery.push(this._getESQueryFromSearchQuery(
searchQuery.slice(openIndex+1, i), queryTypes.slice(openIndex+1, i)));
prodTypes.push('Q');
openIndex = -1;
}else if (openIndex < 0){ // outside a parentheses
prodQuery.push(searchQuery[i]);
prodTypes.push(queryTypes[i]);
}
}
console.log('prodQuery', prodQuery, prodTypes);
return this._getESQueryFromSearchQuery(prodQuery, prodTypes);
}else{ // BASE CASE: there is no parentheses
......@@ -363,16 +369,15 @@ class NewSearchMod {
//else // Regular search, Not allowing other elements -> the elements inserted must be sorted for this to work
// queryObj.bool.must.push(this._getESSimpleMatch('atom_labels_keyword', this._sortElements(elements) )); ///elements.join('')));
}else if (queryTypes[i] === 'Q'){
queryObj.push(item);
}
});
return rootQueryObj;
} // else
}
}
} // _getESQueryFromSearchQuery()
_sortElements(elements){
......
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