Commit f7ff10fe authored by Iker Hurtado's avatar Iker Hurtado
Browse files

Optimade query generation from the UI search query and the property fields

parent 56fcf30e
Pipeline #90240 skipped with stage
......@@ -43,7 +43,7 @@ class FilterPanel {
let structureGroupBox = this.createPropsGroupBox('Structure')
this.element.append(structureGroupBox);
const systemTypeField = new CheckboxesField('System type', 'system-type', [
const systemTypeField = new CheckboxesField('System type', 'material_type', [
{value: 'bulk', text: 'Bulk'},
{value: '2D', text: '2D'},
{value: '1D', text: '1D'}
......@@ -51,7 +51,7 @@ class FilterPanel {
this.fields.push(systemTypeField)
structureGroupBox.append(systemTypeField.element); /// By looping*****
const crystalSystemField = new CheckboxesField('Crystal system', 'crystal-system', [
const crystalSystemField = new CheckboxesField('Crystal system', 'crystal_system', [
{value: 'cubic', text: 'Cubic'},
{value: 'hexagonal', text: 'Hexagonal'},
{value: 'trigonal', text: 'Trigonal'},
......@@ -68,7 +68,7 @@ class FilterPanel {
this.fields.push(spaceGroupField)
structureGroupBox.append(spaceGroupField.element);
const structureTypeField = new AutocompleteField('Structure type', "structure-type", 'structure_type');
const structureTypeField = new AutocompleteField('Structure type', 'structure_type');
this.fields.push(structureTypeField)
structureGroupBox.append(structureTypeField.element);
......@@ -82,7 +82,7 @@ class FilterPanel {
propertiesGroupBox.append(massDensityField.element);
const boolValueFields = new CheckboxesField('Results containing...', undefined, [
{value: 'Band structure', text: 'Band structure', id: 'has-band-structure'},
{value: 'Band structure', text: 'Band structure', id: 'has_band_structure'},
{value: 'DOS', text: 'DOS', id: 'has-dos'},
{value: 'Thermal properties', text: 'Thermal properties', id: 'has-thermal-properties'},
]);
......@@ -206,7 +206,7 @@ class CheckboxesField{
this.checkboxes.forEach( checkbox => {
if (checkbox.checked) {
let s = checkbox.className;
values.push({fieldId: s.substring(0, s.indexOf('-field')), value: true});
values.push({fieldId: s.substring(0, s.indexOf('-field')), value: [true]});
}
});
return values;
......@@ -249,8 +249,8 @@ class SpaceGroupField{
getValues(){
let type = this.select.options[this.select.selectedIndex].value;
let propName = (type === 'by-number' ? 'space-group-number'
: 'space-group-international-short-symbol');
let propName = (type === 'by-number' ? 'space_group_number'
: 'space_group_international_short_symbol');
let value = this.input.value;
return ( value.trim() === '' ? null : { fieldId: propName, value: [value] } );
......@@ -268,7 +268,7 @@ class SpaceGroupField{
class AutocompleteField{
constructor(name, id, apiId){
constructor(name, id){
this.fieldId = id
this.element = document.createElement('div');
this.element.className = 'filter-quantity-box';
......@@ -281,8 +281,8 @@ class AutocompleteField{
this.autocomplete.element.classList.add('textfield-filter');
this.element.append(this.autocomplete.element)
let r1 = util.serverReq(util.getSuggestionURL(apiId), (e) => {
let names = JSON.parse(r1.response)[apiId];
let r1 = util.serverReq(util.getSuggestionURL(this.fieldId), (e) => {
let names = JSON.parse(r1.response)[this.fieldId];
this.autocomplete.autocomplete(names);
});
}
......
......@@ -340,29 +340,32 @@ class NewSearchMod {
sendQuery(){
//**** The optimade query must be formed from the search box and the properties selected
let optimadeQuery = this.searchBox.getOptimadeQuery();// + this.filterPanel.getValues()
console.log('sendQuery optimadeQuery: ', optimadeQuery);
this.materialList.initSearch(optimadeQuery);
}
getOptimadeQueryFromSearchQuery(searchQuery, queryTypes){
let optimadeQuery = this.searchBox.getOptimadeQuery(true);//
let optimadeQueryForProps = getOptimadeQueryFromProps(this.filterPanel.getValues());
if (optimadeQuery !== ''){ // if there are items in the serach box
optimadeQuery += (optimadeQueryForProps.length > 0 ? ' AND '+optimadeQueryForProps : '');
console.log('sendQuery optimadeQuery: ', optimadeQuery, optimadeQueryForProps );
this.materialList.initSearch(optimadeQuery);
}
let optimadeQuery = '';
searchQuery.forEach( (item, i) => {
if (queryTypes[i] === 'E'){
optimadeQuery += ' elements HAS ONLY "'+searchQuery[i]+'"'
function getOptimadeQueryFromProps(propsValuesMap){
let query = '';
propsValuesMap.forEach( (values, prop) => {
let subquery = '';
values.forEach( v => { // values should be and array, sometimes with just one value
let val = ( v === true ? 'TRUE' : '"'+v+'"')
subquery += (subquery === '' ? '' : ' OR ')+prop+'='+val;
})
query += (query === '' ? '' : ' AND ')+`(${subquery})`
})
return query
}
}else if ( queryTypes[i] === 'F' ){
}else if ( queryTypes[i] === 'S' ){
optimadeQuery += ' '+searchQuery[i]+''
}
});
console.log('optimadeQuery: ', optimadeQuery)
return optimadeQuery;
}
_getESQueryFromSearchQuery(searchQuery, queryTypes){
let formulas = [];
let parFormulas = [];
......
......@@ -85,11 +85,36 @@ class SearchBox{
}
getOptimadeQuery(){
getOptimadeQuery(allowOtherElements){
if (this.searchQuery.length === 0 ||
!isQueryWellFormed(this.searchQuery)) return '';
else return 'elements HAS ALL "Si", "Cl"';
//else if () // MATERIAL CASE
else{
let optimadeQuery = '';
//let otherElementsFlag = ( allowOtherElements ? '' : 'ONLY ' )
// Inclusive search
this.searchQuery.forEach( (item, i) => {
if (this.queryTypes[i] === 'E'){
optimadeQuery += ` elements HAS "${this.searchQuery[i]}"`
}else if ( this.queryTypes[i] === 'F' ){
optimadeQuery += ` formula="${this.searchQuery[i]}"`
}else if ( this.queryTypes[i] === 'S' ){
optimadeQuery += ' '+this.searchQuery[i]+''
}
});
console.log('optimadeQuery: ', optimadeQuery)
//return 'elements HAS ONLY "F"';
return optimadeQuery;//'elements HAS ALL "Si", "Cl"';
}
function isQueryWellFormed(searchQuery){
const openingParIndex = searchQuery.indexOf('(')
......@@ -218,6 +243,7 @@ class SearchBox{
setSearchQueryChangeListener(listener) {
this.searchQueryChangeListener = listener;
}
}
......
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