本文整理汇总了Python中arches.app.search.search_engine_factory.SearchEngineFactory.search方法的典型用法代码示例。如果您正苦于以下问题:Python SearchEngineFactory.search方法的具体用法?Python SearchEngineFactory.search怎么用?Python SearchEngineFactory.search使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类arches.app.search.search_engine_factory.SearchEngineFactory
的用法示例。
在下文中一共展示了SearchEngineFactory.search方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_scheme_id
# 需要导入模块: from arches.app.search.search_engine_factory import SearchEngineFactory [as 别名]
# 或者: from arches.app.search.search_engine_factory.SearchEngineFactory import search [as 别名]
def get_scheme_id(self):
se = SearchEngineFactory().create()
result = se.search(index='concept_labels', id=self.id)
if result['found']:
return Concept(result['_type'])
else:
return None
示例2: get_related_resources
# 需要导入模块: from arches.app.search.search_engine_factory import SearchEngineFactory [as 别名]
# 或者: from arches.app.search.search_engine_factory.SearchEngineFactory import search [as 别名]
def get_related_resources(self, lang='en-US', limit=1000, start=0):
"""
Returns an object that lists the related resources, the relationship types, and a reference to the current resource
"""
ret = {
'resource_instance': self,
'resource_relationships': [],
'related_resources': []
}
se = SearchEngineFactory().create()
query = Query(se, limit=limit, start=start)
bool_filter = Bool()
bool_filter.should(Terms(field='resourceinstanceidfrom', terms=self.resourceinstanceid))
bool_filter.should(Terms(field='resourceinstanceidto', terms=self.resourceinstanceid))
query.add_query(bool_filter)
resource_relations = query.search(index='resource_relations', doc_type='all')
ret['total'] = resource_relations['hits']['total']
instanceids = set()
for relation in resource_relations['hits']['hits']:
relation['_source']['preflabel'] = get_preflabel_from_valueid(relation['_source']['relationshiptype'], lang)
ret['resource_relationships'].append(relation['_source'])
instanceids.add(relation['_source']['resourceinstanceidto'])
instanceids.add(relation['_source']['resourceinstanceidfrom'])
if len(instanceids) > 0:
instanceids.remove(str(self.resourceinstanceid))
related_resources = se.search(index='resource', doc_type='_all', id=list(instanceids))
if related_resources:
for resource in related_resources['docs']:
ret['related_resources'].append(resource['_source'])
return ret
示例3: get_preflabel_from_valueid
# 需要导入模块: from arches.app.search.search_engine_factory import SearchEngineFactory [as 别名]
# 或者: from arches.app.search.search_engine_factory.SearchEngineFactory import search [as 别名]
def get_preflabel_from_valueid(valueid, lang):
se = SearchEngineFactory().create()
concept_label = se.search(index='concept_labels', id=valueid)
if concept_label['found']:
# print "ConceptID from ValueID: %s" % get_concept_label_from_valueid(valueid)
return get_preflabel_from_conceptid(get_concept_label_from_valueid(valueid)['conceptid'], lang)
示例4: get_scheme_id
# 需要导入模块: from arches.app.search.search_engine_factory import SearchEngineFactory [as 别名]
# 或者: from arches.app.search.search_engine_factory.SearchEngineFactory import search [as 别名]
def get_scheme_id(self):
se = SearchEngineFactory().create()
result = se.search(index='strings', doc_type='concept', id=self.id)
if result['found']:
return Concept(result['top_concept'])
else:
return None
示例5: get_related_resources
# 需要导入模块: from arches.app.search.search_engine_factory import SearchEngineFactory [as 别名]
# 或者: from arches.app.search.search_engine_factory.SearchEngineFactory import search [as 别名]
def get_related_resources(resourceid, lang, limit=1000, start=0):
ret = {
'resource_relationships': [],
'related_resources': []
}
se = SearchEngineFactory().create()
query = Query(se, limit=limit, start=start)
query.add_filter(Terms(field='entityid1', terms=resourceid).dsl, operator='or')
query.add_filter(Terms(field='entityid2', terms=resourceid).dsl, operator='or')
resource_relations = query.search(index='resource_relations', doc_type='all')
ret['total'] = resource_relations['hits']['total']
entityids = set()
for relation in resource_relations['hits']['hits']:
relation['_source']['preflabel'] = get_preflabel_from_valueid(relation['_source']['relationshiptype'], lang)
ret['resource_relationships'].append(relation['_source'])
entityids.add(relation['_source']['entityid1'])
entityids.add(relation['_source']['entityid2'])
if len(entityids) > 0:
entityids.remove(resourceid)
related_resources = se.search(index='entity', doc_type='_all', id=list(entityids))
if related_resources:
for resource in related_resources['docs']:
ret['related_resources'].append(resource['_source'])
return ret
示例6: get_resource_names
# 需要导入模块: from arches.app.search.search_engine_factory import SearchEngineFactory [as 别名]
# 或者: from arches.app.search.search_engine_factory.SearchEngineFactory import search [as 别名]
def get_resource_names(self, nodevalue):
resource_names = set([])
es = Elasticsearch()
se = SearchEngineFactory().create()
id_list = self.get_id_list(nodevalue)
for resourceid in id_list:
print resourceid
resource_document = se.search(index='resource', doc_type='_all', id=resourceid)
resource_names.add(resource_document['_source']['displayname'])
return resource_names
示例7: get_related_resources
# 需要导入模块: from arches.app.search.search_engine_factory import SearchEngineFactory [as 别名]
# 或者: from arches.app.search.search_engine_factory.SearchEngineFactory import search [as 别名]
def get_related_resources(resourceid, lang, limit=1000, start=0, allowedtypes=[], is_anon=False):
ret = {
'resource_relationships': [],
'related_resources': []
}
se = SearchEngineFactory().create()
query = Query(se, limit=limit, start=start)
query.add_filter(Terms(field='entityid1', terms=resourceid).dsl, operator='or')
query.add_filter(Terms(field='entityid2', terms=resourceid).dsl, operator='or')
resource_relations = query.search(index='resource_relations', doc_type="all")
entityids = set()
for relation in resource_relations['hits']['hits']:
relation['_source']['preflabel'] = get_preflabel_from_valueid(relation['_source']['relationshiptype'], lang)
ret['resource_relationships'].append(relation['_source'])
entityids.add(relation['_source']['entityid1'])
entityids.add(relation['_source']['entityid2'])
if len(entityids) > 0:
entityids.remove(resourceid)
# can't figure why passing allowed types to doc_type param doesn't work,
# so filter is carried out later
related_resources = se.search(index='entity', doc_type='_all', id=list(entityids))
filtered_ids = []
if related_resources:
for resource in related_resources['docs']:
if not resource['_type'] in allowedtypes:
filtered_ids.append(resource['_source']['entityid'])
continue
if is_anon:
# filter out protected resources if user is anonymous
# (this is basically a subset of the get_protected_entityids below
# they should be combined probably)
from search import get_protection_conceptids
protect_id = get_protection_conceptids(settings.PROTECTION_LEVEL_NODE)
conceptids = [d['conceptid'] for d in resource['_source']['domains']]
if protect_id in conceptids:
filtered_ids.append(resource['_source']['entityid'])
continue
ret['related_resources'].append(resource['_source'])
if len(filtered_ids) > 0:
# remove all relationships in ret that match a filtered id (this lc is yuge but I think concise)
filtered_relationships = [rel for rel in ret['resource_relationships'] if not rel['entityid1'] in filtered_ids and not rel['entityid2'] in filtered_ids]
# update ret values
ret['resource_relationships'] = filtered_relationships
ret['total'] = len(ret['resource_relationships'])
return ret
示例8: map_layers
# 需要导入模块: from arches.app.search.search_engine_factory import SearchEngineFactory [as 别名]
# 或者: from arches.app.search.search_engine_factory.SearchEngineFactory import search [as 别名]
def map_layers(request, entitytypeid='all', get_centroids=False):
data = []
geom_param = request.GET.get('geom', None)
bbox = request.GET.get('bbox', '')
limit = request.GET.get('limit', settings.MAP_LAYER_FEATURE_LIMIT)
entityids = request.GET.get('entityid', '')
geojson_collection = {
"type": "FeatureCollection",
"features": []
}
se = SearchEngineFactory().create()
query = Query(se, limit=limit)
args = { 'index': 'maplayers' }
if entitytypeid != 'all':
args['doc_type'] = entitytypeid
if entityids != '':
for entityid in entityids.split(','):
geojson_collection['features'].append(se.search(index='maplayers', id=entityid)['_source'])
return JSONResponse(geojson_collection)
data = query.search(**args)
if not data:
return JSONResponse({})
for item in data['hits']['hits']:
# Ce uporabnik ni avtenticiran, prikazemo le veljavne (to je verjetno potrebno se dodelati (mogoce da vidijo le svoje???)!!!)
if (not request.user.username != 'anonymous'):
if (item['_source']['properties']['ewstatus'] != settings.PUBLISHED_LABEL):
continue
if get_centroids:
item['_source']['geometry'] = item['_source']['properties']['centroid']
#item['_source'].pop('properties', None)
item['_source']['properties'].pop('extent', None)
item['_source']['properties'].pop('elements', None)
item['_source']['properties'].pop('entitytypeid', None)
item['_source']['properties'].pop('constructions', None)
item['_source']['properties'].pop('centroid', None)
item['_source']['properties'].pop('ewstatus', None)
item['_source']['properties'].pop('address', None)
item['_source']['properties'].pop('designations', None)
item['_source']['properties'].pop('primaryname', None)
item['_source']['properties'].pop('resource_type', None)
elif geom_param != None:
item['_source']['geometry'] = item['_source']['properties'][geom_param]
item['_source']['properties'].pop('extent', None)
item['_source']['properties'].pop(geom_param, None)
else:
item['_source']['properties'].pop('extent', None)
item['_source']['properties'].pop('centroid', None)
geojson_collection['features'].append(item['_source'])
return JSONResponse(geojson_collection)
示例9: map_layers
# 需要导入模块: from arches.app.search.search_engine_factory import SearchEngineFactory [as 别名]
# 或者: from arches.app.search.search_engine_factory.SearchEngineFactory import search [as 别名]
def map_layers(request, entitytypeid='all', get_centroids=False):
data = []
geom_param = request.GET.get('geom', None)
bbox = request.GET.get('bbox', '')
limit = request.GET.get('limit', settings.MAP_LAYER_FEATURE_LIMIT)
entityids = request.GET.get('entityid', '')
geojson_collection = {
"type": "FeatureCollection",
"features": []
}
se = SearchEngineFactory().create()
query = Query(se, limit=limit)
args = { 'index': 'maplayers' }
if entitytypeid != 'all':
args['doc_type'] = entitytypeid
if entityids != '':
for entityid in entityids.split(','):
geojson_collection['features'].append(se.search(index='maplayers', id=entityid)['_source'])
return JSONResponse(geojson_collection)
data = query.search(**args)
# if anonymous user, get list of protected entity ids to be excluded from map
protected = []
if request.user.username == 'anonymous':
protected = get_protected_entityids()
print protected
for item in data['hits']['hits']:
if item['_id'] in protected:
print "hide this one"
print json.dumps(item,indent=2)
continue
if get_centroids:
item['_source']['geometry'] = item['_source']['properties']['centroid']
item['_source'].pop('properties', None)
elif geom_param != None:
item['_source']['geometry'] = item['_source']['properties'][geom_param]
item['_source']['properties'].pop('extent', None)
item['_source']['properties'].pop(geom_param, None)
else:
item['_source']['properties'].pop('extent', None)
item['_source']['properties'].pop('centroid', None)
geojson_collection['features'].append(item['_source'])
return JSONResponse(geojson_collection)
示例10: get
# 需要导入模块: from arches.app.search.search_engine_factory import SearchEngineFactory [as 别名]
# 或者: from arches.app.search.search_engine_factory.SearchEngineFactory import search [as 别名]
def get(self, request, resourceid=None):
if resourceid is not None:
se = SearchEngineFactory().create()
document = se.search(index='resource', doc_type='_all', id=resourceid)
resource = Resource.objects.get(pk=resourceid)
return JSONResponse({
'graphid': document['_source']['graph_id'],
'graph_name': resource.graph.name,
'displaydescription': document['_source']['displaydescription'],
'map_popup': document['_source']['map_popup'],
'displayname': document['_source']['displayname'],
'geometries': document['_source']['geometries'],
})
return HttpResponseNotFound()
示例11: get_protected_entityids
# 需要导入模块: from arches.app.search.search_engine_factory import SearchEngineFactory [as 别名]
# 或者: from arches.app.search.search_engine_factory.SearchEngineFactory import search [as 别名]
def get_protected_entityids():
'''returns list of entity ids for protected resources'''
from search import get_protection_conceptids
protect_id = get_protection_conceptids(settings.PROTECTION_LEVEL_NODE)
filtered_ids = []
se = SearchEngineFactory().create()
# for some reason doc_type must be speficied with INFORMATION RESOURCE in order for that type
# to be queried. right now this is ok, because it's the only type with protection levels,
# but this is very strange.
all_resources = se.search(index='entity', doc_type="INFORMATION_RESOURCE.E73")['hits']['hits']
for resource in all_resources:
conceptids = [d['conceptid'] for d in resource['_source']['domains']]
if protect_id in conceptids:
filtered_ids.append(resource['_source']['entityid'])
return filtered_ids
示例12: act_a_layer
# 需要导入模块: from arches.app.search.search_engine_factory import SearchEngineFactory [as 别名]
# 或者: from arches.app.search.search_engine_factory.SearchEngineFactory import search [as 别名]
def act_a_layer(request, boundtype=''):
data = []
geom_param = request.GET.get('geom', None)
bbox = request.GET.get('bbox', '')
limit = request.GET.get('limit', settings.MAP_LAYER_FEATURE_LIMIT)
geojson_collection = {
"type": "FeatureCollection",
"features": []
}
se = SearchEngineFactory().create()
query = Query(se, limit=limit)
data = se.search(index='resource', doc_type='ACTIVITY_A.E7')
pre_collection = []
for item in data['hits']['hits']:
if "PLACE_E53" in item['_source']['graph']:
for geom in item['_source']['graph']['PLACE_E53']:
if geom['SPATIAL_COORDINATES_GEOMETRY_E47'][0]["ACTIVITY_GEOMETRY_TYPE_E55__label"] == "Project Area":
wkt = geom['SPATIAL_COORDINATES_GEOMETRY_E47'][0]['SPATIAL_COORDINATES_GEOMETRY_E47__value']
g1 = shapely.wkt.loads(wkt)
feat = geojson.Feature(geometry=g1, properties={})
feat['properties']['type'] = "Project Area"
feat['id'] = item['_source']['entityid']
geojson_collection['features'].append(feat)
if geom['SPATIAL_COORDINATES_GEOMETRY_E47'][0]["ACTIVITY_GEOMETRY_TYPE_E55__label"] == "Area of Potential Effect":
wkt = geom['SPATIAL_COORDINATES_GEOMETRY_E47'][0]['SPATIAL_COORDINATES_GEOMETRY_E47__value']
g1 = shapely.wkt.loads(wkt)
feat = geojson.Feature(geometry=g1, properties={})
feat['properties']['type'] = "Area of Potential Effect"
feat['id'] = item['_source']['entityid']
geojson_collection['features'].append(feat)
return JSONResponse(geojson_collection)
示例13: map_layers
# 需要导入模块: from arches.app.search.search_engine_factory import SearchEngineFactory [as 别名]
# 或者: from arches.app.search.search_engine_factory.SearchEngineFactory import search [as 别名]
def map_layers(request, entitytypeid='all', get_centroids=False):
data = []
geom_param = request.GET.get('geom', None)
bbox = request.GET.get('bbox', '')
limit = request.GET.get('limit', settings.MAP_LAYER_FEATURE_LIMIT)
entityids = request.GET.get('entityid', '')
geojson_collection = {
"type": "FeatureCollection",
"features": []
}
se = SearchEngineFactory().create()
query = Query(se, limit=limit)
args = { 'index': 'maplayers' }
if entitytypeid != 'all':
args['doc_type'] = entitytypeid
if entityids != '':
for entityid in entityids.split(','):
geojson_collection['features'].append(se.search(index='maplayers', id=entityid)['_source'])
return JSONResponse(geojson_collection)
data = query.search(**args)
for item in data['hits']['hits']:
if get_centroids:
item['_source']['geometry'] = item['_source']['properties']['centroid']
item['_source'].pop('properties', None)
elif geom_param != None:
item['_source']['geometry'] = item['_source']['properties'][geom_param]
item['_source']['properties'].pop('extent', None)
item['_source']['properties'].pop(geom_param, None)
else:
item['_source']['properties'].pop('extent', None)
item['_source']['properties'].pop('centroid', None)
geojson_collection['features'].append(item['_source'])
return JSONResponse(geojson_collection)
示例14: get_preflabel_from_valueid
# 需要导入模块: from arches.app.search.search_engine_factory import SearchEngineFactory [as 别名]
# 或者: from arches.app.search.search_engine_factory.SearchEngineFactory import search [as 别名]
def get_preflabel_from_valueid(valueid, lang):
se = SearchEngineFactory().create()
concept_label = se.search(index='strings', doc_type='concept', id=valueid)
if concept_label['found']:
return get_preflabel_from_conceptid(get_concept_label_from_valueid(valueid)['conceptid'], lang)
示例15: map_layers
# 需要导入模块: from arches.app.search.search_engine_factory import SearchEngineFactory [as 别名]
# 或者: from arches.app.search.search_engine_factory.SearchEngineFactory import search [as 别名]
def map_layers(request, entitytypeid='all', get_centroids=False):
lang = request.GET.get('lang', request.LANGUAGE_CODE)
if lang == 'en':
lang = 'en-US'
data = []
geom_param = request.GET.get('geom', None)
print 'map_layers: ' + entitytypeid
#print request.method
bbox = request.GET.get('bbox', '')
limit = request.GET.get('limit', settings.MAP_LAYER_FEATURE_LIMIT)
if request.method == 'GET':
entityids = request.GET.get('entityid', '')
elif request.method == 'POST':
entityids = request.POST.get('entityid', '')
#print entityids
geojson_collection = {
"type": "FeatureCollection",
"features": []
}
#print request.META
url = request.META.get('HTTP_REFERER')
searchType = 'Search'
if not url:
return JSONResponse(geojson_collection)
if url.find('searchType')>0:
parsed = urlparse.urlparse(url)
searchType = urlparse.parse_qs(parsed.query)['searchType'][0]
else:
if url.find('search_sites')>0:
searchType = 'Site'
entitytypeid = 'SITE.E18'
elif url.find('search_graves')>0:
searchType = 'Grave'
entitytypeid = 'GRAVE.E18'
elif url.find('search_objects')>0:
searchType = 'Object'
entitytypeid = 'OBJECT.E18'
#print searchType
se = SearchEngineFactory().create()
query = Query(se, limit=limit)
args = { 'index': 'maplayers' }
if entitytypeid != 'all':
args['doc_type'] = entitytypeid
if entityids != '':
for entityid in entityids.split(','):
item = se.search(index='maplayers', id=entityid)
#print item
# Prevodi
#print 'Result_item'
#print item['_source']['properties']
concept_label_ids = set()
uuid_regex = re.compile('[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}')
# gather together all uuid's referenced in the resource graph
def crawl(items):
for item in items:
if isinstance(item, dict):
for key in item:
if isinstance(item[key], list):
crawl(item[key])
else:
if isinstance(item[key], basestring) and uuid_regex.match(item[key]):
concept_label_ids.add(item[key])
crawl([item['_source']['properties']])
# get all the concept labels from the uuid's
concept_labels = se.search(index='concept_labels', id=list(concept_label_ids))
# convert all labels to their localized prefLabel
temp = {}
if concept_labels != None:
for concept_label in concept_labels['docs']:
#temp[concept_label['_id']] = concept_label
if concept_label['found']:
# the resource graph already referenced the preferred label in the desired language
if concept_label['_source']['type'] == 'prefLabel' and concept_label['_source']['language'] == lang:
temp[concept_label['_id']] = concept_label['_source']
else:
# the resource graph referenced a non-preferred label or a label not in our target language, so we need to get the right label
temp[concept_label['_id']] = get_preflabel_from_conceptid(concept_label['_source']['conceptid'], lang)
# replace the uuid's in the resource graph with their preferred and localized label
def crawl_again(items):
for item in items:
if isinstance(item, dict):
for key in item:
if isinstance(item[key], list):
crawl_again(item[key])
else:
if isinstance(item[key], basestring) and uuid_regex.match(item[key]):
try:
item[key] = temp[item[key]]['value']
except:
pass
crawl_again([item['_source']['properties']])
#print 'crawl_again'
#print item['_source']['properties']
geojson_collection['features'].append(item['_source'])
#.........这里部分代码省略.........