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

Add the checkboxes that modify the search by Elements and Formula (5)

parent b77a86df
......@@ -7816,9 +7816,10 @@
//if (this.elementTable.getAllowOtherElements())
//else
let esMatchQuery;
if (this.formulaBox.getMultiplesOfFormula())
if (this.formulaBox.getMultiplesOfFormula()){
esMatchQuery = this._getESSimpleMatch('formula_reduced', item);
else
this._reduceFormula(item);
}else
esMatchQuery = this._getESSimpleMatch('formula', item);
queryObj.bool.filter.push(esMatchQuery);
......@@ -7980,6 +7981,80 @@
}
_reduceFormula(formula){
let index = 0;
let map = new Map();
let key;
while ( index < formula.length ){
console.log('_reduceFormula index', index);
let el2 = formula.substring(index, index+2);
let el1 = formula.substring(index, index+1);
if (util.ELEMENTS.indexOf(el2) >= 0){
map.set(el2, 1); // 1 default value
index += 2;
key = el2;
console.log('eleemnt 2chars', key);
}else if (util.ELEMENTS.indexOf(el1) >= 0){
map.set(el1, 1); // 1 default value
index++;
key = el1;
console.log('eleemnt 1chars', key);
}else{ // It's a number
// ************ parseInt(el2)
let num = parseInt(el2);
//console.log('parsed number ', el2, num);
if (num >= 10){ // 2 figures number
index += 2;
}else{ // 1 figure number
index++;
}
console.log('number ', num, key);
map.set(key, num);
}
console.log('FINAL LOOP', map, index);
}
let counter = 0;
while ( !checkIfReduced(map) ){
console.log('Reducing', map);
let div = 1;
if (isDivisibleBy(map, 2)) div = 2;
else if (isDivisibleBy(map, 3)) div = 3;
else if (isDivisibleBy(map, 5)) div = 5;
else if (isDivisibleBy(map, 7)) div = 7;
else if (isDivisibleBy(map, 11)) div = 11;
map.forEach( (value, key) => {
value = value/div;
map.set(key, (value/div));
});
console.log('Reducing DIV', map);
counter++;
if (counter > 5) break;
}
function checkIfReduced(formulaMap){
let min = 100;
formulaMap.forEach( (value, key) => {
if (value < min) min = value;
});
return min === 1;
}
function isDivisibleBy(formulaMap, n){
let div = true;
formulaMap.forEach( (value, key) => {
if (value % n !== 0) div = false;
});
return div;
}
//console.log('_reduceFormula', map);
return formula;
}
_addFiltersInSearchQuery(filterMap, queryFilterArray){
//let filters = [];
filterMap.forEach((values/*Array*/, filterName) => {
......
......@@ -209,9 +209,10 @@ class NewSearchMod {
//if (this.elementTable.getAllowOtherElements())
//else
let esMatchQuery;
if (this.formulaBox.getMultiplesOfFormula())
if (this.formulaBox.getMultiplesOfFormula()){
esMatchQuery = this._getESSimpleMatch('formula_reduced', item);
else
this._reduceFormula(item);
}else
esMatchQuery = this._getESSimpleMatch('formula', item);
queryObj.bool.filter.push(esMatchQuery);
......@@ -373,6 +374,80 @@ class NewSearchMod {
}
_reduceFormula(formula){
let index = 0;
let map = new Map();
let key;
while ( index < formula.length ){
console.log('_reduceFormula index', index);
let el2 = formula.substring(index, index+2);
let el1 = formula.substring(index, index+1);
if (util.ELEMENTS.indexOf(el2) >= 0){
map.set(el2, 1); // 1 default value
index += 2;
key = el2;
console.log('eleemnt 2chars', key);
}else if (util.ELEMENTS.indexOf(el1) >= 0){
map.set(el1, 1); // 1 default value
index++;
key = el1;
console.log('eleemnt 1chars', key);
}else{ // It's a number
// ************ parseInt(el2)
let num = parseInt(el2);
//console.log('parsed number ', el2, num);
if (num >= 10){ // 2 figures number
index += 2;
}else{ // 1 figure number
index++;
}
console.log('number ', num, key);
map.set(key, num);
}
console.log('FINAL LOOP', map, index);
}
let counter = 0;
while ( !checkIfReduced(map) ){
console.log('Reducing', map);
let div = 1;
if (isDivisibleBy(map, 2)) div = 2;
else if (isDivisibleBy(map, 3)) div = 3;
else if (isDivisibleBy(map, 5)) div = 5;
else if (isDivisibleBy(map, 7)) div = 7;
else if (isDivisibleBy(map, 11)) div = 11;
map.forEach( (value, key) => {
value = value/div;
map.set(key, (value/div));
});
console.log('Reducing DIV', map);
counter++;
if (counter > 5) break;
}
function checkIfReduced(formulaMap){
let min = 100;
formulaMap.forEach( (value, key) => {
if (value < min) min = value;
});
return min === 1;
}
function isDivisibleBy(formulaMap, n){
let div = true;
formulaMap.forEach( (value, key) => {
if (value % n !== 0) div = false;
});
return div;
}
//console.log('_reduceFormula', map);
return formula;
}
_addFiltersInSearchQuery(filterMap, queryFilterArray){
//let filters = [];
filterMap.forEach((values/*Array*/, filterName) => {
......
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