Commit 6ed614d2 authored by Iker Hurtado's avatar Iker Hurtado
Browse files

Complex search logic implementation (8)

parent deefa514
......@@ -7922,19 +7922,41 @@
_getESQueryFromSearchQuery(searchQuery, queryTypes){
let formulas = [];
let parFormulas = [];
let parOperator = null;
let openIndex = -1;
searchQuery.forEach( (item, i) => {
if (queryTypes[i] === 'F'){
addItem( (openIndex > 0 ? parFormulas : formulas), i, searchQuery, queryTypes);
}else if ( searchQuery[i] === '(' ) openIndex = i;
if (queryTypes[i] === 'F' || queryTypes[i] === 'E'){
addItem( (openIndex >= 0 ? parFormulas : formulas), i, item, searchQuery, queryTypes);
console.log(formulas, parFormulas);
}else if ( searchQuery[i] === '(' ){
if (i-1 >= 0 ) parOperator = searchQuery[i-1];
openIndex = i;
}
else if ( searchQuery[i] === ')' ){
//prodQuery.push(searchQuery.slice(openIndex+1, i), queryTypes.slice(openIndex+1, i) );
if (parOperator === null){ // The starting ( was the first symbol of the expression
formulas = parFormulas;
}else if (parOperator === 'OR'){ // OR (...
formulas = formulas.concat(parFormulas);
}else{ // AND (...
let rFormulas = [];
formulas.forEach( formula => {
parFormulas.forEach( parFormula => rFormulas.push(formula+parFormula) );
});
formulas = rFormulas;
}
parFormulas = []; // reset the array formulas inside the parentheses
openIndex = -1;
}
});
console.log(formulas, parFormulas);
function addItem(formulas, i, searchQuery, queryTypes){
function addItem(formulas, i, item, searchQuery, queryTypes){
if (i === 0 || searchQuery[i-1] === '('){
formulas.push(item);
}else{
......
......@@ -315,19 +315,41 @@ class NewSearchMod {
_getESQueryFromSearchQuery(searchQuery, queryTypes){
let formulas = [];
let parFormulas = [];
let parOperator = null;
let openIndex = -1;
searchQuery.forEach( (item, i) => {
if (queryTypes[i] === 'F'){
addItem( (openIndex > 0 ? parFormulas : formulas), i, searchQuery, queryTypes);
}else if ( searchQuery[i] === '(' ) openIndex = i;
if (queryTypes[i] === 'F' || queryTypes[i] === 'E'){
addItem( (openIndex >= 0 ? parFormulas : formulas), i, item, searchQuery, queryTypes);
console.log(formulas, parFormulas);
}else if ( searchQuery[i] === '(' ){
if (i-1 >= 0 ) parOperator = searchQuery[i-1];
openIndex = i;
}
else if ( searchQuery[i] === ')' ){
//prodQuery.push(searchQuery.slice(openIndex+1, i), queryTypes.slice(openIndex+1, i) );
if (parOperator === null){ // The starting ( was the first symbol of the expression
formulas = parFormulas;
}else if (parOperator === 'OR'){ // OR (...
formulas = formulas.concat(parFormulas);
}else{ // AND (...
let rFormulas = [];
formulas.forEach( formula => {
parFormulas.forEach( parFormula => rFormulas.push(formula+parFormula) );
});
formulas = rFormulas;
}
parFormulas = []; // reset the array formulas inside the parentheses
openIndex = -1;
}
});
console.log(formulas, parFormulas);
function addItem(formulas, i, searchQuery, queryTypes){
function addItem(formulas, i, item, searchQuery, queryTypes){
if (i === 0 || searchQuery[i-1] === '('){
formulas.push(item);
}else{
......
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