Commit deefa514 authored by Iker Hurtado's avatar Iker Hurtado
Browse files

Complex search logic implementation (7)

parent ae5096d2
......@@ -7920,6 +7920,36 @@
_getESQueryFromSearchQuery(searchQuery, queryTypes){
let formulas = [];
let parFormulas = [];
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;
else if ( searchQuery[i] === ')' ){
//prodQuery.push(searchQuery.slice(openIndex+1, i), queryTypes.slice(openIndex+1, i) );
openIndex = -1;
}
});
console.log(formulas, parFormulas);
function addItem(formulas, i, searchQuery, queryTypes){
if (i === 0 || searchQuery[i-1] === '('){
formulas.push(item);
}else{
if (searchQuery[i-1] === 'OR'){
formulas.push(item);
}else if (searchQuery[i-1] === 'AND'){
formulas.push(formulas.pop()+item);
}
}
}
}
_getESQueryFromSearchQuery_otherElements(searchQuery, queryTypes){
// Query structure analysis - looking for parentheses (only one level supported)
......@@ -7932,7 +7962,7 @@
for (let i = 0; i < searchQuery.length; i++) {
if ( searchQuery[i] === '(' ) openIndex = i;
else if ( searchQuery[i] === ')' ){
prodQuery.push(this._getESQueryFromSearchQuery(
prodQuery.push(this._getESQueryFromSearchQuery_otherElements(
searchQuery.slice(openIndex+1, i), queryTypes.slice(openIndex+1, i)));
prodTypes.push('Q');
openIndex = -1;
......@@ -7942,7 +7972,7 @@
}
}
console.log('prodQuery', prodQuery, prodTypes);
return this._getESQueryFromSearchQuery(prodQuery, prodTypes);
return this._getESQueryFromSearchQuery_otherElements(prodQuery, prodTypes);
}else{ // BASE CASE: there is no parentheses
......
......@@ -313,6 +313,36 @@ class NewSearchMod {
_getESQueryFromSearchQuery(searchQuery, queryTypes){
let formulas = [];
let parFormulas = [];
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;
else if ( searchQuery[i] === ')' ){
//prodQuery.push(searchQuery.slice(openIndex+1, i), queryTypes.slice(openIndex+1, i) );
openIndex = -1;
}
});
console.log(formulas, parFormulas);
function addItem(formulas, i, searchQuery, queryTypes){
if (i === 0 || searchQuery[i-1] === '('){
formulas.push(item);
}else{
if (searchQuery[i-1] === 'OR'){
formulas.push(item);
}else if (searchQuery[i-1] === 'AND'){
formulas.push(formulas.pop()+item);
}
}
}
}
_getESQueryFromSearchQuery_otherElements(searchQuery, queryTypes){
// Query structure analysis - looking for parentheses (only one level supported)
......@@ -325,7 +355,7 @@ class NewSearchMod {
for (let i = 0; i < searchQuery.length; i++) {
if ( searchQuery[i] === '(' ) openIndex = i;
else if ( searchQuery[i] === ')' ){
prodQuery.push(this._getESQueryFromSearchQuery(
prodQuery.push(this._getESQueryFromSearchQuery_otherElements(
searchQuery.slice(openIndex+1, i), queryTypes.slice(openIndex+1, i)));
prodTypes.push('Q');
openIndex = -1;
......@@ -335,7 +365,7 @@ class NewSearchMod {
}
}
console.log('prodQuery', prodQuery, prodTypes);
return this._getESQueryFromSearchQuery(prodQuery, prodTypes);
return this._getESQueryFromSearchQuery_otherElements(prodQuery, prodTypes);
}else{ // BASE CASE: there is no parentheses
......
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