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

Search filter implementation (unfinished)

parent 8b9530e5
......@@ -417,7 +417,8 @@
// Case 1: my local dev environment
let API_HOST= 'http://enc-staging-nomad.esc.rzg.mpg.de/';
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
if (document.location.href.indexOf('nomad-coe.eu') > 0){//
......@@ -524,7 +525,7 @@
function getSearchURL(){
return API_BASE_URL+'materials';
return API_BASE_URL+'esmaterials';
}
function getSuggestionURL(quantity){
......@@ -7835,8 +7836,8 @@
queryObj.query.bool.filter.push(getAtomsESMatch(elements));
let filterMap = this.filterPanel.getValues();
let filters = this._addPropertiesInSearchQuery(filterMap);
if (filters !== null) queryObj.query.bool.filter.push(filters);
this._addFiltersInSearchQuery(filterMap, queryObj.query.bool.filter);
//if (filters !== null) queryObj.query.bool.filter.push(filters);
this.materialList.setSearch(queryObj);
......@@ -7991,15 +7992,28 @@
}
_addPropertiesInSearchQuery(propsMap){
let filter = null;
propsMap.forEach((values/*Array*/, propName) => {
filter = {
"match": { "space_group_number": values[0] }
};
console.log('_addPropertiesInSearchQuery', filter);
_addFiltersInSearchQuery(filterMap, queryFilterArray){
//let filters = [];
filterMap.forEach((values/*Array*/, filterName) => {
let filterNameDef = replaceDashes(filterName);
queryFilterArray.push( this._getFieldESMatch(filterNameDef, values, false) );
});
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 @@
*/
let postQuery = JSON.stringify(this.searchJson);
/*
let postQuery= `
{
"query" : {
"bool" : {
"filter" : {
"range" : { "mass_density": { "gte" : "1000"} }
}
}
}
} `;
*/
console.log('SENDING: ', postQuery);
LoadingPopup.show();
//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);
console.log('GETTING: ', data);
......@@ -9326,10 +9354,13 @@
getValues(){
//let map = this.getPropsWithValueFromCurrentTab(false);
let propsMap = new Map();
this.addPropFromTextField(propsMap, 'space-group-number');
console.log('FilterPanel selected:', propsMap);
return propsMap;
let filterMap = new Map();
this.addFilterFromTextField(filterMap, 'space-group-number');
this.addFilterFromCheckboxes(filterMap,'system-type');
this.addFilterFromDropdownList(filterMap, 'structure-type');
this.addFilterFromCheckboxes(filterMap, 'crystal-system');
console.log('FilterPanel selected:', filterMap);
return filterMap;
}
/*
......@@ -9356,11 +9387,31 @@
*/
addPropFromTextField(propsMap, prop, reset = false){
let field = this.element.querySelector('.'+prop+'-field');
if (field.value !== '') propsMap.set(prop, [field.value]);
addFilterFromTextField(filterMap, filterName){
let field = this.element.querySelector('.'+filterName+'-field');
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){
propsArray.forEach(propName => {
let field = this.element.querySelector('.'+propName+'-field');
......
......@@ -74,7 +74,8 @@ let ELEMENTS = [
// Case 1: my local dev environment
let API_HOST= 'http://enc-staging-nomad.esc.rzg.mpg.de/';
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
if (document.location.href.indexOf('nomad-coe.eu') > 0){//
......@@ -181,7 +182,7 @@ function getSubscriptedFormula(formula){
function getSearchURL(){
return API_BASE_URL+'materials';
return API_BASE_URL+'esmaterials';
}
function getSuggestionURL(quantity){
......
......@@ -155,10 +155,13 @@ class FilterPanel {
getValues(){
//let map = this.getPropsWithValueFromCurrentTab(false);
let propsMap = new Map();
this.addPropFromTextField(propsMap, 'space-group-number');
console.log('FilterPanel selected:', propsMap);
return propsMap;
let filterMap = new Map();
this.addFilterFromTextField(filterMap, 'space-group-number');
this.addFilterFromCheckboxes(filterMap,'system-type');
this.addFilterFromDropdownList(filterMap, 'structure-type');
this.addFilterFromCheckboxes(filterMap, 'crystal-system');
console.log('FilterPanel selected:', filterMap);
return filterMap;
}
/*
......@@ -185,11 +188,31 @@ class FilterPanel {
*/
addPropFromTextField(propsMap, prop, reset = false){
let field = this.element.querySelector('.'+prop+'-field');
if (field.value !== '') propsMap.set(prop, [field.value]);
addFilterFromTextField(filterMap, filterName){
let field = this.element.querySelector('.'+filterName+'-field');
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){
propsArray.forEach(propName => {
let field = this.element.querySelector('.'+propName+'-field');
......
......@@ -143,14 +143,28 @@ class MaterialList {
*/
let postQuery = JSON.stringify(this.searchJson);
/*
let postQuery= `
{
"query" : {
"bool" : {
"filter" : {
"range" : { "mass_density": { "gte" : "1000"} }
}
}
}
} `;
*/
console.log('SENDING: ', postQuery);
LoadingPopup.show();
//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);
console.log('GETTING: ', data);
......
......@@ -221,8 +221,8 @@ class NewSearchMod {
queryObj.query.bool.filter.push(getAtomsESMatch(elements));
let filterMap = this.filterPanel.getValues();
let filters = this._addPropertiesInSearchQuery(filterMap);
if (filters !== null) queryObj.query.bool.filter.push(filters);
this._addFiltersInSearchQuery(filterMap, queryObj.query.bool.filter);
//if (filters !== null) queryObj.query.bool.filter.push(filters);
this.materialList.setSearch(queryObj);
......@@ -377,15 +377,28 @@ class NewSearchMod {
}
_addPropertiesInSearchQuery(propsMap){
let filter = null;
propsMap.forEach((values/*Array*/, propName) => {
filter = {
"match": { "space_group_number": values[0] }
};
console.log('_addPropertiesInSearchQuery', filter);
_addFiltersInSearchQuery(filterMap, queryFilterArray){
//let filters = [];
filterMap.forEach((values/*Array*/, filterName) => {
let filterNameDef = replaceDashes(filterName);
queryFilterArray.push( this._getFieldESMatch(filterNameDef, values, false) );
});
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