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

Complex search logic implementation (9)

parent 6ed614d2
...@@ -7702,6 +7702,9 @@ ...@@ -7702,6 +7702,9 @@
<input type="checkbox" id="multiples-of-formula" value=""> <input type="checkbox" id="multiples-of-formula" value="">
Include multiples of formula Include multiples of formula
<br> <br>
<input type="checkbox" id="allow-other-elements" value="">
Allow other elements
<br>
...@@ -7825,14 +7828,21 @@ ...@@ -7825,14 +7828,21 @@
if (this.searchQuery.lenght === 0){ if (this.searchQuery.lenght === 0){
util.showUserMsg('No query'); util.showUserMsg('No query');
}else{ }else{
let rootQueryObj;
//************** Material name or complex search expression //************** Material name or complex search expression
//if (this.queryTypes[i] === 'MN'){ //if (this.queryTypes[i] === 'MN'){
//queryObj.push(this._getESSimpleMatch('material_name', item)); //queryObj.push(this._getESSimpleMatch('material_name', item));
let rootQueryObj =
if (this.element.querySelector('#allow-other-elements').checked)
rootQueryObj = this._getESQueryFromSearchQuery_otherElements(
this.searchQuery, this.queryTypes);
// Regular case: search containing only the elements in the search expression
else rootQueryObj =
this._getESQueryFromSearchQuery(this.searchQuery, this.queryTypes); this._getESQueryFromSearchQuery(this.searchQuery, this.queryTypes);
/* Pending to ADD *************/ /* Pending to ADD *************/
//let filterMap = this.filterPanel.getValues(); //let filterMap = this.filterPanel.getValues();
//this._addFiltersInSearchQuery(filterMap, queryObj); //this._addFiltersInSearchQuery(filterMap, queryObj);
...@@ -7926,8 +7936,8 @@ ...@@ -7926,8 +7936,8 @@
let openIndex = -1; let openIndex = -1;
searchQuery.forEach( (item, i) => { searchQuery.forEach( (item, i) => {
if (queryTypes[i] === 'F' || queryTypes[i] === 'E'){ if (queryTypes[i] === 'F' || queryTypes[i] === 'E'){
addItem( (openIndex >= 0 ? parFormulas : formulas), i, item, searchQuery, queryTypes); addItem( (openIndex >= 0 ? parFormulas : formulas), i,
console.log(formulas, parFormulas); item+(queryTypes[i] === 'E' ? 'X' : ''));
}else if ( searchQuery[i] === '(' ){ }else if ( searchQuery[i] === '(' ){
if (i-1 >= 0 ) parOperator = searchQuery[i-1]; if (i-1 >= 0 ) parOperator = searchQuery[i-1];
...@@ -7950,31 +7960,28 @@ ...@@ -7950,31 +7960,28 @@
openIndex = -1; openIndex = -1;
} }
}); });
console.log(formulas, parFormulas); console.log('_getESQueryFromSearchQuery: ',formulas, parFormulas);
//*********** Get the elastic search expression from the search expression
// the elements inserted must be sorted for this to work
// queryObj.bool.must.push(this._getESSimpleMatch('atom_labels_keyword', this._sortElements(elements) )); ///elements.join('')));
// if ( this.element.querySelector('#multiples-of-formula').checked ){ // reduced search
function addItem(formulas, i, item, searchQuery, queryTypes){ function addItem(formulas, i, item){
if (i === 0 || searchQuery[i-1] === '('){ if (i === 0 || searchQuery[i-1] === '('){
formulas.push(item); formulas.push(item);
}else{ }else{
if (searchQuery[i-1] === 'OR'){ if (searchQuery[i-1] === 'OR') formulas.push(item);
formulas.push(item); else if (searchQuery[i-1] === 'AND')
}else if (searchQuery[i-1] === 'AND'){
formulas.push(formulas.pop()+item); formulas.push(formulas.pop()+item);
} }
} }
}
} } // _getESQueryFromSearchQuery()
_getESQueryFromSearchQuery_otherElements(searchQuery, queryTypes){ _getESQueryFromSearchQuery_otherElements(searchQuery, queryTypes){
// Query structure analysis - looking for parentheses (only one level supported) // Query structure analysis - looking for parentheses (only one level supported)
if ( searchQuery.indexOf('(') >= 0){ // Recursion if ( searchQuery.indexOf('(') >= 0){ // Recursion
let openIndex = -1; let openIndex = -1;
...@@ -7993,10 +8000,9 @@ ...@@ -7993,10 +8000,9 @@
prodTypes.push(queryTypes[i]); prodTypes.push(queryTypes[i]);
} }
} }
console.log('prodQuery', prodQuery, prodTypes); //console.log('prodQuery', prodQuery, prodTypes);
return this._getESQueryFromSearchQuery_otherElements(prodQuery, prodTypes); return this._getESQueryFromSearchQuery_otherElements(prodQuery, prodTypes);
}else{ // BASE CASE: there is no parentheses }else{ // BASE CASE: there is no parentheses
let boolOperator; let boolOperator;
...@@ -8017,8 +8023,7 @@ ...@@ -8017,8 +8023,7 @@
searchQuery.forEach( (item, i) => { searchQuery.forEach( (item, i) => {
if (queryTypes[i] === 'F'){ if (queryTypes[i] === 'F'){ // Formula case
// ** PENDING: search Not allowing other elements
let esMatchQuery; let esMatchQuery;
if ( this.element.querySelector('#multiples-of-formula').checked ){ // reduced search if ( this.element.querySelector('#multiples-of-formula').checked ){ // reduced search
esMatchQuery = this._getESOperatorMatch('formula_reduced', this._reduceFormula(item)); esMatchQuery = this._getESOperatorMatch('formula_reduced', this._reduceFormula(item));
...@@ -8026,12 +8031,9 @@ ...@@ -8026,12 +8031,9 @@
esMatchQuery = this._getESOperatorMatch('formula', this._tokenizeFormula(item)); esMatchQuery = this._getESOperatorMatch('formula', this._tokenizeFormula(item));
queryObj.push(esMatchQuery); queryObj.push(esMatchQuery);
}else if (queryTypes[i] === 'E'){ }else if (queryTypes[i] === 'E'){ // Element case
// if (this.elementTable.getAllowOtherElements())
queryObj.push(this._getESSimpleMatch('atom_labels', item)); queryObj.push(this._getESSimpleMatch('atom_labels', item));
//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'){ }else if (queryTypes[i] === 'Q'){
queryObj.push(item); queryObj.push(item);
} }
...@@ -8039,8 +8041,7 @@ ...@@ -8039,8 +8041,7 @@
return rootQueryObj; return rootQueryObj;
} // else } // else
} // _getESQueryFromSearchQuery_otherElements()
} // _getESQueryFromSearchQuery()
_sortElements(elements){ _sortElements(elements){
...@@ -8430,12 +8431,12 @@ ...@@ -8430,12 +8431,12 @@
this.element.innerHTML= this.element.innerHTML=
` `
<div style="padding-bottom: 20px;"> <div style="padding-bottom: 20px;">
<!--
<input type="checkbox" class="allow-other-elements" value=""> <input type="checkbox" class="allow-other-elements" value="">
Allow other elements Allow other elements
<br> <br>
<!--
<input type="checkbox" class="multiples-of-formula" value=""> <input type="checkbox" class="multiples-of-formula" value="">
Include multiples of formula Include multiples of formula
<br> --> <br> -->
...@@ -8471,12 +8472,12 @@ ...@@ -8471,12 +8472,12 @@
this.formulaButton.disabled = true;//bool; this.formulaButton.disabled = true;//bool;
} }
/*
getAllowOtherElements(){ getAllowOtherElements(){
return this.element.querySelector('.allow-other-elements').checked; return this.element.querySelector('.allow-other-elements').checked;
} }
/*
getMultiplesOfFormula(){ getMultiplesOfFormula(){
return this.element.querySelector('.multiples-of-formula').checked; return this.element.querySelector('.multiples-of-formula').checked;
}*/ }*/
...@@ -8888,11 +8889,8 @@ ...@@ -8888,11 +8889,8 @@
this.element = document.createElement('div'); this.element = document.createElement('div');
this.element.setAttribute('id','elementable'); this.element.setAttribute('id','elementable');
let tempHtml= `<input type="checkbox" class="allow-other-elements" value="">
Allow other elements`;
// header with dropdown // header with dropdown
tempHtml+= '<div class="element-info"></div>'; let tempHtml = '<div class="element-info"></div>';
tempHtml+= '<div class="ptWrapper">'; tempHtml+= '<div class="ptWrapper">';
...@@ -9090,11 +9088,6 @@ ...@@ -9090,11 +9088,6 @@
} }
} }
getAllowOtherElements(){
return this.element.querySelector('.allow-other-elements').checked;
}
} // class ElemenTable } // class ElemenTable
......
...@@ -158,11 +158,8 @@ class ElemenTable{ ...@@ -158,11 +158,8 @@ class ElemenTable{
this.element = document.createElement('div'); this.element = document.createElement('div');
this.element.setAttribute('id','elementable'); this.element.setAttribute('id','elementable');
let tempHtml= `<input type="checkbox" class="allow-other-elements" value="">
Allow other elements`;
// header with dropdown // header with dropdown
tempHtml+= '<div class="element-info"></div>'; let tempHtml = '<div class="element-info"></div>';
tempHtml+= '<div class="ptWrapper">'; tempHtml+= '<div class="ptWrapper">';
...@@ -360,11 +357,6 @@ class ElemenTable{ ...@@ -360,11 +357,6 @@ class ElemenTable{
} }
} }
getAllowOtherElements(){
return this.element.querySelector('.allow-other-elements').checked;
}
} // class ElemenTable } // class ElemenTable
......
...@@ -95,6 +95,9 @@ class NewSearchMod { ...@@ -95,6 +95,9 @@ class NewSearchMod {
<input type="checkbox" id="multiples-of-formula" value=""> <input type="checkbox" id="multiples-of-formula" value="">
Include multiples of formula Include multiples of formula
<br> <br>
<input type="checkbox" id="allow-other-elements" value="">
Allow other elements
<br>
...@@ -218,14 +221,21 @@ class NewSearchMod { ...@@ -218,14 +221,21 @@ class NewSearchMod {
if (this.searchQuery.lenght === 0){ if (this.searchQuery.lenght === 0){
util.showUserMsg('No query'); util.showUserMsg('No query');
}else{ }else{
let rootQueryObj;
//************** Material name or complex search expression //************** Material name or complex search expression
//if (this.queryTypes[i] === 'MN'){ //if (this.queryTypes[i] === 'MN'){
//queryObj.push(this._getESSimpleMatch('material_name', item)); //queryObj.push(this._getESSimpleMatch('material_name', item));
let rootQueryObj =
if (this.element.querySelector('#allow-other-elements').checked)
rootQueryObj = this._getESQueryFromSearchQuery_otherElements(
this.searchQuery, this.queryTypes);
// Regular case: search containing only the elements in the search expression
else rootQueryObj =
this._getESQueryFromSearchQuery(this.searchQuery, this.queryTypes); this._getESQueryFromSearchQuery(this.searchQuery, this.queryTypes);
/* Pending to ADD *************/ /* Pending to ADD *************/
//let filterMap = this.filterPanel.getValues(); //let filterMap = this.filterPanel.getValues();
//this._addFiltersInSearchQuery(filterMap, queryObj); //this._addFiltersInSearchQuery(filterMap, queryObj);
...@@ -319,8 +329,8 @@ class NewSearchMod { ...@@ -319,8 +329,8 @@ class NewSearchMod {
let openIndex = -1; let openIndex = -1;
searchQuery.forEach( (item, i) => { searchQuery.forEach( (item, i) => {
if (queryTypes[i] === 'F' || queryTypes[i] === 'E'){ if (queryTypes[i] === 'F' || queryTypes[i] === 'E'){
addItem( (openIndex >= 0 ? parFormulas : formulas), i, item, searchQuery, queryTypes); addItem( (openIndex >= 0 ? parFormulas : formulas), i,
console.log(formulas, parFormulas); item+(queryTypes[i] === 'E' ? 'X' : ''));
}else if ( searchQuery[i] === '(' ){ }else if ( searchQuery[i] === '(' ){
if (i-1 >= 0 ) parOperator = searchQuery[i-1]; if (i-1 >= 0 ) parOperator = searchQuery[i-1];
...@@ -343,31 +353,28 @@ class NewSearchMod { ...@@ -343,31 +353,28 @@ class NewSearchMod {
openIndex = -1; openIndex = -1;
} }
}); });
console.log(formulas, parFormulas); console.log('_getESQueryFromSearchQuery: ',formulas, parFormulas);
//*********** Get the elastic search expression from the search expression
// the elements inserted must be sorted for this to work
// queryObj.bool.must.push(this._getESSimpleMatch('atom_labels_keyword', this._sortElements(elements) )); ///elements.join('')));
// if ( this.element.querySelector('#multiples-of-formula').checked ){ // reduced search
function addItem(formulas, i, item, searchQuery, queryTypes){ function addItem(formulas, i, item){
if (i === 0 || searchQuery[i-1] === '('){ if (i === 0 || searchQuery[i-1] === '('){
formulas.push(item); formulas.push(item);
}else{ }else{
if (searchQuery[i-1] === 'OR'){ if (searchQuery[i-1] === 'OR') formulas.push(item);
formulas.push(item); else if (searchQuery[i-1] === 'AND')
}else if (searchQuery[i-1] === 'AND'){
formulas.push(formulas.pop()+item); formulas.push(formulas.pop()+item);
} }
} }
}
} } // _getESQueryFromSearchQuery()
_getESQueryFromSearchQuery_otherElements(searchQuery, queryTypes){ _getESQueryFromSearchQuery_otherElements(searchQuery, queryTypes){
// Query structure analysis - looking for parentheses (only one level supported) // Query structure analysis - looking for parentheses (only one level supported)
if ( searchQuery.indexOf('(') >= 0){ // Recursion if ( searchQuery.indexOf('(') >= 0){ // Recursion
let openIndex = -1; let openIndex = -1;
...@@ -386,10 +393,9 @@ class NewSearchMod { ...@@ -386,10 +393,9 @@ class NewSearchMod {
prodTypes.push(queryTypes[i]); prodTypes.push(queryTypes[i]);
} }
} }
console.log('prodQuery', prodQuery, prodTypes); //console.log('prodQuery', prodQuery, prodTypes);
return this._getESQueryFromSearchQuery_otherElements(prodQuery, prodTypes); return this._getESQueryFromSearchQuery_otherElements(prodQuery, prodTypes);
}else{ // BASE CASE: there is no parentheses }else{ // BASE CASE: there is no parentheses
let boolOperator; let boolOperator;
...@@ -410,8 +416,7 @@ class NewSearchMod { ...@@ -410,8 +416,7 @@ class NewSearchMod {
searchQuery.forEach( (item, i) => { searchQuery.forEach( (item, i) => {
if (queryTypes[i] === 'F'){ if (queryTypes[i] === 'F'){ // Formula case
// ** PENDING: search Not allowing other elements
let esMatchQuery; let esMatchQuery;
if ( this.element.querySelector('#multiples-of-formula').checked ){ // reduced search if ( this.element.querySelector('#multiples-of-formula').checked ){ // reduced search
esMatchQuery = this._getESOperatorMatch('formula_reduced', this._reduceFormula(item)); esMatchQuery = this._getESOperatorMatch('formula_reduced', this._reduceFormula(item));
...@@ -419,12 +424,9 @@ class NewSearchMod { ...@@ -419,12 +424,9 @@ class NewSearchMod {
esMatchQuery = this._getESOperatorMatch('formula', this._tokenizeFormula(item)); esMatchQuery = this._getESOperatorMatch('formula', this._tokenizeFormula(item));
queryObj.push(esMatchQuery); queryObj.push(esMatchQuery);
}else if (queryTypes[i] === 'E'){ }else if (queryTypes[i] === 'E'){ // Element case
// if (this.elementTable.getAllowOtherElements())
queryObj.push(this._getESSimpleMatch('atom_labels', item)); queryObj.push(this._getESSimpleMatch('atom_labels', item));
//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'){ }else if (queryTypes[i] === 'Q'){
queryObj.push(item); queryObj.push(item);
} }
...@@ -432,8 +434,7 @@ class NewSearchMod { ...@@ -432,8 +434,7 @@ class NewSearchMod {
return rootQueryObj; return rootQueryObj;
} // else } // else
} // _getESQueryFromSearchQuery_otherElements()
} // _getESQueryFromSearchQuery()
_sortElements(elements){ _sortElements(elements){
...@@ -823,12 +824,12 @@ class FormulaBox{ ...@@ -823,12 +824,12 @@ class FormulaBox{
this.element.innerHTML= this.element.innerHTML=
` `
<div style="padding-bottom: 20px;"> <div style="padding-bottom: 20px;">
<!--
<input type="checkbox" class="allow-other-elements" value=""> <input type="checkbox" class="allow-other-elements" value="">
Allow other elements Allow other elements
<br> <br>
<!--
<input type="checkbox" class="multiples-of-formula" value=""> <input type="checkbox" class="multiples-of-formula" value="">
Include multiples of formula Include multiples of formula
<br> --> <br> -->
...@@ -864,12 +865,12 @@ class FormulaBox{ ...@@ -864,12 +865,12 @@ class FormulaBox{
this.formulaButton.disabled = true;//bool; this.formulaButton.disabled = true;//bool;
} }
/*
getAllowOtherElements(){ getAllowOtherElements(){
return this.element.querySelector('.allow-other-elements').checked; return this.element.querySelector('.allow-other-elements').checked;
} }
/*
getMultiplesOfFormula(){ getMultiplesOfFormula(){
return this.element.querySelector('.multiples-of-formula').checked; return this.element.querySelector('.multiples-of-formula').checked;
}*/ }*/
......
Supports Markdown
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