Skip to content

Commit

Permalink
chore: Save config in config file (#116)
Browse files Browse the repository at this point in the history
  • Loading branch information
maicol07 committed Mar 6, 2024
1 parent d88e484 commit 8abd28d
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 29 deletions.
39 changes: 39 additions & 0 deletions api/api/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"available_facets": [
"txt_knowsAbout",
"txt_knowsLanguage",
"txt_nationality",
"txt_jobTitle",
"txt_contributor",
"txt_keywords",
"txt_memberOf",
"txt_parentOrganization",
"id_provider",
"id_includedInDataCatalog"
],
"facet_intervals_numeric": ["[*,1800)","[1800,1900)","[1900,1950)"],
"facet_fields": {
"Spatial": [ "txt_keywords", "txt_provider", "txt_variableMeasured", "type"],
"Person": [ "txt_memberOf", "txt_knowsLanguage", "txt_jobTitle", "txt_knowsAbout", "txt_affiliation", "txt_provider"],
"Organization": [ "txt_memberOf", "txt_provider"],
"Dataset": [ "txt_keywords", "txt_provider", "txt_variableMeasured"],
"CreativeWork": ["txt_keywords", "txt_provider", "txt_contributor"],
"Course": ["txt_keywords", "txt_provider", "txt_author", "txt_educationalCredentialAwarded"],
"Vehicle": ["txt_keywords", "txt_provider", "txt_vehicleSpecialUsage"],
"ResearchProject": [ "txt_keywords", "txt_provider", "txt_areaServed"]
},
"facet_intervals": {
"Dataset": [ "n_startYear", "n_endYear"],
"Course": [ "n_startYear", "n_endYear"],
"Spatial": [ "n_startYear", "n_endYear"]
},
"geojson": ["id", "geom_length"],
"geojson_rows": 1000,
"default_geometry": "[-90,-180 TO 90,180]",
"server_cors_allow_origins": ["*"],
"default_facet_fields": ["txt_knowsAbout", "name", "txt_knowsLanguage", "txt_nationality", "txt_jobTitle",
"txt_contributor", "txt_keywords", "txt_memberOf", "txt_parentOrganization", "id_provider",
"has_geom",
"id_includedInDataCatalog", "id_identifier", "id", "keys", "type"
]
}
40 changes: 16 additions & 24 deletions api/api/main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import json
import os
from pathlib import Path

import requests
import re

Expand All @@ -19,43 +21,33 @@

SOLR_URL = os.path.join(os.environ.get('SOLR_URL', 'http://solr'), 'select')

AVAILABLE_FACETS = ['txt_knowsAbout', 'txt_knowsLanguage', 'txt_nationality', 'txt_jobTitle', 'txt_contributor',
'txt_keywords',
'txt_memberOf', 'txt_parentOrganization', 'id_provider', 'id_includedInDataCatalog']
with open(str(Path(__file__).resolve().parent) + '/config.json') as f:
config_json = f.read()

config = json.loads(config_json)

AVAILABLE_FACETS = config.get('available_facets', [])

facet_intervals = ["[*,1800)","[1800,1900)","[1900,1950)"]
facet_intervals = config.get('facet_intervals_numeric', [])
facet_intervals.extend("[%d,%d)" %(x,x+10) for x in range(1950,2010,10))
facet_intervals.extend("[%d,%d)" %(x,x+2) for x in range(2010,2030,2))


FACET_FIELDS = {
'Spatial': [ 'txt_keywords', 'txt_provider', 'txt_variableMeasured', 'type'],
'Person': [ 'txt_memberOf', 'txt_knowsLanguage', 'txt_jobTitle', 'txt_knowsAbout', 'txt_affiliation', 'txt_provider'],
'Organization': [ 'txt_memberOf', 'txt_provider'],
'Dataset': [ 'txt_keywords', 'txt_provider', 'txt_variableMeasured'],
'CreativeWork': ['txt_keywords', 'txt_provider', 'txt_contributor'],
'Course': ['txt_keywords', 'txt_provider', 'txt_author', 'txt_educationalCredentialAwarded'],
'Vehicle': ['txt_keywords', 'txt_provider', 'txt_vehicleSpecialUsage'],
'ResearchProject': [ 'txt_keywords', 'txt_provider', 'txt_areaServed'],
}

FACET_INTERVALS = {
'Dataset': [ 'n_startYear', 'n_endYear'],
'Course': [ 'n_startYear', 'n_endYear'],
'Spatial': [ 'n_startYear', 'n_endYear'],
}
FACET_FIELDS = config.get('facet_fields', {})

FACET_INTERVALS = config.get('facet_intervals', {})

GEOJSON_FIELDS = { 'id', 'geom_length' }
GEOJSON_ROWS = 10000
DEFAULT_GEOMETRY = "[-90,-180 TO 90,180]"
GEOJSON_FIELDS = config.get('geojson_fields', ['id', 'geom_length'])
GEOJSON_ROWS = config.get('geojson_rows', 1000)
DEFAULT_GEOMETRY = config.get('default_geometry')
COMBINED_TYPES = {
'Experts': ['Person', 'Organization']
}
app = FastAPI()

app.add_middleware(
CORSMiddleware,
allow_origins=['*']
allow_origins=config.get('server_cors_allow_origins', []),
)

@app.get("/search")
Expand Down
14 changes: 9 additions & 5 deletions api/api/util/solr_query_builder.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
DEFAULT_FACET_FIELDS = ['txt_knowsAbout', 'name', 'txt_knowsLanguage', 'txt_nationality', 'txt_jobTitle',
'txt_contributor', 'txt_keywords', 'txt_memberOf', 'txt_parentOrganization', 'id_provider',
'has_geom',
'id_includedInDataCatalog', 'id_identifier', 'id', 'keys', 'type'
]
import json
from pathlib import Path

with open(str(Path(__file__).resolve().parent.parent) + '/config.json') as f:
config_json = f.read()

config = json.loads(config_json)

DEFAULT_FACET_FIELDS = config.get('default_facet_fields', {})


class SolrQueryBuilder:
Expand Down

0 comments on commit 8abd28d

Please sign in to comment.