Commit 009f6330 authored by Markus Scheidgen's avatar Markus Scheidgen
Browse files

Added optimade to search GUI. #219

parent e8971ac3
Pipeline #61735 passed with stages
in 21 minutes and 40 seconds
......@@ -109,7 +109,8 @@ class DomainProviderBase extends React.Component {
pid: {},
mainfile: {},
calc_hash: {},
formula: {}
formula: {},
optimade: {}
},
/**
* An dict where each object represents a column. Possible keys are label, render.
......
......@@ -49,6 +49,8 @@ class ErrorSnacksUnstyled extends React.Component {
errorStr = 'You are trying to access information that does not exist. Please try again and let us know, if this error keeps happening.'
} else if (error.name === 'VersionMismatch') {
errorStr = 'There is a new GUI version available. Please press "shift" and reload the page.'
} else if (error.message.startsWith('could not parse optimade')) {
errorStr = 'The given OPTiMaDe query can not be parsed.'
} else if (error.message) {
errorStr = `Unexpected error: "${error.message}". Please try again and let us know, if this error keeps happening.`
}
......
......@@ -200,7 +200,7 @@ class SearchBar extends React.Component {
let key, value
if (chip.includes('=')) {
const parts = chip.split('=')
const parts = chip.split(/=(.+)/)
key = parts[0]
value = parts[1]
} else {
......
......@@ -24,6 +24,7 @@ from elasticsearch.exceptions import NotFoundError
from nomad import search, utils, datamodel
from nomad.app.utils import rfc3339DateTime
from nomad.app.optimade import filterparser
from .api import api
from .auth import login_if_available
......@@ -161,11 +162,20 @@ def add_query(search_request: search.SearchRequest):
except Exception:
abort(400, message='bad datetime format')
# optimade
try:
optimade = request.args.get('optimade', None)
if optimade is not None:
q = filterparser.parse_filter(optimade)
search_request.query(q)
except filterparser.FilterException:
abort(400, message='could not parse optimade query')
# search parameter
search_request.search_parameters(**{
key: request.args.getlist(key) if search.quantities[key] else request.args.get(key)
for key in request.args.keys()
if key in search.quantities})
if key not in ['optimade'] and key in search.quantities})
@ns.route('/')
......
......@@ -239,7 +239,7 @@ Domain(
'Number of atoms in the simulated system',
elastic_mapping=Integer()),
optimade=DomainQuantity(
'Data for the optimade API',
'Search based on optimade\'s filter query language',
elastic_mapping=Object(optimade.ESOptimadeEntry),
elastic_value=lambda entry: optimade.elastic_obj(entry, optimade.ESOptimadeEntry)
)),
......
......@@ -987,6 +987,14 @@ class TestRepo():
assert data['pagination']['total'] == 1
assert data['results'][0]['raw_id'] == 'C61A2F88-A0EA-4F0B-AA47-A715868B2E26'
def test_optimade(self, api, non_empty_processed, test_user_auth):
rv = api.get(
'/repo/?%s' % urlencode(dict(owner='all', optimade='nelements >= 1')),
headers=test_user_auth)
assert rv.status_code == 200
data = json.loads(rv.data)
assert data['pagination']['total'] > 0
class TestRaw(UploadFilesBasedTests):
......
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