コード例 #1
0
 def get_string_rec_attributes(self, solr_recs):
     """ gets string record attributes from the database.
         The solr index does not keep string-fields in memory
     """
     solr_uuids = SolrUUIDs(self.response_dict_json)
     solr_uuids.rec_attributes = self.rec_attributes
     output = solr_uuids.get_string_rec_attributes(solr_recs)
     return output
コード例 #2
0
 def get_string_rec_attributes(self, solr_recs):
     """ gets string record attributes from the database.
         The solr index does not keep string-fields in memory
     """
     solr_uuids = SolrUUIDs(self.response_dict_json)
     solr_uuids.rec_attributes = self.rec_attributes
     output = solr_uuids.get_string_rec_attributes(solr_recs)
     return output
コード例 #3
0
 def get_all_media_files(self, solr_recs):
     """ gets all media files for items using the SolrUUIDs object"""
     if self.get_all_media:
         solr_uuids = SolrUUIDs(self.response_dict_json)
         solr_uuids.do_media_thumbs = self.do_media_thumbs
         solr_uuids.get_all_media = self.get_all_media
         return solr_uuids.get_all_media_files(solr_recs)
     else:
         return {}
コード例 #4
0
 def get_all_media_files(self, solr_recs):
     """ gets all media files for items using the SolrUUIDs object"""
     if self.get_all_media:
         solr_uuids = SolrUUIDs(self.response_dict_json)
         solr_uuids.do_media_thumbs = self.do_media_thumbs
         solr_uuids.get_all_media = self.get_all_media
         return solr_uuids.get_all_media_files(solr_recs)
     else:
         return {}
コード例 #5
0
ファイル: solrdirect.py プロジェクト: rdhyee/open-context-py
 def get_result_uuids(self, request_url):
     """ gets result uuids from
         a request directly to solr
     """
     uuids = []
     solr_json = self.get_solr_result_json(request_url)
     if isinstance(solr_json, dict):
         s_uuids = SolrUUIDs()
         uuids = s_uuids.make_uuids_from_solr(solr_json)
     else:
         print('Uh oh. No Solr JSON')
     return uuids
コード例 #6
0
 def process_solr_recs(self, solr_recs):
     """ processes the solr_json to
          make GeoJSON records
     """
     i = self.rec_start
     for solr_rec in solr_recs:
         i += 1
         record = LastUpdatedOrderedDict()
         rec_props_obj = RecordProperties(self.response_dict_json)
         rec_props_obj.entities = self.entities
         rec_props_obj.min_date = self.min_date
         rec_props_obj.max_date = self.max_date
         rec_props_obj.highlighting = self.highlighting
         rec_props_obj.flatten_rec_attributes = self.flatten_rec_attributes
         rec_props_obj.rec_attributes = self.rec_attributes
         rec_props_obj.parse_solr_record(solr_rec)
         self.entities = rec_props_obj.entities  # add to existing list of entities, reduce lookups
         record['id'] = '#record-' + str(i) + '-of-' + str(self.total_found)
         if rec_props_obj.label is False:
             record['label'] = 'Record ' + str(i) + ' of ' + str(self.total_found)
         else:
             record['label'] = rec_props_obj.label
         if rec_props_obj.uri is not False:
             record['rdfs:isDefinedBy'] = rec_props_obj.uri
         if rec_props_obj.latitude is not False \
            and rec_props_obj.longitude is not False:
             geometry = LastUpdatedOrderedDict()
             geometry['id'] = '#geo-rec-geom-' + str(i) + '-of-' + str(self.total_found)
             geometry['type'] = 'Point'
             geometry['coordinates'] = [rec_props_obj.longitude,
                                        rec_props_obj.latitude]
             record['type'] = 'Feature'
             record['category'] = 'oc-api:geo-record'
             record['geometry'] = geometry
         else:
             geometry = False
         if rec_props_obj.early_date is not False \
            and rec_props_obj.late_date is not False:
             when = LastUpdatedOrderedDict()
             when['id'] = '#event-rec-when-' + str(i) + '-of-' + str(self.total_found)
             when['type'] = 'oc-gen:formation-use-life'
             # convert numeric to GeoJSON-LD ISO 8601
             when['start'] = ISOyears().make_iso_from_float(rec_props_obj.early_date)
             when['stop'] = ISOyears().make_iso_from_float(rec_props_obj.late_date)
             record['when'] = when
         # start adding GeoJSON properties
         properties = LastUpdatedOrderedDict()
         properties['id'] = '#rec-' + str(i) + '-of-' + str(self.total_found)
         properties['feature-type'] = 'item record'
         properties['uri'] = rec_props_obj.uri
         properties['href'] = rec_props_obj.href
         properties['citation uri'] = rec_props_obj.cite_uri
         properties['label'] = rec_props_obj.label
         properties['project label'] = rec_props_obj.project_label
         properties['project href'] = rec_props_obj.project_href
         properties['context label'] = rec_props_obj.context_label
         properties['context href'] = rec_props_obj.context_href
         properties['early bce/ce'] = rec_props_obj.early_date
         properties['late bce/ce'] = rec_props_obj.late_date
         properties['item category'] = rec_props_obj.category
         if rec_props_obj.snippet is not False:
             properties['snippet'] = rec_props_obj.snippet
         properties['thumbnail'] = rec_props_obj.thumbnail_scr
         properties['published'] = rec_props_obj.published
         properties['updated'] = rec_props_obj.updated
         if isinstance(rec_props_obj.other_attributes, list):
             for attribute in rec_props_obj.other_attributes:
                 prop_key = attribute['property']
                 prop_key = rec_props_obj.prevent_attribute_key_collision(properties,
                                                                          prop_key)
                 if self.flatten_rec_attributes:
                     properties[prop_key] = attribute['value']
                 else:
                     properties[prop_key] = attribute['values_list']
         record['properties'] = properties
         if geometry is not False:
             # add to list of geospatial records
             self.geojson_recs.append(record)
         else:
             # case when the record is not GeoSpatial in nature
             item = SolrUUIDs().make_item_dict_from_rec_props_obj(rec_props_obj, False)
             self.non_geo_recs.append(item)
コード例 #7
0
 def process_solr_recs(self, solr_recs):
     """ processes the solr_json to
          make GeoJSON records
     """
     # check database for complex geo objects for all of these records
     db_geo = self.get_recs_complex_geo_features(solr_recs)
     if self.get_all_media:
         self.do_media_thumbs = False
     thumbnail_data = self.get_media_thumbs(solr_recs)
     media_file_data = self.get_all_media_files(solr_recs)
     string_attrib_data = self.get_string_rec_attributes(solr_recs)
     i = self.rec_start
     for solr_rec in solr_recs:
         i += 1
         record = LastUpdatedOrderedDict()
         rec_props_obj = RecordProperties(self.response_dict_json)
         rec_props_obj.min_date = self.min_date
         rec_props_obj.max_date = self.max_date
         rec_props_obj.highlighting = self.highlighting
         rec_props_obj.flatten_rec_attributes = self.flatten_rec_attributes
         rec_props_obj.rec_attributes = self.rec_attributes
         rec_props_obj.thumbnail_data = thumbnail_data
         rec_props_obj.media_file_data = media_file_data
         rec_props_obj.string_attrib_data = string_attrib_data
         rec_props_obj.parse_solr_record(solr_rec)
         record['id'] = '#record-' + str(i) + '-of-' + str(self.total_found)
         if rec_props_obj.label is False:
             record['label'] = 'Record ' + str(i) + ' of ' + str(
                 self.total_found)
         else:
             record['label'] = rec_props_obj.label
         if rec_props_obj.uri is not False:
             record['rdfs:isDefinedBy'] = rec_props_obj.uri
         if rec_props_obj.latitude is not False \
            and rec_props_obj.longitude is not False:
             # check to see if there are complex geo objects for this item
             geometry = self.get_item_complex_geo_feature(
                 i, solr_rec['uuid'], db_geo)
             if geometry is False:
                 geometry = LastUpdatedOrderedDict()
                 geometry['id'] = '#geo-rec-geom-' + str(i) + '-of-' + str(
                     self.total_found)
                 geometry['type'] = 'Point'
                 geometry['coordinates'] = [
                     rec_props_obj.longitude, rec_props_obj.latitude
                 ]
             record['type'] = 'Feature'
             record['category'] = 'oc-api:geo-record'
             record['geometry'] = geometry
         else:
             geometry = False
         if rec_props_obj.early_date is not False \
            and rec_props_obj.late_date is not False:
             when = LastUpdatedOrderedDict()
             when['id'] = '#event-rec-when-' + str(i) + '-of-' + str(
                 self.total_found)
             when['type'] = 'oc-gen:formation-use-life'
             # convert numeric to GeoJSON-LD ISO 8601
             when['start'] = ISOyears().make_iso_from_float(
                 rec_props_obj.early_date)
             when['stop'] = ISOyears().make_iso_from_float(
                 rec_props_obj.late_date)
             record['when'] = when
         # start adding GeoJSON properties
         properties = LastUpdatedOrderedDict()
         properties['id'] = '#rec-' + str(i) + '-of-' + str(
             self.total_found)
         properties['feature-type'] = 'item record'
         properties['uri'] = rec_props_obj.uri
         properties['href'] = rec_props_obj.href
         properties['citation uri'] = rec_props_obj.cite_uri
         properties['label'] = rec_props_obj.label
         properties['project label'] = rec_props_obj.project_label
         properties['project href'] = rec_props_obj.project_href
         properties['context label'] = rec_props_obj.context_label
         properties['context href'] = rec_props_obj.context_href
         properties['early bce/ce'] = rec_props_obj.early_date
         properties['late bce/ce'] = rec_props_obj.late_date
         properties['item category'] = rec_props_obj.category
         if rec_props_obj.human_remains_flagged:
             # the record is flagged to relate to human remains
             properties[
                 'human remains flagged'] = rec_props_obj.human_remains_flagged
         if rec_props_obj.snippet is not False:
             properties['snippet'] = rec_props_obj.snippet
         properties['thumbnail'] = rec_props_obj.thumbnail_scr
         if rec_props_obj.preview_scr is not False:
             properties['preview'] = rec_props_obj.preview_scr
         if rec_props_obj.fullfile_scr is not False:
             properties['primary-file'] = rec_props_obj.fullfile_scr
         properties['published'] = rec_props_obj.published
         properties['updated'] = rec_props_obj.updated
         if isinstance(rec_props_obj.other_attributes, list):
             for attribute in rec_props_obj.other_attributes:
                 prop_key = attribute['property']
                 prop_key = rec_props_obj.prevent_attribute_key_collision(
                     properties, prop_key)
                 if self.flatten_rec_attributes:
                     properties[prop_key] = attribute['value']
                 else:
                     properties[prop_key] = attribute['values_list']
         record['properties'] = properties
         if geometry is not False:
             # add to list of geospatial records
             self.geojson_recs.append(record)
         else:
             # case when the record is not GeoSpatial in nature
             item = SolrUUIDs().make_item_dict_from_rec_props_obj(
                 rec_props_obj, False)
             self.non_geo_recs.append(item)
コード例 #8
0
 def convert_solr_json(self, solr_json):
     """ Converst the solr jsont """
     ok_show_debug = True
     if 'solr' in self.act_responses:
         return solr_json
     if 'context' in self.act_responses \
        or 'geo-facet' in self.act_responses \
        or 'geo-project' in self.act_responses \
        or 'geo-record' in self.act_responses:
         search_context_obj = SearchContext()
         self.json_ld['@context'] = search_context_obj.id
     if 'metadata' in self.act_responses:
         self.json_ld['id'] = self.make_id()
         self.json_ld['label'] = self.label
         self.json_ld['dcmi:modified'] = self.get_modified_datetime(
             solr_json)
         self.json_ld['dcmi:created'] = self.get_created_datetime(solr_json)
         self.add_paging_json(solr_json)
         self.add_filters_json()
         self.add_text_fields()
     # now process numeric + date fields, facets will
     # only be added if 'facet' in self.act_response
     self.add_numeric_fields(solr_json)
     self.add_date_fields(solr_json)
     # now check for form-use-life chronology
     # note! Do this first to set time bounds for geo-features
     # needs to be done, even if facet results are not displayed
     self.make_form_use_life_chronotiles(solr_json)
     if 'geo-facet' in self.act_responses:
         # now check for discovery geotiles
         self.make_discovery_geotiles(solr_json)
     if 'geo-project' in self.act_responses:
         # now check for project geojson
         self.make_project_geojson(solr_json)
     # now process regular facets.
     # they will only be added to the response if
     # 'facet' in self.act_response
     self.make_facets(solr_json)
     if 'geo-record' in self.act_responses \
        or 'nongeo-record' in self.act_responses:
         # now add the result information
         geojson_recs_obj = GeoJsonRecords(self.request_dict_json)
         geojson_recs_obj.entities = self.entities
         geojson_recs_obj.min_date = self.min_date
         geojson_recs_obj.max_date = self.max_date
         geojson_recs_obj.flatten_rec_attributes = self.flatten_rec_attributes
         geojson_recs_obj.rec_attributes = self.rec_attributes
         geojson_recs_obj.make_records_from_solr(solr_json)
         if len(geojson_recs_obj.geojson_recs) > 0 \
            and 'geo-record' in self.act_responses:
             self.json_ld['type'] = 'FeatureCollection'
             if 'features' not in self.json_ld:
                 self.json_ld['features'] = []
             self.json_ld['features'] += geojson_recs_obj.geojson_recs
         if len(geojson_recs_obj.non_geo_recs) > 0 \
            and 'nongeo-record' in self.act_responses:
             self.json_ld[
                 'oc-api:has-results'] = geojson_recs_obj.non_geo_recs
     if 'uuid' in self.act_responses:
         solr_uuids = SolrUUIDs(self.request_dict_json)
         uuids = solr_uuids.make_uuids_from_solr(solr_json)
         if len(self.act_responses) > 1:
             # return a list inside a key
             self.json_ld['oc-api:uuids'] = uuids
         else:
             # just return a simple list
             self.json_ld = uuids
             ok_show_debug = False
     if 'uri' in self.act_responses:
         solr_uuids = SolrUUIDs(self.request_dict_json)
         uris = solr_uuids.make_uris_from_solr(solr_json)
         if len(self.act_responses) > 1:
             # return a list inside a key
             self.json_ld['oc-api:has-results'] = uris
         else:
             # just return a simple list
             self.json_ld = uris
             ok_show_debug = False
     elif 'uri-meta' in self.act_responses:
         solr_uuids = SolrUUIDs(self.request_dict_json)
         solr_uuids.min_date = self.min_date
         solr_uuids.max_date = self.max_date
         solr_uuids.entities = self.entities
         solr_uuids.flatten_rec_attributes = self.flatten_rec_attributes
         solr_uuids.rec_attributes = self.rec_attributes
         uris = solr_uuids.make_uris_from_solr(solr_json, False)
         if len(self.act_responses) > 1:
             # return a list inside a key
             self.json_ld['oc-api:has-results'] = uris
         else:
             # just return a simple list
             self.json_ld = uris
             ok_show_debug = False
     if settings.DEBUG and ok_show_debug:
         self.json_ld['request'] = self.request_dict
         # self.json_ld['request'] = self.request_dict
         self.json_ld['solr'] = solr_json
     return self.json_ld
コード例 #9
0
 def convert_solr_json(self, solr_json):
     """ Converst the solr jsont """
     ok_show_debug = True
     if 'solr' in self.act_responses:
         return solr_json
     if 'context' in self.act_responses \
        or 'geo-facet' in self.act_responses \
        or 'geo-project' in self.act_responses \
        or 'geo-record' in self.act_responses:
         search_context_obj = SearchContext()
         self.json_ld['@context'] = search_context_obj.id
     if 'metadata' in self.act_responses:
         self.json_ld['id'] = self.make_id()
         self.json_ld['label'] = self.label
         self.json_ld['dcmi:modified'] = self.get_modified_datetime(solr_json)
         self.json_ld['dcmi:created'] = self.get_created_datetime(solr_json)
         self.add_paging_json(solr_json)
         self.add_filters_json()
         self.add_text_fields()
     # now process numeric + date fields, facets will
     # only be added if 'facet' in self.act_response
     self.add_numeric_fields(solr_json)
     self.add_date_fields(solr_json)
     # now check for form-use-life chronology
     # note! Do this first to set time bounds for geo-features
     # needs to be done, even if facet results are not displayed
     self.make_form_use_life_chronotiles(solr_json)
     if 'geo-facet' in self.act_responses:
         # now check for discovery geotiles
         self.make_discovery_geotiles(solr_json)
     if 'geo-project' in self.act_responses:
         # now check for project geojson
         self.make_project_geojson(solr_json)
     # now process regular facets.
     # they will only be added to the response if
     # 'facet' in self.act_response
     self.make_facets(solr_json)
     if 'geo-record' in self.act_responses \
        or 'nongeo-record' in self.act_responses:
         # now add the result information
         geojson_recs_obj = GeoJsonRecords(self.request_dict_json)
         geojson_recs_obj.entities = self.entities
         geojson_recs_obj.min_date = self.min_date
         geojson_recs_obj.max_date = self.max_date
         geojson_recs_obj.flatten_rec_attributes = self.flatten_rec_attributes
         geojson_recs_obj.rec_attributes = self.rec_attributes
         geojson_recs_obj.make_records_from_solr(solr_json)
         if len(geojson_recs_obj.geojson_recs) > 0 \
            and 'geo-record' in self.act_responses:
             self.json_ld['type'] = 'FeatureCollection'
             if 'features' not in self.json_ld:
                 self.json_ld['features'] = []
             self.json_ld['features'] += geojson_recs_obj.geojson_recs
         if len(geojson_recs_obj.non_geo_recs) > 0 \
            and 'nongeo-record' in self.act_responses:
             self.json_ld['oc-api:has-results'] = geojson_recs_obj.non_geo_recs
     if 'uuid' in self.act_responses:
         solr_uuids = SolrUUIDs(self.request_dict_json)
         uuids = solr_uuids.make_uuids_from_solr(solr_json)
         if len(self.act_responses) > 1:
             # return a list inside a key
             self.json_ld['oc-api:uuids'] = uuids
         else:
             # just return a simple list
             self.json_ld = uuids
             ok_show_debug = False
     if 'uri' in self.act_responses:
         solr_uuids = SolrUUIDs(self.request_dict_json)
         uris = solr_uuids.make_uris_from_solr(solr_json)
         if len(self.act_responses) > 1:
             # return a list inside a key
             self.json_ld['oc-api:has-results'] = uris
         else:
             # just return a simple list
             self.json_ld = uris
             ok_show_debug = False
     elif 'uri-meta' in self.act_responses:
         solr_uuids = SolrUUIDs(self.request_dict_json)
         solr_uuids.min_date = self.min_date
         solr_uuids.max_date = self.max_date
         solr_uuids.entities = self.entities
         solr_uuids.flatten_rec_attributes = self.flatten_rec_attributes
         solr_uuids.rec_attributes = self.rec_attributes
         uris = solr_uuids.make_uris_from_solr(solr_json,
                                               False)
         if len(self.act_responses) > 1:
             # return a list inside a key
             self.json_ld['oc-api:has-results'] = uris
         else:
             # just return a simple list
             self.json_ld = uris
             ok_show_debug = False
     if settings.DEBUG and ok_show_debug:
         self.json_ld['request'] = self.request_dict
         # self.json_ld['request'] = self.request_dict
         self.json_ld['solr'] = solr_json
     return self.json_ld