Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
nomad-lab
encyclopedia-gui
Commits
f7ff10fe
Commit
f7ff10fe
authored
Dec 29, 2020
by
Iker Hurtado
Browse files
Optimade query generation from the UI search query and the property fields
parent
56fcf30e
Pipeline
#90240
skipped with stage
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
client/src/search-mod/FilterPanel.view.js
View file @
f7ff10fe
...
...
@@ -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
(
api
Id
),
(
e
)
=>
{
let
names
=
JSON
.
parse
(
r1
.
response
)[
api
Id
];
let
r1
=
util
.
serverReq
(
util
.
getSuggestionURL
(
this
.
field
Id
),
(
e
)
=>
{
let
names
=
JSON
.
parse
(
r1
.
response
)[
this
.
field
Id
];
this
.
autocomplete
.
autocomplete
(
names
);
});
}
...
...
client/src/search-mod/NewSearchMod.js
View file @
f7ff10fe
...
...
@@ -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
=
[];
...
...
client/src/search-mod/SearchBox.view.js
View file @
f7ff10fe
...
...
@@ -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
;
}
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment