def get_facets_for_query(self, qid, limit=20, parent=None): """Return facet data.""" from invenio.legacy.search_engine import get_most_popular_field_values,\ get_field_tags return get_most_popular_field_values(self.get_recids(qid), get_field_tags(self.name) )[0:limit]
def get_facets_for_query(self, qid, limit=20, parent=None): """Return facet data.""" from invenio.legacy.search_engine import get_most_popular_field_values,\ get_field_tags return get_most_popular_field_values(self.get_recids(qid), get_field_tags( self.name))[0:limit]
def get_kbd_values(kbname, searchwith=""): """Return a list of values by searching a dynamic kb. :param kbname: name of the knowledge base :param searchwith: a term to search with """ from invenio.legacy import search_engine # first check that the kb in question is dynamic kb = get_kb_by_name(kbname) kbid = kb.id if not kbid: return [] kbtype = kb.kbtype if not kbtype: return [] if kbtype != 'd': return [] # get the configuration so that we see what the field is confdict = kb.kbdefs.to_dict() if not confdict: return [] if 'field' not in confdict: return [] field = confdict['field'] expression = confdict['expression'] collection = "" if 'collection' in confdict: collection = confdict['collection'] reclist = [] # return this if searchwith and expression: if (expression.count('%') > 0): expression = expression.replace("%", searchwith) reclist = search_engine.perform_request_search(p=expression, cc=collection) else: # no %.. just make a combination expression = expression + " and " + searchwith reclist = search_engine.perform_request_search(p=expression, cc=collection) else: # either no expr or no searchwith.. but never mind about searchwith if expression: # in this case: only expression reclist = search_engine.perform_request_search(p=expression, cc=collection) else: # make a fake expression so that only records that have this field # will be returned fake_exp = "/.*/" if searchwith: fake_exp = searchwith reclist = search_engine.perform_request_search(f=field, p=fake_exp, cc=collection) if reclist: return [ val for (val, dummy) in search_engine.get_most_popular_field_values( reclist, field) ] return [] # in case nothing worked
def _get_collabtuples_fallback(pubs, person_id): ''' Returns the list of keyword tuples for given personid. @param person_id: int person id ''' tup = get_most_popular_field_values(pubs, COLLABORATION_TAG, count_repetitive_values=False) return tup
def _get_kwtuples_fallback(pubs, person_id): ''' Returns the list of keyword tuples for given personid. @param person_id: int person id ''' tup = get_most_popular_field_values(pubs, (KEYWORD_TAG, FKEYWORD_TAG), count_repetitive_values=False) return tup
def get_kbd_values(kbname, searchwith=""): """Return a list of values by searching a dynamic kb. :param kbname: name of the knowledge base :param searchwith: a term to search with """ from invenio.legacy import search_engine # first check that the kb in question is dynamic kb = get_kb_by_name(kbname) kbid = kb.id if not kbid: return [] kbtype = kb.kbtype if not kbtype: return [] if kbtype != 'd': return [] # get the configuration so that we see what the field is confdict = kb.kbdefs.to_dict() if not confdict: return [] if 'field' not in confdict: return [] field = confdict['field'] expression = confdict['expression'] collection = "" if 'collection' in confdict: collection = confdict['collection'] reclist = [] # return this if searchwith and expression: if (expression.count('%') > 0): expression = expression.replace("%", searchwith) reclist = search_engine.perform_request_search(p=expression, cc=collection) else: # no %.. just make a combination expression = expression + " and " + searchwith reclist = search_engine.perform_request_search(p=expression, cc=collection) else: # either no expr or no searchwith.. but never mind about searchwith if expression: # in this case: only expression reclist = search_engine.perform_request_search(p=expression, cc=collection) else: # make a fake expression so that only records that have this field # will be returned fake_exp = "/.*/" if searchwith: fake_exp = searchwith reclist = search_engine.perform_request_search(f=field, p=fake_exp, cc=collection) if reclist: return [val for (val, dummy) in search_engine.get_most_popular_field_values(reclist, field)] return [] # in case nothing worked
def get_kbd_values_by_def(confdict, searchwith=""): """Return a list of values by searching a dynamic kb. :param confdict: dictionary with keys "field", "expression" and "collection" name :param searchwith: a term to search with :return: list of values """ from invenio.legacy import search_engine # get the configuration so that we see what the field is if not confdict: return [] if 'field' not in confdict: return [] field = confdict['field'] expression = confdict['expression'] collection = "" if 'collection' in confdict: collection = confdict['collection'] reclist = [] # return this if searchwith and expression: if (expression.count('%') > 0): expression = expression.replace("%", searchwith) reclist = search_engine.perform_request_search(p=expression, cc=collection) else: # no %.. just make a combination expression = expression + " and " + searchwith reclist = search_engine.perform_request_search(p=expression, cc=collection) else: # either no expr or no searchwith.. but never mind about searchwith if expression: # in this case: only expression reclist = search_engine.perform_request_search(p=expression, cc=collection) else: # make a fake expression so that only records that have this field # will be returned fake_exp = "/.*/" if searchwith: fake_exp = searchwith reclist = search_engine.perform_request_search(f=field, p=fake_exp, cc=collection) if reclist: return [ val for (val, dummy) in search_engine.get_most_popular_field_values( reclist, field) ] return [] # in case nothing worked
def get_kbd_values_by_def(confdict, searchwith=""): """Return a list of values by searching a dynamic kb. :param confdict: dictionary with keys "field", "expression" and "collection" name :param searchwith: a term to search with :return: list of values """ from invenio.legacy import search_engine # get the configuration so that we see what the field is if not confdict: return [] if 'field' not in confdict: return [] field = confdict['field'] expression = confdict['expression'] collection = "" if 'collection' in confdict: collection = confdict['collection'] reclist = [] # return this if searchwith and expression: if (expression.count('%') > 0): expression = expression.replace("%", searchwith) reclist = search_engine.perform_request_search(p=expression, cc=collection) else: # no %.. just make a combination expression = expression + " and " + searchwith reclist = search_engine.perform_request_search(p=expression, cc=collection) else: # either no expr or no searchwith.. but never mind about searchwith if expression: # in this case: only expression reclist = search_engine.perform_request_search(p=expression, cc=collection) else: # make a fake expression so that only records that have this field # will be returned fake_exp = "/.*/" if searchwith: fake_exp = searchwith reclist = search_engine.perform_request_search(f=field, p=fake_exp, cc=collection) if reclist: return [val for (val, dummy) in search_engine.get_most_popular_field_values(reclist, field)] return [] # in case nothing worked
def _get_venuetuples(pubs, person_id): tup = get_most_popular_field_values(pubs, (VENUE_TAG)) return tup