def invenio_search(message): '''Search Invenio using high-level API @param kwargs: (Map<String, String[]>) list of parameters This search is problematic becuase it can return different types of values: None, list of ints, String ''' params = message.getParam('kwargs') if params is None: return params = HashMap.cast_(params) #.of_(String, List) kwargs = {} kset = params.keySet().toArray() vset = params.values().toArray() max_size = len(vset) i = 0 while i < max_size: v = list(ArrayList(vset[i])) #.of_(String)) if len(v) == 1: kwargs[str(kset[i])] = v[0] else: kwargs[str(kset[i])] = v i += 1 # versatile #(wid, result) = api_calls.dispatch('invenio_search', kwargs) # dumb, but fast (wid, result) = api_calls.dispatch('invenio_search_xml2', kwargs) if not (isinstance(result, str) or result is None): raise Exception('Wrong arguments - I\'ll rather die than give you what you want!') message.setResults(result)
def test_bigtest05(self): '''Get recids_hm_intint''' message = self.bridge.createMessage('bigtest') \ .setParam('action', 'recids_hm_intint') \ .setParam('size', self.size) self.bridge.sendMessage(message) res = HashMap.cast_(message.getResults()) assert res.size() == self.size assert Integer.cast_(res.get(0)).equals(0) assert Integer.cast_(res.get(5)).equals(5)
def test_get_recids_added_all(self): # make all records appear as old message = self.bridge.createMessage('change_records') \ .setParam('diff', -1) \ .setParam('recids', JArray_int([1])) self.bridge.sendMessage(message) req = QueryRequest() rsp = SolrQueryResponse() message = self.bridge.createMessage('get_recids_changes') \ .setSender('InvenioKeepRecidUpdated') \ .setParam('response', rsp) \ .setParam('last_recid', 0) #test we can deal with extreme cases self.bridge.sendMessage(message) results = message.getResults() out = HashMap.cast_(results) added = JArray_int.cast_(out.get('ADDED')) updated = JArray_int.cast_(out.get('UPDATED')) deleted = JArray_int.cast_(out.get('DELETED')) assert (len(added)+len(updated)+len(deleted)) == self.max_recs -1 message = self.bridge.createMessage('get_recids_changes') \ .setSender('InvenioKeepRecidUpdated') \ .setParam('response', rsp) \ .setParam('max_records', 10) \ .setParam('last_recid', 0) #test we can deal with extreme cases self.bridge.sendMessage(message) results = message.getResults() out = HashMap.cast_(results) added = JArray_int.cast_(out.get('ADDED')) updated = JArray_int.cast_(out.get('UPDATED')) deleted = JArray_int.cast_(out.get('DELETED')) assert (len(added) == 10)
def test_bigtest03(self): '''Get recids_hm_strstr''' message = self.bridge.createMessage('bigtest') \ .setParam('action', 'recids_hm_strstr') \ .setParam('size', self.size) self.bridge.sendMessage(message) res = HashMap.cast_(message.getResults()) assert res.size() == self.size assert str(String.cast_(res.get('0'))) == '0' assert str(String.cast_(res.get('5'))) == '5'
def test_get_recids_minus_one(self): req = QueryRequest() rsp = SolrQueryResponse() message = self.bridge.createMessage('get_recids_changes') \ .setSender('InvenioKeepRecidUpdated') \ .setParam('response', rsp) \ .setParam('last_recid', -1) self.bridge.sendMessage(message) results = message.getResults() out = HashMap.cast_(results) added = JArray_int.cast_(out.get('ADDED')) updated = JArray_int.cast_(out.get('UPDATED')) deleted = JArray_int.cast_(out.get('DELETED')) assert (len(added)+len(updated)+len(deleted)) == self.max_recs assert len(updated) == 0
def test_get_recids_added(self): message = self.bridge.createMessage('add_records') \ .setParam('diff', 6) \ .setParam('recids', JArray_int(range(1, 11))) self.bridge.sendMessage(message) req = QueryRequest() rsp = SolrQueryResponse() message = self.bridge.createMessage('get_recids_changes') \ .setSender('InvenioKeepRecidUpdated') \ .setParam('response', rsp) \ .setParam('last_recid', 30) self.bridge.sendMessage(message) results = message.getResults() out = HashMap.cast_(results) added = JArray_int.cast_(out.get('ADDED')) assert len(added) == 10
def test_get_recids_deleted(self): #time.sleep(1) # otherwise the new record has the same creation time as the old recs #message = self.bridge.createMessage('create_delete') #self.bridge.sendMessage(message) message = self.bridge.createMessage('create_record') self.bridge.sendMessage(message) created_recid = int(Integer.cast_(message.getResults()).intValue()) message = self.bridge.createMessage('delete_record').setParam('recid', created_recid) self.bridge.sendMessage(message) deleted_recid = int(str(message.getResults())) req = QueryRequest() rsp = SolrQueryResponse() message = self.bridge.createMessage('get_recids_changes') \ .setSender('InvenioKeepRecidUpdated') \ .setParam('response', rsp) \ .setParam('last_recid', 30) self.bridge.sendMessage(message) results = message.getResults() out = HashMap.cast_(results) added = JArray_int.cast_(out.get('ADDED')) updated = JArray_int.cast_(out.get('UPDATED')) deleted = JArray_int.cast_(out.get('DELETED')) message = self.bridge.createMessage('wipeout_record') \ .setParam('recid', deleted_recid) self.bridge.sendMessage(message) assert created_recid == deleted_recid assert len(added) == 0 assert len(updated) == 0 assert len(deleted) == 1 assert int(str(deleted[0])) == deleted_recid
def sort_and_format(message): '''Calls sorting XOR formatting over the result set''' start = time.time() recids = intbitset(message.getParamArray_int("recids")) kwargs = HashMap.cast_(message.getParam('kwargs')) kws = {} kset = kwargs.keySet().toArray() vset = kwargs.values().toArray() max_size = len(vset) i = 0 while i < max_size: v = str(vset[i]) if v[0:1] in ["'", '[', '{'] : try: v = eval(v) except: pass kws[str(kset[i])] = v i += 1 if config.MONTYSOLR_BUGDEBUG: message.threadInfo("start: citation_summary") message.threadInfo("int[] converted to intbitset in: %s, size=%s" % (time.time() - start, len(recids))) (wid, (output)) = api_calls.dispatch('sort_and_format', recids, kws) if config.MONTYSOLR_BUGDEBUG: message.threadInfo("end: citation_summary pid=%s, finished in %s" % (wid, time.time() - start)) if isinstance(output, list): message.setResults(JArray_int(output)) message.setParam("rtype", "int") else: message.setResults(output) message.setParam("rtype", "string")
def xtest_bigtest05(self): '''Get recids_hm_intint -- TODO: move to demotest, it will not work, because it needs solr instance''' #req = QueryRequest() size = self.size hm = HashMap().of_(String, String) hm.put('action', 'recids_hm_intint') hm.put('size', str(size)) params = MapSolrParams(hm) req = LocalSolrQueryRequest(self.core, params) rsp = SolrQueryResponse() message = self.bridge.createMessage('bigtest_www') \ .setParam('response', rsp) \ .setParam('request', req) self.bridge.sendMessage(message) res = HashMap.cast_(message.getResults()) assert res.size() == self.size assert Integer.cast_(res.get(0)).equals(0) assert Integer.cast_(res.get(5)).equals(5)