Commit 8b9530e5 authored by Iker Hurtado's avatar Iker Hurtado
Browse files

First filter gathering

parent 6050e99d
......@@ -7799,6 +7799,7 @@
this.searchQuery = [];
this.queryTypes = []; //**** Types associated to query elements
// Types: element (E), formula (F), symbol (S) and prop names
this.searchFilters = [];
this._events();
}
......@@ -7818,21 +7819,25 @@
let elements = [];
this.searchQuery.forEach( (item, i) => {
if (this.queryTypes[i] === 'F'){
queryObj.query.bool.filter.push(getFormulaESMatch(item));
}else if (this.queryTypes[i] === 'MN'){
queryObj.query.bool.filter.push(getMatNameESMatch(item));
}
else if (this.queryTypes[i] === 'E') elements.push(item);
else if (this.queryTypes[i] !== 'S'){ // property
}
//else if (this.queryTypes[i] !== 'S'){ // property }
});
if (elements.length > 0) // If there are elements (there is no formula or material name)
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.materialList.setSearch(queryObj);
//util.setBrowserHashPath('search','results');
......@@ -7981,6 +7986,20 @@
}
});
}
_addPropertiesInSearchQuery(propsMap){
let filter = null;
propsMap.forEach((values/*Array*/, propName) => {
filter = {
"match": { "space_group_number": values[0] }
};
console.log('_addPropertiesInSearchQuery', filter);
});
return filter;
}
......@@ -8030,9 +8049,9 @@
return true;
}
/*
addPropertiesInSearchQuery(propsMap){
propsMap.forEach((values/*Array*/, propName) => {
propsMap.forEach((values, propName) => {
let i = this.queryTypes.indexOf(propName);
if (i < 0)
this.addTagInSearchQuery(values.join(' | '), propName);
......@@ -8047,7 +8066,7 @@
//this._showSearchBox();
}
});
}
}*/
removeElementORFormulaInSearchQuery(element){
......@@ -8105,7 +8124,7 @@
html+= getTagHtml(this.searchQuery[i], ( type === 'F' ? true : false));
}
console.log('this.updateSearchQuery: ', this.searchQuery ,this.queryTypes);
this.searchQueryBox.innerHTML= html;
this.searchQueryBox.innerHTML = html;
}
///********* DELETE?
......@@ -8937,11 +8956,11 @@
this.searchJson = searchJson;
this.page = 1;
this._search1();
this._search();
}
_search1(){ /**************** ES queries!!!!!*/
_search(){ /**************** ES queries!!!!!*/
/*
let postQuery= `
......@@ -8966,14 +8985,14 @@
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', postQuery, e => {
let oReq = util.serverReqPOST('http://enc-staging-nomad.esc.rzg.mpg.de/v1.0/esmaterials?page='+this.page, postQuery, e => {
let data= JSON.parse(e.target.response);
console.log('GETTING: ', data);
/*
if (e.target.status === 200){
this.total_results= data.total_results;
this.pagesNum= (data.pages === null ? 1 : data.pages.pages);
let matData= data.results;
this.total_results = data.total_results;
this.pagesNum = Math.ceil(data.total_results/10);//0;//(data.pages === null ? 1 : data.pages.pages);
let matData = data.results;
if (this.total_results === 1){
util.setBrowserHashPath('material',+matData[0].id);
......@@ -8989,14 +9008,15 @@
this.setData([]);
}
this._updateUI();
*/
this.resultsContainer.style.visibility = 'visible';
LoadingPopup.hide();
});
}
/*
_search(){
this.searchJson.search_by.page = this.page;
......@@ -9013,7 +9033,7 @@
this.pagesNum= (data.pages === null ? 1 : data.pages.pages);
let matData= data.results;
if (/*matData.length === 1 && */this.total_results === 1){
if (this.total_results === 1){
util.setBrowserHashPath('material',+matData[0].id);
util.searchResults = false;
}else{
......@@ -9042,7 +9062,7 @@
});
}
*/
setData(data){
//this.formula= formula;
......@@ -9299,11 +9319,17 @@
panel.addEventListener( 'input', e => { this.checkPropsValues(); });
panel.addEventListener( 'change', e => { this.checkPropsValues(); });
*/
}
checkPropsValues(){
getValues(){
//let map = this.getPropsWithValueFromCurrentTab(false);
let propsMap = new Map();
this.addPropFromTextField(propsMap, 'space-group-number');
console.log('FilterPanel selected:', propsMap);
return propsMap;
}
/*
......@@ -9330,7 +9356,12 @@
*/
addPropsFromTextFields(propsMap,propsArray, reset){
addPropFromTextField(propsMap, prop, reset = false){
let field = this.element.querySelector('.'+prop+'-field');
if (field.value !== '') propsMap.set(prop, [field.value]);
}
addPropsFromTextFields(propsMap,propsArray, reset = false){
propsArray.forEach(propName => {
let field = this.element.querySelector('.'+propName+'-field');
if (field.value !== ''){
......
......@@ -148,11 +148,17 @@ class FilterPanel {
panel.addEventListener( 'input', e => { this.checkPropsValues(); });
panel.addEventListener( 'change', e => { this.checkPropsValues(); });
*/
}
checkPropsValues(){
getValues(){
//let map = this.getPropsWithValueFromCurrentTab(false);
let propsMap = new Map();
this.addPropFromTextField(propsMap, 'space-group-number');
console.log('FilterPanel selected:', propsMap);
return propsMap;
}
/*
......@@ -179,7 +185,12 @@ class FilterPanel {
*/
addPropsFromTextFields(propsMap,propsArray, reset){
addPropFromTextField(propsMap, prop, reset = false){
let field = this.element.querySelector('.'+prop+'-field');
if (field.value !== '') propsMap.set(prop, [field.value]);
}
addPropsFromTextFields(propsMap,propsArray, reset = false){
propsArray.forEach(propName => {
let field = this.element.querySelector('.'+propName+'-field');
if (field.value !== ''){
......
......@@ -121,11 +121,11 @@ class MaterialList {
this.searchJson = searchJson;
this.page = 1;
this._search1();
this._search();
}
_search1(){ /**************** ES queries!!!!!*/
_search(){ /**************** ES queries!!!!!*/
/*
let postQuery= `
......@@ -150,14 +150,14 @@ class MaterialList {
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', postQuery, e => {
let oReq = util.serverReqPOST('http://enc-staging-nomad.esc.rzg.mpg.de/v1.0/esmaterials?page='+this.page, postQuery, e => {
let data= JSON.parse(e.target.response);
console.log('GETTING: ', data);
/*
if (e.target.status === 200){
this.total_results= data.total_results;
this.pagesNum= (data.pages === null ? 1 : data.pages.pages);
let matData= data.results;
this.total_results = data.total_results;
this.pagesNum = Math.ceil(data.total_results/10);//0;//(data.pages === null ? 1 : data.pages.pages);
let matData = data.results;
if (this.total_results === 1){
util.setBrowserHashPath('material',+matData[0].id);
......@@ -173,14 +173,15 @@ class MaterialList {
this.setData([]);
}
this._updateUI();
*/
this.resultsContainer.style.visibility = 'visible';
LoadingPopup.hide();
});
}
/*
_search(){
this.searchJson.search_by.page = this.page;
......@@ -197,7 +198,7 @@ class MaterialList {
this.pagesNum= (data.pages === null ? 1 : data.pages.pages);
let matData= data.results;
if (/*matData.length === 1 && */this.total_results === 1){
if (this.total_results === 1){
util.setBrowserHashPath('material',+matData[0].id);
util.searchResults = false;
}else{
......@@ -226,7 +227,7 @@ class MaterialList {
});
}
*/
setData(data){
//this.formula= formula;
......
......@@ -185,6 +185,7 @@ class NewSearchMod {
this.searchQuery = [];
this.queryTypes = []; //**** Types associated to query elements
// Types: element (E), formula (F), symbol (S) and prop names
this.searchFilters = [];
this._events();
}
......@@ -204,21 +205,25 @@ class NewSearchMod {
let elements = [];
this.searchQuery.forEach( (item, i) => {
if (this.queryTypes[i] === 'F'){
queryObj.query.bool.filter.push(getFormulaESMatch(item));
}else if (this.queryTypes[i] === 'MN'){
queryObj.query.bool.filter.push(getMatNameESMatch(item));
}
else if (this.queryTypes[i] === 'E') elements.push(item);
else if (this.queryTypes[i] !== 'S'){ // property
}
//else if (this.queryTypes[i] !== 'S'){ // property }
});
if (elements.length > 0) // If there are elements (there is no formula or material name)
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.materialList.setSearch(queryObj);
//util.setBrowserHashPath('search','results');
......@@ -367,6 +372,20 @@ class NewSearchMod {
}
});
}
_addPropertiesInSearchQuery(propsMap){
let filter = null;
propsMap.forEach((values/*Array*/, propName) => {
filter = {
"match": { "space_group_number": values[0] }
};
console.log('_addPropertiesInSearchQuery', filter);
});
return filter;
}
......@@ -416,9 +435,9 @@ class NewSearchMod {
return true;
}
/*
addPropertiesInSearchQuery(propsMap){
propsMap.forEach((values/*Array*/, propName) => {
propsMap.forEach((values, propName) => {
let i = this.queryTypes.indexOf(propName);
if (i < 0)
this.addTagInSearchQuery(values.join(' | '), propName);
......@@ -433,7 +452,7 @@ class NewSearchMod {
//this._showSearchBox();
}
});
}
}*/
removeElementORFormulaInSearchQuery(element){
......@@ -491,7 +510,7 @@ class NewSearchMod {
html+= getTagHtml(this.searchQuery[i], ( type === 'F' ? true : false));
}
console.log('this.updateSearchQuery: ', this.searchQuery ,this.queryTypes);
this.searchQueryBox.innerHTML= html;
this.searchQueryBox.innerHTML = html;
}
///********* DELETE?
......
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