Commit 716a86e2 authored by Iker Hurtado's avatar Iker Hurtado
Browse files

Search filter implementation (unfinished)

parent 0d24f3cf
...@@ -417,8 +417,8 @@ ...@@ -417,8 +417,8 @@
// Case 1: my local dev environment // Case 1: my local dev environment
let API_HOST= 'http://enc-staging-nomad.esc.rzg.mpg.de/'; let API_HOST= 'http://enc-staging-nomad.esc.rzg.mpg.de/';
let USER_COOKIE_DOMAIN = 'localhost'; let USER_COOKIE_DOMAIN = 'localhost';
//let path = 'current/v1.0/'; // current development version of the API let path = 'current/v1.0/'; // current development version of the API
let path = 'v1.0/'; // stable staging // let path = 'v1.0/'; // stable staging
// Case 2: production environment // Case 2: production environment
if (document.location.href.indexOf('nomad-coe.eu') > 0){// if (document.location.href.indexOf('nomad-coe.eu') > 0){//
...@@ -7814,18 +7814,18 @@ ...@@ -7814,18 +7814,18 @@
if (this.searchQuery.lenght === 0){ if (this.searchQuery.lenght === 0){
util.showUserMsg('No query'); util.showUserMsg('No query');
}else{ }else{
let queryObj = { 'query' : { 'bool' : {} } }; let queryObj = { 'bool' : {} };
//queryObj.query.bool.must = {}; //queryObj.bool.must = {};
queryObj.query.bool.filter = []; queryObj.bool.filter = [];
let elements = []; let elements = [];
this.searchQuery.forEach( (item, i) => { this.searchQuery.forEach( (item, i) => {
if (this.queryTypes[i] === 'F'){ if (this.queryTypes[i] === 'F'){
queryObj.query.bool.filter.push(getFormulaESMatch(item)); queryObj.bool.filter.push(getESSimpleMatch('formula_reduced', item));
}else if (this.queryTypes[i] === 'MN'){ }else if (this.queryTypes[i] === 'MN'){
queryObj.query.bool.filter.push(getMatNameESMatch(item)); queryObj.bool.filter.push(getESSimpleMatch('material_name', item));
} }
else if (this.queryTypes[i] === 'E') elements.push(item); else if (this.queryTypes[i] === 'E') elements.push(item);
//else if (this.queryTypes[i] !== 'S'){ // property } //else if (this.queryTypes[i] !== 'S'){ // property }
...@@ -7833,10 +7833,12 @@ ...@@ -7833,10 +7833,12 @@
if (elements.length > 0) // If there are elements (there is no formula or material name) if (elements.length > 0) // If there are elements (there is no formula or material name)
queryObj.query.bool.filter.push(getAtomsESMatch(elements)); queryObj.bool.filter.push(this._getFieldESMatch('atom_labels', elements, true));//getAtomsESMatch(elements));
///atom_labels": { "operator": "and",
let filterMap = this.filterPanel.getValues(); let filterMap = this.filterPanel.getValues();
this._addFiltersInSearchQuery(filterMap, queryObj.query.bool.filter); this._addFiltersInSearchQuery(filterMap, queryObj.bool.filter);
//if (filters !== null) queryObj.query.bool.filter.push(filters); //if (filters !== null) queryObj.query.bool.filter.push(filters);
...@@ -7886,30 +7888,9 @@ ...@@ -7886,30 +7888,9 @@
} }
*/ */
function getAtomsESMatch(elements){ function getESSimpleMatch(field, value){
let elementsString = '';
if (elements.length > 0) elementsString = elements.join(' ');
let atomsMatch = {
"match": {
"atom_labels": {
"operator": "and",
"query": elementsString
}
}
};
return atomsMatch;
}
function getFormulaESMatch(formula){
return {
"match": { "formula_reduced": formula }
};
}
function getMatNameESMatch(name){
return { return {
"match": { "material_name": name } "match": { [field] : value }
}; };
} }
...@@ -7995,8 +7976,23 @@ ...@@ -7995,8 +7976,23 @@
_addFiltersInSearchQuery(filterMap, queryFilterArray){ _addFiltersInSearchQuery(filterMap, queryFilterArray){
//let filters = []; //let filters = [];
filterMap.forEach((values/*Array*/, filterName) => { filterMap.forEach((values/*Array*/, filterName) => {
if ('mass-density'){
let massDensity = values.split(':');
let massDensityObj = {
"range": {
"mass_density": { "gte" : massDensity[0], "lte" : massDensity[1] }
}
};
queryFilterArray.push( massDensityObj );
}else{ // normal case
let filterNameDef = replaceDashes(filterName); let filterNameDef = replaceDashes(filterName);
queryFilterArray.push( this._getFieldESMatch(filterNameDef, values, false) ); queryFilterArray.push( this._getFieldESMatch(filterNameDef, values, false) );
}
}); });
//return filters; //return filters;
} }
...@@ -8876,7 +8872,7 @@ ...@@ -8876,7 +8872,7 @@
let InfoSys = __webpack_require__(12); let InfoSys = __webpack_require__(12);
let LoadingPopup = __webpack_require__(4); let LoadingPopup = __webpack_require__(4);
const RESULTS_PER_PAGE = 25; const RESULTS_PER_PAGE = 20;
class MaterialList { class MaterialList {
...@@ -8976,50 +8972,33 @@ ...@@ -8976,50 +8972,33 @@
_search(){ /**************** ES queries!!!!!*/ _search(){ /**************** ES queries!!!!!*/
/*
let postQuery= `
{
"query" : {
"bool" : {
"filter" : {
"match" : { "formula_reduced": "Be3Li5" }
}
}
}
} `;
*/
let postQuery = JSON.stringify(this.searchJson); let postQuery = JSON.stringify(this.searchJson);
/* /*
let postQuery= ` let postQuery= `
{ {
"query" : {
"bool" : { "bool" : {
"filter" : { "filter" : {
"range" : { "mass_density": { "gte" : "1000"} } "range" : { "mass_density": { "gte" : 35000 } }
} }
} }
}
} `; } `;
*/ */
console.log('SENDING: ', postQuery); console.log('SENDING: ', postQuery);
LoadingPopup.show(); LoadingPopup.show();
//let oReq = util.serverReqPOST(util.getSearchURL(), postQuery, e => { //let oReq = util.serverReqPOST(util.getSearchURL(), postQuery, e => {
//let oReq = util.serverReqPOST('http://enc-staging-nomad.esc.rzg.mpg.de/current/v1.0/esmaterials', postQuery, e => { //let oReq = util.serverReqPOST('http://enc-staging-nomad.esc.rzg.mpg.de/current/v1.0/esmaterials', postQuery, e => {
let oReq = util.serverReqPOST(util.getSearchURL()+'?page='+this.page, postQuery, e => { let oReq = util.serverReqPOST(util.getSearchURL()+'?page='+this.page+'&per_page='+RESULTS_PER_PAGE, postQuery, e => {
let data= JSON.parse(e.target.response); let data= JSON.parse(e.target.response);
console.log('GETTING: ', data); console.log('GETTING: ', data);
if (e.target.status === 200){ if (e.target.status === 200){
this.total_results = data.total_results; this.total_results = data.total_results;
this.pagesNum = Math.ceil(data.total_results/10);//0;//(data.pages === null ? 1 : data.pages.pages); this.pagesNum = Math.ceil(data.total_results/RESULTS_PER_PAGE);//0;//(data.pages === null ? 1 : data.pages.pages);
let matData = data.results; let matData = data.results;
if (this.total_results === 1){ if (this.total_results === 1){
...@@ -9357,6 +9336,7 @@ ...@@ -9357,6 +9336,7 @@
let filterMap = new Map(); let filterMap = new Map();
this.addFilterFromTextField(filterMap, 'space-group-number'); this.addFilterFromTextField(filterMap, 'space-group-number');
this.addFilterFromCheckboxes(filterMap,'system-type'); this.addFilterFromCheckboxes(filterMap,'system-type');
this.addMassDensityFilter(filterMap);
this.addFilterFromDropdownList(filterMap, 'structure-type'); this.addFilterFromDropdownList(filterMap, 'structure-type');
this.addFilterFromCheckboxes(filterMap, 'crystal-system'); this.addFilterFromCheckboxes(filterMap, 'crystal-system');
console.log('FilterPanel selected:', filterMap); console.log('FilterPanel selected:', filterMap);
...@@ -9409,6 +9389,26 @@ ...@@ -9409,6 +9389,26 @@
//if (reset) field.selectedIndex = 0; //if (reset) field.selectedIndex = 0;
} }
addMassDensityFilter(filterMap){
let minField = document.querySelector('.mass-density-min-field');
let maxField = document.querySelector('.mass-density-max-field');
let fieldName = 'mass-density';
let value = ':';
//let label = 'Mass Density';
if (minField.value !== ''){
//label = minField.value+' < '+label;
value = minField.value+value;
//if (reset) minField.value = '';
}
if (maxField.value !== ''){
//label += ' < '+maxField.value;
value = value+maxField.value;
//if (reset) maxField.value = '';
}
if (value !== ':') filterMap.set(fieldName, value);
}
...@@ -9469,23 +9469,7 @@ ...@@ -9469,23 +9469,7 @@
} }
addMassDensityProps(propsMap, reset){
let minField = document.querySelector('.mass-density-min-field');
let maxField = document.querySelector('.mass-density-max-field');
let fieldName = 'mass-density';
let label = 'Mass Density';
if (minField.value !== ''){
label = minField.value+' < '+label;
fieldName += ':'+minField.value;
if (reset) minField.value = '';
}
if (maxField.value !== ''){
label += ' < '+maxField.value;
fieldName += ':'+maxField.value;
if (reset) maxField.value = '';
}
if (label !== 'Mass Density') propsMap.set(fieldName, [label]);
}
setAddPropertiesListener(listener) { setAddPropertiesListener(listener) {
......
...@@ -74,8 +74,8 @@ let ELEMENTS = [ ...@@ -74,8 +74,8 @@ let ELEMENTS = [
// Case 1: my local dev environment // Case 1: my local dev environment
let API_HOST= 'http://enc-staging-nomad.esc.rzg.mpg.de/'; let API_HOST= 'http://enc-staging-nomad.esc.rzg.mpg.de/';
let USER_COOKIE_DOMAIN = 'localhost'; let USER_COOKIE_DOMAIN = 'localhost';
//let path = 'current/v1.0/'; // current development version of the API let path = 'current/v1.0/'; // current development version of the API
let path = 'v1.0/'; // stable staging // let path = 'v1.0/'; // stable staging
// Case 2: production environment // Case 2: production environment
if (document.location.href.indexOf('nomad-coe.eu') > 0){// if (document.location.href.indexOf('nomad-coe.eu') > 0){//
......
...@@ -158,6 +158,7 @@ class FilterPanel { ...@@ -158,6 +158,7 @@ class FilterPanel {
let filterMap = new Map(); let filterMap = new Map();
this.addFilterFromTextField(filterMap, 'space-group-number'); this.addFilterFromTextField(filterMap, 'space-group-number');
this.addFilterFromCheckboxes(filterMap,'system-type'); this.addFilterFromCheckboxes(filterMap,'system-type');
this.addMassDensityFilter(filterMap);
this.addFilterFromDropdownList(filterMap, 'structure-type'); this.addFilterFromDropdownList(filterMap, 'structure-type');
this.addFilterFromCheckboxes(filterMap, 'crystal-system'); this.addFilterFromCheckboxes(filterMap, 'crystal-system');
console.log('FilterPanel selected:', filterMap); console.log('FilterPanel selected:', filterMap);
...@@ -210,6 +211,26 @@ class FilterPanel { ...@@ -210,6 +211,26 @@ class FilterPanel {
//if (reset) field.selectedIndex = 0; //if (reset) field.selectedIndex = 0;
} }
addMassDensityFilter(filterMap){
let minField = document.querySelector('.mass-density-min-field');
let maxField = document.querySelector('.mass-density-max-field');
let fieldName = 'mass-density';
let value = ':';
//let label = 'Mass Density';
if (minField.value !== ''){
//label = minField.value+' < '+label;
value = minField.value+value;
//if (reset) minField.value = '';
}
if (maxField.value !== ''){
//label += ' < '+maxField.value;
value = value+maxField.value;
//if (reset) maxField.value = '';
}
if (value !== ':') filterMap.set(fieldName, value);
}
...@@ -270,23 +291,7 @@ class FilterPanel { ...@@ -270,23 +291,7 @@ class FilterPanel {
} }
addMassDensityProps(propsMap, reset){
let minField = document.querySelector('.mass-density-min-field');
let maxField = document.querySelector('.mass-density-max-field');
let fieldName = 'mass-density';
let label = 'Mass Density';
if (minField.value !== ''){
label = minField.value+' < '+label;
fieldName += ':'+minField.value;
if (reset) minField.value = '';
}
if (maxField.value !== ''){
label += ' < '+maxField.value;
fieldName += ':'+maxField.value;
if (reset) maxField.value = '';
}
if (label !== 'Mass Density') propsMap.set(fieldName, [label]);
}
setAddPropertiesListener(listener) { setAddPropertiesListener(listener) {
......
...@@ -27,7 +27,7 @@ let util = require('../common/util.js'); ...@@ -27,7 +27,7 @@ let util = require('../common/util.js');
let InfoSys = require('../common/InfoSys.js'); let InfoSys = require('../common/InfoSys.js');
let LoadingPopup = require('../common/LoadingPopup.js'); let LoadingPopup = require('../common/LoadingPopup.js');
const RESULTS_PER_PAGE = 25; const RESULTS_PER_PAGE = 20;
class MaterialList { class MaterialList {
...@@ -127,50 +127,33 @@ class MaterialList { ...@@ -127,50 +127,33 @@ class MaterialList {
_search(){ /**************** ES queries!!!!!*/ _search(){ /**************** ES queries!!!!!*/
/*
let postQuery= `
{
"query" : {
"bool" : {
"filter" : {
"match" : { "formula_reduced": "Be3Li5" }
}
}
}
} `;
*/
let postQuery = JSON.stringify(this.searchJson); let postQuery = JSON.stringify(this.searchJson);
/* /*
let postQuery= ` let postQuery= `
{ {
"query" : {
"bool" : { "bool" : {
"filter" : { "filter" : {
"range" : { "mass_density": { "gte" : "1000"} } "range" : { "mass_density": { "gte" : 35000 } }
}
} }
} }
} `; } `;
*/ */
console.log('SENDING: ', postQuery); console.log('SENDING: ', postQuery);
LoadingPopup.show(); LoadingPopup.show();
//let oReq = util.serverReqPOST(util.getSearchURL(), postQuery, e => { //let oReq = util.serverReqPOST(util.getSearchURL(), postQuery, e => {
//let oReq = util.serverReqPOST('http://enc-staging-nomad.esc.rzg.mpg.de/current/v1.0/esmaterials', postQuery, e => { //let oReq = util.serverReqPOST('http://enc-staging-nomad.esc.rzg.mpg.de/current/v1.0/esmaterials', postQuery, e => {
let oReq = util.serverReqPOST(util.getSearchURL()+'?page='+this.page, postQuery, e => { let oReq = util.serverReqPOST(util.getSearchURL()+'?page='+this.page+'&per_page='+RESULTS_PER_PAGE, postQuery, e => {
let data= JSON.parse(e.target.response); let data= JSON.parse(e.target.response);
console.log('GETTING: ', data); console.log('GETTING: ', data);
if (e.target.status === 200){ if (e.target.status === 200){
this.total_results = data.total_results; this.total_results = data.total_results;
this.pagesNum = Math.ceil(data.total_results/10);//0;//(data.pages === null ? 1 : data.pages.pages); this.pagesNum = Math.ceil(data.total_results/RESULTS_PER_PAGE);//0;//(data.pages === null ? 1 : data.pages.pages);
let matData = data.results; let matData = data.results;
if (this.total_results === 1){ if (this.total_results === 1){
......
...@@ -199,18 +199,18 @@ class NewSearchMod { ...@@ -199,18 +199,18 @@ class NewSearchMod {
if (this.searchQuery.lenght === 0){ if (this.searchQuery.lenght === 0){
util.showUserMsg('No query'); util.showUserMsg('No query');
}else{ }else{
let queryObj = { 'query' : { 'bool' : {} } }; let queryObj = { 'bool' : {} };
//queryObj.query.bool.must = {}; //queryObj.bool.must = {};
queryObj.query.bool.filter = []; queryObj.bool.filter = [];
let elements = []; let elements = [];
this.searchQuery.forEach( (item, i) => { this.searchQuery.forEach( (item, i) => {
if (this.queryTypes[i] === 'F'){ if (this.queryTypes[i] === 'F'){
queryObj.query.bool.filter.push(getFormulaESMatch(item)); queryObj.bool.filter.push(getESSimpleMatch('formula_reduced', item));
}else if (this.queryTypes[i] === 'MN'){ }else if (this.queryTypes[i] === 'MN'){
queryObj.query.bool.filter.push(getMatNameESMatch(item)); queryObj.bool.filter.push(getESSimpleMatch('material_name', item));
} }
else if (this.queryTypes[i] === 'E') elements.push(item); else if (this.queryTypes[i] === 'E') elements.push(item);
//else if (this.queryTypes[i] !== 'S'){ // property } //else if (this.queryTypes[i] !== 'S'){ // property }
...@@ -218,10 +218,12 @@ class NewSearchMod { ...@@ -218,10 +218,12 @@ class NewSearchMod {
if (elements.length > 0) // If there are elements (there is no formula or material name) if (elements.length > 0) // If there are elements (there is no formula or material name)
queryObj.query.bool.filter.push(getAtomsESMatch(elements)); queryObj.bool.filter.push(this._getFieldESMatch('atom_labels', elements, true));//getAtomsESMatch(elements));
///atom_labels": { "operator": "and",
let filterMap = this.filterPanel.getValues(); let filterMap = this.filterPanel.getValues();
this._addFiltersInSearchQuery(filterMap, queryObj.query.bool.filter); this._addFiltersInSearchQuery(filterMap, queryObj.bool.filter);
//if (filters !== null) queryObj.query.bool.filter.push(filters); //if (filters !== null) queryObj.query.bool.filter.push(filters);
...@@ -271,30 +273,9 @@ class NewSearchMod { ...@@ -271,30 +273,9 @@ class NewSearchMod {
} }
*/ */
function getAtomsESMatch(elements){ function getESSimpleMatch(field, value){
let elementsString = '';
if (elements.length > 0) elementsString = elements.join(' ');
let atomsMatch = {
"match": {
"atom_labels": {
"operator": "and",
"query": elementsString
}
}
};
return atomsMatch;
}
function getFormulaESMatch(formula){
return { return {
"match": { "formula_reduced": formula } "match": { [field] : value }
};
}
function getMatNameESMatch(name){
return {
"match": { "material_name": name }
}; };
} }
...@@ -380,8 +361,23 @@ class NewSearchMod { ...@@ -380,8 +361,23 @@ class NewSearchMod {
_addFiltersInSearchQuery(filterMap, queryFilterArray){ _addFiltersInSearchQuery(filterMap, queryFilterArray){
//let filters = []; //let filters = [];
filterMap.forEach((values/*Array*/, filterName) => { filterMap.forEach((values/*Array*/, filterName) => {
if ('mass-density'){
let massDensity = values.split(':');
let massDensityObj = {
"range": {
"mass_density": { "gte" : massDensity[0], "lte" : massDensity[1] }
}
};
queryFilterArray.push( massDensityObj );
}else{ // normal case
let filterNameDef = replaceDashes(filterName); let filterNameDef = replaceDashes(filterName);
queryFilterArray.push( this._getFieldESMatch(filterNameDef, values, false) ); queryFilterArray.push( this._getFieldESMatch(filterNameDef, values, false) );
}
}); });
//return filters; //return filters;
} }
......