def test_results_by_instance_keyword_with_data_registries_unknown(self): OaiRecord.initIndexes() self.dump_oai_registry() self.dump_template() self.dump_oai_my_metadata_format() data = {'keyword': 'MGI', 'schemas[]': ['software', 'service'], 'registries[]': [FAKE_ID]} url = '/oai_pmh/explore/get_results_by_instance_keyword/' req = RequestFactory().post(url, data=data) req.session = {} req.user = User.objects.get(username='******') r = get_results_by_instance_keyword(req) self.assert_result_by_instance(r, 0, [])
def ready(self): #Settings Initialization discover.init_settings() #Add indexes for the keyword research OaiRecord.initIndexes() #Load metadata prefixes discover.load_metadata_prefixes() #Check registries state discover.init_registries_status() #Launch background tasks if USE_BACKGROUND_TASK: tasks.init_harvest()
def ready(self): #Settings Initialization discover.init_settings() #Add indexes for the keyword research OaiRecord.initIndexes() #Load metadata prefixes discover.load_metadata_prefixes() #Load sets discover.load_sets() #Load xslt discover.load_xslt() #Check registries state discover.init_registries_status() #Launch background tasks tasks.init_harvest()
def test_results_by_instance_keyword_with_data(self): OaiRecord.initIndexes() self.dump_oai_registry() self.dump_template() self.dump_oai_my_metadata_format() data = {'keyword': 'MGI', 'schemas[]': ['software', 'service']} url = '/oai_pmh/explore/get_results_by_instance_keyword/' req = RequestFactory().get(url, data=data) req.session = {} req.user = User.objects.get(username='******') r = get_results_by_instance_keyword(req) result = json.loads(r) self.assertIsNotNone(result.get('resultString')) self.assertEquals(result.get('count'), 1) self.assertEquals(result.get('resultsByKeyword'), [])
def test_results_by_instance_keyword_with_data_and_suggestions(self): OaiRecord.initIndexes() self.dump_oai_registry() self.dump_template() self.dump_oai_my_metadata_format() data = {'keyword': 'MGI', 'schemas[]': ['software', 'service'], 'onlySuggestions': json.dumps(True)} url = '/oai_pmh/explore/get_results_by_instance_keyword/' req = RequestFactory().post(url, data=data) req.session = {} req.user = User.objects.get(username='******') r = get_results_by_instance_keyword(req) result = json.loads(r) self.assertEquals(result.get('resultString'), '') self.assertEquals(result.get('count'), 1) self.assertEquals(result.get('resultsByKeyword')[0].get('label'), 'mgi') self.assertEquals(result.get('resultsByKeyword')[0].get('value'), 'mgi')
def test_results_by_instance_keyword_with_data_and_suggestions(self): OaiRecord.initIndexes() self.dump_oai_registry() self.dump_template() self.dump_oai_my_metadata_format() data = {'keyword': 'MGI', 'schemas[]': ['software', 'service'], 'onlySuggestions': json.dumps(True)} url = '/oai_pmh/explore/get_results_by_instance_keyword/' req = RequestFactory().get(url, data=data) req.session = {} req.user = User.objects.get(username='******') r = get_results_by_instance_keyword(req) result = json.loads(r) self.assertEquals(result.get('resultString'), '') self.assertEquals(result.get('count'), 1) self.assertEquals(result.get('resultsByKeyword')[0].get('label'), 'mgi') self.assertEquals(result.get('resultsByKeyword')[0].get('value'), 'mgi')
def test_results_by_instance_keyword_with_data(self): OaiRecord.initIndexes() self.dump_oai_registry() self.dump_template() data = { 'keyword': 'MGI', 'schemas[]': json.dumps({'oai-pmh': ['5731fc80a530af33ed232f78']}) } url = '/oai_pmh/explore/get_results_by_instance_keyword/' r = self.doRequestGetAdminClientLogged(url=url, data=data) self.isStatusOK(r.status_code) self.assertIsNotNone(r.content) result = json.loads(r.content) self.assertIsNotNone(result.get('resultString')) self.assertEquals(result.get('count'), 1) self.assertEquals(result.get('resultsByKeyword'), [])
def oai_pmh_detail_registry(request): result_id = request.GET['id'] template = loader.get_template('oai_pmh/admin/oai_pmh_detail_registry.html') context = RequestContext(request, { 'registry': OaiRegistry.objects.get(pk=result_id), 'metadataformats': OaiMetadataFormat.objects(registry=result_id), 'sets': OaiSet.objects(registry=result_id), 'nbRecords': OaiRecord.objects(registry=result_id).count(), }) return HttpResponse(template.render(context))
def test_oai_pmh_detail_registry(self): self.dump_oai_registry() url = '/oai_pmh/admin/oai-pmh-detail-registry' id = '5731fc7fa530af33ed232f6b' data = {'id': id} r = self.doRequestGetAdminClientLogged(url=url, data=data) self.isStatusOK(r.status_code) self.assertIsNotNone(r.context) self.assertIsNotNone(r.context.dicts[1].get('metadataformats')) self.assertIsNotNone(r.context.dicts[1].get('sets')) self.assertEqual(r.context.dicts[1].get('nbRecords'), OaiRecord.objects(registry=id).count()) self.assertIsNotNone(r.context.dicts[1].get('registry'))
def get_results_occurrences(request): print 'BEGIN def getResultsKeyword(request)' tree_info = [] tree_count = [] cache_instances = {} keyword = request.POST.get('keyword', '') schemas = request.POST.getlist('schemas[]', []) user_schemas = request.POST.getlist('userSchemas[]', []) refinements = json.loads(request.POST.get('refinements', '{}')) all_refinements = json.loads(request.POST.get('allRefinements', {})) registries = request.POST.getlist('registries[]', []) splitter = ":" metadata_format_ids = _get_metadata_formats_id(schemas=schemas, user_schemas=user_schemas, registries=registries) try: for current in all_refinements: refine = [] for x in refinements: if x['key'] != current['key']: refine.append(x) list_refinements = refinements_to_mongo(refine) json_refinements = json.dumps(list_refinements) if not cache_instances.has_key(json_refinements): instance_results = OaiRecord.executeFullTextQuery(keyword, metadata_format_ids, list_refinements, only_content=True) cache_instances[json_refinements] = instance_results else: instance_results = cache_instances[json_refinements] for refinement in current['value']: ids = _get_list_ids_for_refinement(instance_results, refinement) tree_count.append({"refinement": refinement, "ids": ids}) result_json = {'text_id': hashlib.sha1(refinement).hexdigest(), 'nb_occurrences': len(ids)} tree_info.append(result_json) # For categories max_level = max(len(x['refinement'].split(splitter)) for x in tree_count) for i in range(max_level, 0, -1): grouper = lambda x: ":".join(x['refinement'].split(splitter)[:i]) for key, grp in groupby(sorted(tree_count, key=grouper), grouper): if len(key.split(splitter)) == i: ids = [] for item in grp: ids.extend(item["ids"]) key_category = "{0}_{1}".format(key, Tree.TreeInfo.get_category_label()) result_json = {'text_id': hashlib.sha1(key_category).hexdigest(), 'nb_occurrences': len(sorted(set(ids)))} tree_info.append(result_json) except Exception, e: pass
def get_results_by_instance_keyword(request): print 'BEGIN def getResultsKeyword(request)' resultsByKeyword = [] results = [] resultString = "" #Instance json_instances = [] if 'HTTPS' in request.META['SERVER_PROTOCOL']: protocol = "https" else: protocol = "http" instance = Instance(name="Local", protocol=protocol, address=request.META['REMOTE_ADDR'], port=request.META['SERVER_PORT'], access_token="token", refresh_token="token") json_instances.append(instance.to_json()) request.session['instancesExplore'] = json_instances sessionName = "resultsExploreOaiPMh" + instance['name'] try: keyword = request.GET['keyword'] schemas = request.GET.getlist('schemas[]') userSchemas = request.GET.getlist('userSchemas[]') refinements = refinements_to_mongo(request.GET.getlist('refinements[]')) if 'onlySuggestions' in request.GET: onlySuggestions = json.loads(request.GET['onlySuggestions']) else: onlySuggestions = False except: keyword = '' schemas = [] userSchemas = [] refinements = {} onlySuggestions = True #We get all template versions for the given schemas #First, we take care of user defined schema templatesIDUser = Template.objects(title__in=userSchemas).distinct(field="id") templatesIDUser = [str(x) for x in templatesIDUser] #Take care of the rest, with versions templatesVersions = Template.objects(title__in=schemas).distinct(field="templateVersion") #We get all templates ID, for all versions allTemplatesIDCommon = TemplateVersion.objects(pk__in=templatesVersions, isDeleted=False).distinct(field="versions") #We remove the removed version allTemplatesIDCommonRemoved = TemplateVersion.objects(pk__in=templatesVersions, isDeleted=False).distinct(field="deletedVersions") templatesIDCommon = list(set(allTemplatesIDCommon) - set(allTemplatesIDCommonRemoved)) templatesID = templatesIDUser + templatesIDCommon #We retrieve deactivated registries so as not to get their metadata formats deactivatedRegistries = [str(x.id) for x in OaiRegistry.objects(isDeactivated=True).order_by('id')] metadataFormatsID = OaiMetadataFormat.objects(template__in=templatesID, registry__not__in=deactivatedRegistries).distinct(field="id") instanceResults = OaiRecord.executeFullTextQuery(keyword, metadataFormatsID, refinements) if len(instanceResults) > 0: if not onlySuggestions: xsltPath = os.path.join(settings.SITE_ROOT, 'static/resources/xsl/xml2html.xsl') xslt = etree.parse(xsltPath) transform = etree.XSLT(xslt) template = loader.get_template('oai_pmh/explore/explore_result_keyword.html') #Retrieve schema and registries. Avoid to retrieve the information for each result registriesName = {} objMetadataFormats = {} listRegistriesID = set([x['registry'] for x in instanceResults]) for registryId in listRegistriesID: obj = OaiRegistry.objects(pk=registryId).get() registriesName[str(registryId)] = obj.name listSchemaId = set([x['metadataformat'] for x in instanceResults]) for schemaId in listSchemaId: obj = OaiMetadataFormat.objects(pk=schemaId).get() objMetadataFormats[str(schemaId)] = obj listItems = [] xmltodictunparse = xmltodict.unparse appendResult = results.append toXML = etree.XML parse = etree.parse XSLT = etree.XSLT if not onlySuggestions: for instanceResult in instanceResults: custom_xslt = False appendResult({'title':instanceResult['identifier'], 'content':xmltodictunparse(instanceResult['metadata']),'id':str(instanceResult['_id'])}) dom = toXML(str(xmltodictunparse(instanceResult['metadata']).encode('utf-8'))) #Check if a custom list result XSLT has to be used try: metadataFormat = objMetadataFormats[str(instanceResult['metadataformat'])] if metadataFormat.template.ResultXsltList: listXslt = parse(BytesIO(metadataFormat.template.ResultXsltList.content.encode('utf-8'))) listTransform = XSLT(listXslt) newdom = listTransform(dom) custom_xslt = True else: newdom = transform(dom) except Exception, e: #We use the default one newdom = transform(dom) custom_xslt = False context = RequestContext(request, {'id':str(instanceResult['_id']), 'xml': str(newdom), 'title': instanceResult['identifier'], 'custom_xslt': custom_xslt, 'schema_name': metadataFormat.metadataPrefix, 'registry_name': registriesName[instanceResult['registry']], 'oai_pmh': True}) resultString+= template.render(context) else: for instanceResult in instanceResults[:20]: wordList = re.sub("[^\w]", " ", keyword).split() wordList = [x + "|" + x +"\w+" for x in wordList] wordList = '|'.join(wordList) listWholeKeywords = re.findall("\\b("+ wordList +")\\b", xmltodict.unparse(instanceResult['metadata']).encode('utf-8'), flags=re.IGNORECASE) labels = list(set(listWholeKeywords)) for label in labels: label = label.lower() result_json = {} result_json['label'] = label result_json['value'] = label if not result_json in resultsByKeyword: resultsByKeyword.append(result_json)
def dump_oai_record(self): self.assertEquals(len(OaiRecord.objects()), 0) self.restoreDump(join(DUMP_OAI_PMH_TEST_PATH, 'oai_record.bson'), 'oai_record') self.assertTrue(len(OaiRecord.objects()) > 0)
def get_results_by_instance_keyword(request): print 'BEGIN def getResultsKeyword(request)' resultsByKeyword = [] results = [] resultString = "" #Instance json_instances = [] if 'HTTPS' in request.META['SERVER_PROTOCOL']: protocol = "https" else: protocol = "http" instance = Instance(name="Local", protocol=protocol, address=request.META['REMOTE_ADDR'], port=request.META['SERVER_PORT'], access_token="token", refresh_token="token") json_instances.append(instance.to_json()) request.session['instancesExplore'] = json_instances sessionName = "resultsExploreOaiPMh" + instance['name'] keyword = request.POST.get('keyword', '') schemas = request.POST.getlist('schemas[]', []) user_schemas = request.POST.getlist('userSchemas[]', []) refinements = refinements_to_mongo( json.loads(request.POST.get('refinements', '{}'))) registries = request.POST.getlist('registries[]', []) if 'onlySuggestions' in request.POST: onlySuggestions = json.loads(request.POST['onlySuggestions']) else: onlySuggestions = False metadata_format_ids = _get_metadata_formats_id(schemas=schemas, user_schemas=user_schemas, registries=registries) instanceResults = OaiRecord.executeFullTextQuery(keyword, metadata_format_ids, refinements) if len(instanceResults) > 0: if not onlySuggestions: xsltPath = os.path.join(settings.SITE_ROOT, 'static/resources/xsl/xml2html.xsl') xslt = etree.parse(xsltPath) transform = etree.XSLT(xslt) template = loader.get_template( 'oai_pmh/explore/explore_result_keyword.html') #Retrieve schema and registries. Avoid to retrieve the information for each result registriesName = {} objMetadataFormats = {} listRegistriesID = set([x['registry'] for x in instanceResults]) registriesURL = {} for registryId in listRegistriesID: obj = OaiRegistry.objects(pk=registryId).get() registriesName[str(registryId)] = obj.name registriesURL[str(registryId)] = obj.url listSchemaId = set([x['metadataformat'] for x in instanceResults]) for schemaId in listSchemaId: obj = OaiMetadataFormat.objects(pk=schemaId).get() objMetadataFormats[str(schemaId)] = obj listItems = [] xmltodictunparse = XMLdata.unparse appendResult = results.append toXML = etree.XML parse = etree.parse XSLT = etree.XSLT if not onlySuggestions: for instanceResult in instanceResults: custom_xslt = False appendResult({ 'title': instanceResult['identifier'], 'content': xmltodictunparse(instanceResult['metadata']), 'id': str(instanceResult['_id']) }) dom = toXML( str( xmltodictunparse( instanceResult['metadata']).encode('utf-8'))) #Check if a custom list result XSLT has to be used try: metadataFormat = objMetadataFormats[str( instanceResult['metadataformat'])] if metadataFormat.template.ResultXsltList: listXslt = parse( BytesIO( metadataFormat.template.ResultXsltList.content. encode('utf-8'))) listTransform = XSLT(listXslt) newdom = listTransform(dom) custom_xslt = True else: newdom = transform(dom) except Exception, e: #We use the default one newdom = transform(dom) custom_xslt = False registry_name = registriesName[instanceResult['registry']] if len(registry_name) > 30: registry_name = "{0}...".format(registry_name[:30]) url = urlparse(registriesURL[instanceResult['registry']]) context = RequestContext( request, { 'id': str(instanceResult['_id']), 'xml': str(newdom), 'title': instanceResult['identifier'], 'custom_xslt': custom_xslt, 'template_name': metadataFormat.template.title, 'registry_name': registry_name, 'registry_url': "{0}://{1}".format( url.scheme, url.netloc), 'oai_pmh': True }) resultString += template.render(context) else: for instanceResult in instanceResults[:20]: wordList = re.sub("[^\w]", " ", keyword).split() wordList = [x + "|" + x + "\w+" for x in wordList] wordList = '|'.join(wordList) listWholeKeywords = re.findall( "\\b(" + wordList + ")\\b", XMLdata.unparse( instanceResult['metadata']).encode('utf-8'), flags=re.IGNORECASE) labels = list(set(listWholeKeywords)) for label in labels: label = label.lower() result_json = {} result_json['label'] = label result_json['value'] = label if not result_json in resultsByKeyword: resultsByKeyword.append(result_json)
def get_results_by_instance_keyword(request): print 'BEGIN def getResultsKeyword(request)' resultsByKeyword = [] results = [] resultString = "" #Instance json_instances = [] if 'HTTPS' in request.META['SERVER_PROTOCOL']: protocol = "https" else: protocol = "http" instance = Instance(name="Local", protocol=protocol, address=request.META['REMOTE_ADDR'], port=request.META['SERVER_PORT'], access_token="token", refresh_token="token") json_instances.append(instance.to_json()) request.session['instancesExplore'] = json_instances sessionName = "resultsExploreOaiPMh" + instance['name'] try: keyword = request.GET['keyword'] schemas = request.GET.getlist('schemas[]') mergedSchemas = [] for schema in schemas: t = json.loads(schema) mergedSchemas += t['oai-pmh'] if 'onlySuggestions' in request.GET: onlySuggestions = json.loads(request.GET['onlySuggestions']) else: onlySuggestions = False except: keyword = '' schemas = [] onlySuggestions = True mergedSchemas = [] instanceResults = OaiRecord.executeFullTextQuery(keyword, mergedSchemas) if len(instanceResults) > 0: if not onlySuggestions: xsltPath = os.path.join(settings.SITE_ROOT, 'static/resources/xsl/xml2html.xsl') xslt = etree.parse(xsltPath) transform = etree.XSLT(xslt) #Retrieve schema and registries. Avoid to retrieve the information for each result registriesName = {} schemasName = {} listRegistriesID = set([x['registry'] for x in instanceResults]) for registryId in listRegistriesID: obj = OaiRegistry.objects(pk=registryId).get() registriesName[str(registryId)] = obj.name listSchemaId = set([x['metadataformat'] for x in instanceResults]) for schemaId in listSchemaId: obj = OaiMetadataFormat.objects(pk=schemaId).get() schemasName[str(schemaId)] = obj listItems = [] xmltodictunparse = unparse appendResult = results.append toXML = etree.XML parse = etree.parse XSLT = etree.XSLT if not onlySuggestions: for instanceResult in instanceResults: custom_xslt = False appendResult({ 'title': instanceResult['identifier'], 'content': xmltodictunparse(instanceResult['metadata']), 'id': str(instanceResult['_id']) }) dom = toXML( str( xmltodictunparse( instanceResult['metadata']).encode('utf-8'))) #Check if a custom list result XSLT has to be used try: schema = schemasName[str(instanceResult['metadataformat'])] if schema.ResultXsltList: listXslt = parse( BytesIO( schema.ResultXsltList.content.encode('utf-8'))) listTransform = XSLT(listXslt) newdom = listTransform(dom) custom_xslt = True else: newdom = transform(dom) except Exception, e: #We use the default one newdom = transform(dom) custom_xslt = False item = { 'id': str(instanceResult['_id']), 'xml': str(newdom), 'title': instanceResult['identifier'], 'custom_xslt': custom_xslt, 'schema_name': schema.metadataPrefix, 'registry_name': registriesName[instanceResult['registry']] } listItems.append(item) context = RequestContext(request, {'list_results': listItems}) else: for instanceResult in instanceResults[:20]: wordList = re.sub("[^\w]", " ", keyword).split() wordList = [x + "|" + x + "\w+" for x in wordList] wordList = '|'.join(wordList) listWholeKeywords = re.findall( "\\b(" + wordList + ")\\b", unparse(instanceResult['metadata']).encode('utf-8'), flags=re.IGNORECASE) labels = list(set(listWholeKeywords)) for label in labels: label = label.lower() result_json = {} result_json['label'] = label result_json['value'] = label if not result_json in resultsByKeyword: resultsByKeyword.append(result_json) if not onlySuggestions: template = loader.get_template( 'oai_pmh/explore/explore_result_keyword.html') resultString += template.render(context)
def get_results_by_instance_keyword(request): print 'BEGIN def getResultsKeyword(request)' resultsByKeyword = [] results = [] resultString = "" #Instance json_instances = [] if 'HTTPS' in request.META['SERVER_PROTOCOL']: protocol = "https" else: protocol = "http" instance = Instance(name="Local", protocol=protocol, address=request.META['REMOTE_ADDR'], port=request.META['SERVER_PORT'], access_token="token", refresh_token="token") json_instances.append(instance.to_json()) request.session['instancesExplore'] = json_instances sessionName = "resultsExploreOaiPMh" + instance['name'] try: keyword = request.GET['keyword'] schemas = request.GET.getlist('schemas[]') userSchemas = request.GET.getlist('userSchemas[]') refinements = refinements_to_mongo( request.GET.getlist('refinements[]')) if 'onlySuggestions' in request.GET: onlySuggestions = json.loads(request.GET['onlySuggestions']) else: onlySuggestions = False except: keyword = '' schemas = [] userSchemas = [] refinements = {} onlySuggestions = True #We get all template versions for the given schemas #First, we take care of user defined schema templatesIDUser = Template.objects(title__in=userSchemas).distinct( field="id") templatesIDUser = [str(x) for x in templatesIDUser] #Take care of the rest, with versions templatesVersions = Template.objects(title__in=schemas).distinct( field="templateVersion") #We get all templates ID, for all versions allTemplatesIDCommon = TemplateVersion.objects( pk__in=templatesVersions, isDeleted=False).distinct(field="versions") #We remove the removed version allTemplatesIDCommonRemoved = TemplateVersion.objects( pk__in=templatesVersions, isDeleted=False).distinct(field="deletedVersions") templatesIDCommon = list( set(allTemplatesIDCommon) - set(allTemplatesIDCommonRemoved)) templatesID = templatesIDUser + templatesIDCommon #We retrieve deactivated registries so as not to get their metadata formats deactivatedRegistries = [ str(x.id) for x in OaiRegistry.objects(isDeactivated=True).order_by('id') ] metadataFormatsID = OaiMetadataFormat.objects( template__in=templatesID, registry__not__in=deactivatedRegistries).distinct(field="id") instanceResults = OaiRecord.executeFullTextQuery(keyword, metadataFormatsID, refinements) if len(instanceResults) > 0: if not onlySuggestions: xsltPath = os.path.join(settings.SITE_ROOT, 'static/resources/xsl/xml2html.xsl') xslt = etree.parse(xsltPath) transform = etree.XSLT(xslt) template = loader.get_template( 'oai_pmh/explore/explore_result_keyword.html') #Retrieve schema and registries. Avoid to retrieve the information for each result registriesName = {} objMetadataFormats = {} listRegistriesID = set([x['registry'] for x in instanceResults]) for registryId in listRegistriesID: obj = OaiRegistry.objects(pk=registryId).get() registriesName[str(registryId)] = obj.name listSchemaId = set([x['metadataformat'] for x in instanceResults]) for schemaId in listSchemaId: obj = OaiMetadataFormat.objects(pk=schemaId).get() objMetadataFormats[str(schemaId)] = obj listItems = [] xmltodictunparse = xmltodict.unparse appendResult = results.append toXML = etree.XML parse = etree.parse XSLT = etree.XSLT if not onlySuggestions: for instanceResult in instanceResults: custom_xslt = False appendResult({ 'title': instanceResult['identifier'], 'content': xmltodictunparse(instanceResult['metadata']), 'id': str(instanceResult['_id']) }) dom = toXML( str( xmltodictunparse( instanceResult['metadata']).encode('utf-8'))) #Check if a custom list result XSLT has to be used try: metadataFormat = objMetadataFormats[str( instanceResult['metadataformat'])] if metadataFormat.template.ResultXsltList: listXslt = parse( BytesIO( metadataFormat.template.ResultXsltList.content. encode('utf-8'))) listTransform = XSLT(listXslt) newdom = listTransform(dom) custom_xslt = True else: newdom = transform(dom) except Exception, e: #We use the default one newdom = transform(dom) custom_xslt = False context = RequestContext( request, { 'id': str(instanceResult['_id']), 'xml': str(newdom), 'title': instanceResult['identifier'], 'custom_xslt': custom_xslt, 'schema_name': metadataFormat.metadataPrefix, 'registry_name': registriesName[instanceResult['registry']], 'oai_pmh': True }) resultString += template.render(context) else: for instanceResult in instanceResults[:20]: wordList = re.sub("[^\w]", " ", keyword).split() wordList = [x + "|" + x + "\w+" for x in wordList] wordList = '|'.join(wordList) listWholeKeywords = re.findall( "\\b(" + wordList + ")\\b", xmltodict.unparse( instanceResult['metadata']).encode('utf-8'), flags=re.IGNORECASE) labels = list(set(listWholeKeywords)) for label in labels: label = label.lower() result_json = {} result_json['label'] = label result_json['value'] = label if not result_json in resultsByKeyword: resultsByKeyword.append(result_json)