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
cd1b8e13
Commit
cd1b8e13
authored
Feb 09, 2021
by
Iker Hurtado
Browse files
Implement basic search exclusive mode for formulas
parent
3aed4032
Pipeline
#93092
skipped with stage
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
client/conf.js
View file @
cd1b8e13
window
.
nomadEnv
=
{
//apiRoot: "https://nomad-lab.eu/dev/nomad/enc-search/api/encyclopedia/",
apiRoot
:
"
https://nomad-lab.eu/dev/rae/enc-search/api/encyclopedia/
"
,
//"https://nomad-lab.eu/prod/rae/beta/api/encyclopedia/",
//apiRoot: "https://nomad-lab.eu/prod/rae/api/encyclopedia/",
apiRoot
:
"
http://localhost:8000/fairdi/nomad/latest/api/encyclopedia/
"
,
//
apiRoot: "http://localhost:8000/fairdi/nomad/latest/api/encyclopedia/",
keycloakBase
:
'
https://nomad-lab.eu/fairdi/keycloak/auth/
'
,
keycloakRealm
:
'
fairdi_nomad_test
'
,
keycloakClientId
:
'
nomad_gui_dev
'
...
...
client/src/search-mod/NewSearchMod.js
View file @
cd1b8e13
...
...
@@ -69,7 +69,7 @@ class NewSearchMod {
<input type="checkbox" id="multiples-of-formula" value="">
Include multiples of formula
<br>
<input type="checkbox" id="allow-other-elements" value="">
<input type="checkbox" id="allow-other-elements" value=""
checked
>
Allow other elements
<br>
...
...
client/src/search-mod/SearchBox.view.js
View file @
cd1b8e13
...
...
@@ -152,12 +152,13 @@ class SearchBox{
subquery
.
forEach
(
(
item
,
i
)
=>
{
// For every item in the subquery
if
(
item
.
charAt
(
0
)
===
'
(
'
){
// console.log('OPPPPP', optimadeSubqueries[+item.charAt(1)])
optimadeQuery
+=
`(
${
optimadeSubqueries
[
+
item
.
charAt
(
1
)]}
)`
}
else
if
(
isElement
(
item
)
){
optimadeQuery
+=
`elements HAS "
${
item
}
"`
optimadeQuery
+=
`(
${
optimadeSubqueries
[
+
item
.
charAt
(
1
)]}
)`
;
}
else
if
(
item
===
'
AND
'
||
item
===
'
NOT
'
){
optimadeQuery
+=
'
'
+
item
+
'
'
;
}
else
if
(
isElement
(
item
)
){
optimadeQuery
+=
`elements HAS "
${
item
}
"`
}
else
{
// Formula
let
formula
=
new
Formula
(
item
);
...
...
@@ -167,15 +168,19 @@ class SearchBox{
}
else
{
// Exclusive search. For now only one formula or elements subqueries supported. Operator NOT doesn't make sense here
// if (subquery.length === 1 && !isElement(subquery[0])){ // Only one formula
if
(
!
isElement
(
subquery
[
0
])){
// formula(s)
//optimadeQuery += `formula="${subquery[0]}"`;
let
formula
=
new
Formula
(
subquery
[
0
]);
optimadeQuery
+=
formula
.
getOptimadeSubquery
(
allowOtherElements
);
const
items
=
[];
let
areElements
=
false
;
subquery
.
forEach
(
(
item
)
=>
{
if
(
isElement
(
item
))
areElements
=
true
;
if
(
item
!==
'
AND
'
&&
item
!==
'
NOT
'
){
// item = element or formula
if
(
areElements
)
items
.
push
(
`"
${
item
}
"`
);
else
// formula
items
.
push
(
new
Formula
(
item
).
getFragments
());
}
});
console
.
log
(
'
Exclusive search:
'
,
items
)
optimadeQuery
+=
(
areElements
?
'
elements
'
:
'
formula
'
)
+
'
HAS ONLY
'
+
items
.
join
(
'
,
'
);
}
else
{
// Several items, they all should be elements
optimadeQuery
+=
getOptimadeExclusiveANDSubquery
(
subquery
);
}
}
});
...
...
@@ -187,19 +192,26 @@ class SearchBox{
return
util
.
ELEMENTS
.
includes
(
item
)
}
/* NOt used anymore??
function getOptimadeElementExclusiveANDSubquery(subquery){
const elements = []
subquery.forEach( (item) => {
if (isElement(item)) elements.push(`"${item}"`);
});
return 'elements HAS ONLY '+elements.join(', ');
}
function
getOptimadeExclusiveANDSubquery
(
subquery
){
// this subquery is supposed to be form only for elements and ANDs separating
let
optSubquery
=
'
elements HAS ONLY
'
;
function getOptimade
Formula
ExclusiveANDSubquery(subquery){
const fragments = []
;
subquery.forEach( (item) => {
if
(
isElement
(
item
)
){
//
item !== 'AND'){
//
check if element isntead ?
optSubquery
+=
`"
${
item
}
",`
;
if (
!
isElement(item)
&&
item !== 'AND'
&& item !== 'NOT'
){//
Is formula
fragments.push(new Formula(item).getFragments())
;
}
});
optSubquery
=
optSubquery
.
substring
(
0
,
optSubquery
.
length
-
1
);
return
optSubquery
;
return 'formula HAS ONLY '+fragments.join(', ');
}
*/
function
isQueryWellFormed
(
searchQuery
){
const
openingParIndex
=
searchQuery
.
indexOf
(
'
(
'
)
...
...
@@ -423,6 +435,15 @@ class Formula{
return
'
formula HAS
'
+
(
allowOtherElements
?
'
ALL
'
:
'
ONLY
'
)
+
fragments
.
join
(
'
,
'
)
}
getFragments
()
{
const
fragments
=
[]
this
.
formulaMap
.
forEach
(
(
number
,
element
)
=>
{
const
fragment
=
'
"
'
+
element
+
(
number
===
1
?
''
:
+
number
)
+
'
"
'
;
fragments
.
push
(
fragment
);
})
return
fragments
;
}
/*
getReducedFormula(getTokens = true){
...
...
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