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

Complex search logic implementation (9)

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