Commit 0d24f3cf authored by Iker Hurtado's avatar Iker Hurtado
Browse files

Search filter implementation (unfinished)

parent 8b9530e5
...@@ -417,7 +417,8 @@ ...@@ -417,7 +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 = 'v1.0/'; //let path = 'current/v1.0/'; // current development version of the API
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){//
...@@ -524,7 +525,7 @@ ...@@ -524,7 +525,7 @@
function getSearchURL(){ function getSearchURL(){
return API_BASE_URL+'materials'; return API_BASE_URL+'esmaterials';
} }
function getSuggestionURL(quantity){ function getSuggestionURL(quantity){
...@@ -7835,8 +7836,8 @@ ...@@ -7835,8 +7836,8 @@
queryObj.query.bool.filter.push(getAtomsESMatch(elements)); queryObj.query.bool.filter.push(getAtomsESMatch(elements));
let filterMap = this.filterPanel.getValues(); let filterMap = this.filterPanel.getValues();
let filters = this._addPropertiesInSearchQuery(filterMap); this._addFiltersInSearchQuery(filterMap, queryObj.query.bool.filter);
if (filters !== null) queryObj.query.bool.filter.push(filters); //if (filters !== null) queryObj.query.bool.filter.push(filters);
this.materialList.setSearch(queryObj); this.materialList.setSearch(queryObj);
...@@ -7991,15 +7992,28 @@ ...@@ -7991,15 +7992,28 @@
} }
_addPropertiesInSearchQuery(propsMap){ _addFiltersInSearchQuery(filterMap, queryFilterArray){
let filter = null; //let filters = [];
propsMap.forEach((values/*Array*/, propName) => { filterMap.forEach((values/*Array*/, filterName) => {
filter = { let filterNameDef = replaceDashes(filterName);
"match": { "space_group_number": values[0] } queryFilterArray.push( this._getFieldESMatch(filterNameDef, values, false) );
};
console.log('_addPropertiesInSearchQuery', filter);
}); });
return filter; //return filters;
}
_getFieldESMatch(field, elements, and = true){
let elementsString = '';
if (elements.length > 0) elementsString = elements.join(' ');
return {
"match": {
[field]: {
"operator": (and ? "and" : 'or'),
"query": elementsString
}
}
};
} }
...@@ -8978,14 +8992,28 @@ ...@@ -8978,14 +8992,28 @@
*/ */
let postQuery = JSON.stringify(this.searchJson); let postQuery = JSON.stringify(this.searchJson);
/*
let postQuery= `
{
"query" : {
"bool" : {
"filter" : {
"range" : { "mass_density": { "gte" : "1000"} }
}
}
}
} `;
*/
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/v1.0/esmaterials?page='+this.page, 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 data= JSON.parse(e.target.response); let data= JSON.parse(e.target.response);
console.log('GETTING: ', data); console.log('GETTING: ', data);
...@@ -9326,10 +9354,13 @@ ...@@ -9326,10 +9354,13 @@
getValues(){ getValues(){
//let map = this.getPropsWithValueFromCurrentTab(false); //let map = this.getPropsWithValueFromCurrentTab(false);
let propsMap = new Map(); let filterMap = new Map();
this.addPropFromTextField(propsMap, 'space-group-number'); this.addFilterFromTextField(filterMap, 'space-group-number');
console.log('FilterPanel selected:', propsMap); this.addFilterFromCheckboxes(filterMap,'system-type');
return propsMap; this.addFilterFromDropdownList(filterMap, 'structure-type');
this.addFilterFromCheckboxes(filterMap, 'crystal-system');
console.log('FilterPanel selected:', filterMap);
return filterMap;
} }
/* /*
...@@ -9356,11 +9387,31 @@ ...@@ -9356,11 +9387,31 @@
*/ */
addPropFromTextField(propsMap, prop, reset = false){ addFilterFromTextField(filterMap, filterName){
let field = this.element.querySelector('.'+prop+'-field'); let field = this.element.querySelector('.'+filterName+'-field');
if (field.value !== '') propsMap.set(prop, [field.value]); if (field.value !== '') filterMap.set(filterName, [field.value]);
} }
addFilterFromCheckboxes(filterMap, filterName){
let checkboxes = this.element.querySelectorAll('.'+filterName+'-field');
let value = [];
for (var i = 0; i < checkboxes.length; i++) {
if (checkboxes[i].checked) value.push(checkboxes[i].value);
//if (reset) checkboxes[i].checked = false;
}
if (value.length > 0) filterMap.set(filterName, value);
}
addFilterFromDropdownList(filterMap, filterName){
let field = this.element.querySelector('.'+filterName+'-field');
let value = field.options[field.selectedIndex].value;
if (value.length > 2) filterMap.set(filterName, [value]);
//if (reset) field.selectedIndex = 0;
}
addPropsFromTextFields(propsMap,propsArray, reset = false){ addPropsFromTextFields(propsMap,propsArray, reset = false){
propsArray.forEach(propName => { propsArray.forEach(propName => {
let field = this.element.querySelector('.'+propName+'-field'); let field = this.element.querySelector('.'+propName+'-field');
......
...@@ -74,7 +74,8 @@ let ELEMENTS = [ ...@@ -74,7 +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 = 'v1.0/'; //let path = 'current/v1.0/'; // current development version of the API
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){//
...@@ -181,7 +182,7 @@ function getSubscriptedFormula(formula){ ...@@ -181,7 +182,7 @@ function getSubscriptedFormula(formula){
function getSearchURL(){ function getSearchURL(){
return API_BASE_URL+'materials'; return API_BASE_URL+'esmaterials';
} }
function getSuggestionURL(quantity){ function getSuggestionURL(quantity){
......
...@@ -155,10 +155,13 @@ class FilterPanel { ...@@ -155,10 +155,13 @@ class FilterPanel {
getValues(){ getValues(){
//let map = this.getPropsWithValueFromCurrentTab(false); //let map = this.getPropsWithValueFromCurrentTab(false);
let propsMap = new Map(); let filterMap = new Map();
this.addPropFromTextField(propsMap, 'space-group-number'); this.addFilterFromTextField(filterMap, 'space-group-number');
console.log('FilterPanel selected:', propsMap); this.addFilterFromCheckboxes(filterMap,'system-type');
return propsMap; this.addFilterFromDropdownList(filterMap, 'structure-type');
this.addFilterFromCheckboxes(filterMap, 'crystal-system');
console.log('FilterPanel selected:', filterMap);
return filterMap;
} }
/* /*
...@@ -185,11 +188,31 @@ class FilterPanel { ...@@ -185,11 +188,31 @@ class FilterPanel {
*/ */
addPropFromTextField(propsMap, prop, reset = false){ addFilterFromTextField(filterMap, filterName){
let field = this.element.querySelector('.'+prop+'-field'); let field = this.element.querySelector('.'+filterName+'-field');
if (field.value !== '') propsMap.set(prop, [field.value]); if (field.value !== '') filterMap.set(filterName, [field.value]);
}
addFilterFromCheckboxes(filterMap, filterName){
let checkboxes = this.element.querySelectorAll('.'+filterName+'-field');
let value = [];
for (var i = 0; i < checkboxes.length; i++) {
if (checkboxes[i].checked) value.push(checkboxes[i].value);
//if (reset) checkboxes[i].checked = false;
}
if (value.length > 0) filterMap.set(filterName, value);
}
addFilterFromDropdownList(filterMap, filterName){
let field = this.element.querySelector('.'+filterName+'-field');
let value = field.options[field.selectedIndex].value;
if (value.length > 2) filterMap.set(filterName, [value]);
//if (reset) field.selectedIndex = 0;
} }
addPropsFromTextFields(propsMap,propsArray, reset = false){ addPropsFromTextFields(propsMap,propsArray, reset = false){
propsArray.forEach(propName => { propsArray.forEach(propName => {
let field = this.element.querySelector('.'+propName+'-field'); let field = this.element.querySelector('.'+propName+'-field');
......
...@@ -143,14 +143,28 @@ class MaterialList { ...@@ -143,14 +143,28 @@ class MaterialList {
*/ */
let postQuery = JSON.stringify(this.searchJson); let postQuery = JSON.stringify(this.searchJson);
/*
let postQuery= `
{
"query" : {
"bool" : {
"filter" : {
"range" : { "mass_density": { "gte" : "1000"} }
}
}
}
} `;
*/
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/v1.0/esmaterials?page='+this.page, 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 data= JSON.parse(e.target.response); let data= JSON.parse(e.target.response);
console.log('GETTING: ', data); console.log('GETTING: ', data);
......
...@@ -221,8 +221,8 @@ class NewSearchMod { ...@@ -221,8 +221,8 @@ class NewSearchMod {
queryObj.query.bool.filter.push(getAtomsESMatch(elements)); queryObj.query.bool.filter.push(getAtomsESMatch(elements));
let filterMap = this.filterPanel.getValues(); let filterMap = this.filterPanel.getValues();
let filters = this._addPropertiesInSearchQuery(filterMap); this._addFiltersInSearchQuery(filterMap, queryObj.query.bool.filter);
if (filters !== null) queryObj.query.bool.filter.push(filters); //if (filters !== null) queryObj.query.bool.filter.push(filters);
this.materialList.setSearch(queryObj); this.materialList.setSearch(queryObj);
...@@ -377,15 +377,28 @@ class NewSearchMod { ...@@ -377,15 +377,28 @@ class NewSearchMod {
} }
_addPropertiesInSearchQuery(propsMap){ _addFiltersInSearchQuery(filterMap, queryFilterArray){
let filter = null; //let filters = [];
propsMap.forEach((values/*Array*/, propName) => { filterMap.forEach((values/*Array*/, filterName) => {
filter = { let filterNameDef = replaceDashes(filterName);
"match": { "space_group_number": values[0] } queryFilterArray.push( this._getFieldESMatch(filterNameDef, values, false) );
};
console.log('_addPropertiesInSearchQuery', filter);
}); });
return filter; //return filters;
}
_getFieldESMatch(field, elements, and = true){
let elementsString = '';
if (elements.length > 0) elementsString = elements.join(' ');
return {
"match": {
[field]: {
"operator": (and ? "and" : 'or'),
"query": elementsString
}
}
};
} }
......
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