Skip to content

Commit

Permalink
add base search filter interface, re #4771
Browse files Browse the repository at this point in the history
  • Loading branch information
apeters committed May 6, 2019
1 parent 8703a0b commit dff45b8
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 24 deletions.
33 changes: 33 additions & 0 deletions arches/app/search/components/base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@

details = {
"searchcomponentid": "", # leave blank for the system to generate a uuid
"name": "", # the name that shows up in the UI
"icon": "", # the icon class to use
"modulename": "base.py", # the name of this file
"classname": "BaseSearchFilter", # the classname below",
"type": "filter", # 'filter' if you want the component to show up dynamically
"componentpath": "views/components/search/...", # path to ko component
"componentname": "advanced-search", # lowercase unique name
"config": {}, # config values to pass to the component
"sortorder": "0", # order in which to display dynamically added filters to the UI
"enabled": True # True to enable in the system
}


class BaseSearchFilter():

def append_dsl(self, querysting_params, query_dsl, permitted_nodegroups, include_provisional):
"""
used to append ES query dsl to the search request
"""

pass

def view_data(self):
"""
data that the view should gather to pass to the front end
"""

pass
3 changes: 2 additions & 1 deletion arches/app/search/components/map_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from arches.app.models.system_settings import settings
from arches.app.utils.betterJSONSerializer import JSONSerializer, JSONDeserializer
from arches.app.search.elasticsearch_dsl_builder import Bool, Nested, Terms, GeoShape
from arches.app.search.components.base import BaseSearchFilter

details = {
"searchcomponentid": "",
Expand All @@ -18,7 +19,7 @@
}


class MapFilter():
class MapFilter(BaseSearchFilter):

def append_dsl(self, querysting_params, query_dsl, permitted_nodegroups, include_provisional):
search_query = Bool()
Expand Down
3 changes: 2 additions & 1 deletion arches/app/search/components/term_filter.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from arches.app.models.concept import Concept
from arches.app.utils.betterJSONSerializer import JSONDeserializer
from arches.app.search.elasticsearch_dsl_builder import Bool, Match, Nested, Terms
from arches.app.search.components.base import BaseSearchFilter

details = {
"searchcomponentid": "",
Expand All @@ -17,7 +18,7 @@
}


class TermFilter():
class TermFilter(BaseSearchFilter):

def append_dsl(self, querysting_params, query_dsl, permitted_nodegroups, include_provisional):
search_query = Bool()
Expand Down
3 changes: 2 additions & 1 deletion arches/app/search/components/time_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from arches.app.utils.date_utils import ExtendedDateFormat
from arches.app.utils.betterJSONSerializer import JSONDeserializer
from arches.app.search.elasticsearch_dsl_builder import Bool, Nested, Term, Terms, Range
from arches.app.search.components.base import BaseSearchFilter

details = {
"searchcomponentid": "",
Expand All @@ -18,7 +19,7 @@
}


class TimeFilter():
class TimeFilter(BaseSearchFilter):

def append_dsl(self, querysting_params, query_dsl, permitted_nodegroups, include_provisional):
search_query = Bool()
Expand Down
44 changes: 23 additions & 21 deletions arches/management/commands/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,28 +58,30 @@ def register(self, source):
"""

dt_source = imp.load_source('', source)
details = dt_source.details

try:
uuid.UUID(details['searchcomponentid'])
except:
details['searchcomponentid'] = unicode(uuid.uuid4())
print "Registering the search component, %s, with componentid: %s" % (details['name'], details['searchcomponentid'])

instance = models.SearchComponent(
searchcomponentid=details['searchcomponentid'],
name=details['name'],
icon=details['icon'],
modulename=os.path.basename(source),
classname=details['classname'],
type=details['type'],
componentpath=details['componentpath'],
componentname=details['componentname'],
config=details['config'],
sortorder=details['sortorder']
)

instance.save()
if getattr(dt_source, 'details', None):
details = dt_source.details

try:
uuid.UUID(details['searchcomponentid'])
except:
details['searchcomponentid'] = unicode(uuid.uuid4())
print "Registering the search component, %s, with componentid: %s" % (details['name'], details['searchcomponentid'])

instance = models.SearchComponent(
searchcomponentid=details['searchcomponentid'],
name=details['name'],
icon=details['icon'],
modulename=os.path.basename(source),
classname=details['classname'],
type=details['type'],
componentpath=details['componentpath'],
componentname=details['componentname'],
config=details['config'],
sortorder=details['sortorder']
)

instance.save()

def update(self, source):
"""
Expand Down

0 comments on commit dff45b8

Please sign in to comment.