Commit 6050e99d authored by Iker Hurtado's avatar Iker Hurtado
Browse files

Simple Elastic Search queries integration

parent fea1ea71
This diff is collapsed.
......@@ -125,12 +125,14 @@ class Breadcrumb {
this.overviewSel.style.display = 'none';
this.detailsSel.style.display = 'none';
/*
if (param === 'results'){
this.resultsSel.style.display = 'inline';
this.resultsSel.querySelector('span').style.fontWeight = 'bold';
this.element.style.visibility = 'visible';
}else
this.element.style.visibility = 'hidden';
}else this.element.style.visibility = 'hidden';
*/
this.element.style.visibility = 'hidden';
}else if (appModule === 'material'){
this.element.style.visibility = 'visible';
......@@ -202,8 +204,7 @@ PubSub.subscribe('show-search', search => {
searchMod.showSearchPage();
LoadingPopup.hide(); // In case it comes from the result page
}else if (search === 'results')
searchMod.showSearchResults();
}//else if (search === 'results') searchMod.showSearchResults();
showModuleDOM(searchMod.element);
......
......@@ -125,25 +125,26 @@ class MaterialList {
}
_search1(){ /**************** ES queries!!!!!!!!!!!!!!!!!!!111111
_search1(){ /**************** ES queries!!!!!*/
/*
let postQuery= `
{
"query" : {
"constant_score" : {
"bool" : {
"filter" : {
"bool" : {
"must": [
{"match" : { "atom_labels": "Te" }},
{"match" : { "atom_labels": "Si" }}
]
}
"match" : { "formula_reduced": "Be3Li5" }
}
}
}
} `;
*/
let postQuery = JSON.stringify(this.searchJson);
console.log('SENDING: ', postQuery);
......
......@@ -154,7 +154,7 @@ class NewSearchMod {
this.materialNameBox = new MaterialNameBox();
this.materialNameBox.setAddMaterialNameListener( name => {
if (name.trim() !== ''){
this.addTagInSearchQuery(name, 'material-name');
this.addTagInSearchQuery(name, 'MN');
this.addElementButton.disabled = true;
this.addFormulaButton.disabled = true;
this.formulaBox.disable(true);
......@@ -194,6 +194,40 @@ class NewSearchMod {
// External event - Search button press
this.mainButton.addEventListener( "click", (e) => {
//console.log("this.labels: "+JSON.stringify(this.labels));
if (this.searchQuery.lenght === 0){
util.showUserMsg('No query');
}else{
let queryObj = { 'query' : { 'bool' : {} } };
//queryObj.query.bool.must = {};
queryObj.query.bool.filter = [];
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
}
});
if (elements.length > 0) // If there are elements (there is no formula or material name)
queryObj.query.bool.filter.push(getAtomsESMatch(elements));
this.materialList.setSearch(queryObj);
//util.setBrowserHashPath('search','results');
this.element.querySelector('.add-box').style.display = 'none';
}
/*
if (this.searchQuery.lenght === 0){
util.showUserMsg('No query');
}else{
......@@ -230,9 +264,39 @@ class NewSearchMod {
this.element.querySelector('.add-box').style.display = 'none';
}
*/
function getAtomsESMatch(elements){
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 {
"match": { "material_name": name }
};
}
});
this.cleanButton.addEventListener( "click", (e) => {
this.searchQuery = [];
this.queryTypes = [];
......@@ -305,6 +369,7 @@ class NewSearchMod {
}
_setTabSelectedStyles(element, value){
/*
element.style.fontWeight = (value ? 'bold' : 'normal');
......@@ -429,7 +494,7 @@ class NewSearchMod {
this.searchQueryBox.innerHTML= html;
}
///********* DELETE?
showSearchResults(){
/*
this.searchPage.style.display= 'none';
......
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