Пример #1
0
def get_external_collection_engine(external_collection_name):
    """Return the external collection engine given its name"""

    if external_collections_dictionary.has_key(external_collection_name):
        return external_collections_dictionary[external_collection_name]
    else:
        return None
Пример #2
0
def select_external_engines(collection_name, selected_external_searches):
    """Build a tuple of two sets. The first one is the list of engine to use for an external search and the
    second one is for the seealso box."""

    collection_id = get_collection_id(collection_name)
    if not collection_id:
        return (None, None)

    if not type(selected_external_searches) is list:
        selected_external_searches = [selected_external_searches]

    seealso_engines = set()
    search_engines = set()

    if dico_collection_seealso.has_key(collection_id):
        seealso_engines = copy(dico_collection_seealso[collection_id])

    if dico_collection_external_searches.has_key(collection_id):
        seealso_engines = seealso_engines.union(
            dico_collection_external_searches[collection_id])

    for ext_search_name in selected_external_searches:
        if external_collections_dictionary.has_key(ext_search_name):
            engine = external_collections_dictionary[ext_search_name]
            if engine.parser:
                search_engines.add(engine)
        else:
            warning('select_external_engines: %(ext_search_name)s unknown.' %
                    locals())

    seealso_engines = seealso_engines.difference(search_engines)

    return (search_engines, seealso_engines)
def get_external_collection_engine(external_collection_name):
    """Return the external collection engine given its name"""

    if external_collections_dictionary.has_key(external_collection_name):
        return external_collections_dictionary[external_collection_name]
    else:
        return None
def select_external_engines(collection_name, selected_external_searches):
    """Build a tuple of two sets. The first one is the list of engine to use for an external search and the
    second one is for the seealso box."""

    collection_id = get_collection_id(collection_name)
    if not collection_id:
        return (None, None)

    if not type(selected_external_searches) is list:
        selected_external_searches = [selected_external_searches]

    seealso_engines = set()
    search_engines = set()

    if dico_collection_seealso.has_key(collection_id):
        seealso_engines = copy(dico_collection_seealso[collection_id])

    if dico_collection_external_searches.has_key(collection_id):
        seealso_engines = seealso_engines.union(dico_collection_external_searches[collection_id])

    for ext_search_name in selected_external_searches:
        if external_collections_dictionary.has_key(ext_search_name):
            engine = external_collections_dictionary[ext_search_name]
            if engine.parser:
                search_engines.add(engine)
        else:
            warning('select_external_engines: %(ext_search_name)s unknown.' % locals())

    seealso_engines = seealso_engines.difference(search_engines)

    return (search_engines, seealso_engines)
Пример #5
0
def external_collection_load_states():
    global external_collections_state, dico_collection_external_searches, dico_collection_seealso

    external_collections_state = {}
    dico_collection_external_searches = {}
    dico_collection_seealso = {}

    query = "SELECT collection_externalcollection.id_collection, collection_externalcollection.type, externalcollection.name FROM collection_externalcollection, externalcollection WHERE collection_externalcollection.id_externalcollection = externalcollection.id;"
    try:
        results = run_sql(query)
    except (OperationalError, ProgrammingError):
        results = None
    if results:
        for result in results:
            collection_id = int(result[0])
            search_type = int(result[1])
            engine_name = result[2]

            if not external_collections_dictionary.has_key(engine_name):
                warning("No search engine : " + engine_name)
                continue

            engine = external_collections_dictionary[engine_name]

            if not external_collections_state.has_key(collection_id):
                external_collections_state[collection_id] = {}
            col_states = external_collections_state[collection_id]

            col_states[engine] = search_type

            dictionary = None

            if search_type == 1:
                dictionary = dico_collection_seealso

            if search_type in [2, 3]:
                dictionary = dico_collection_external_searches

            if dictionary is None:
                continue

            if not dictionary.has_key(collection_id):
                dictionary[collection_id] = set()
            engine_set = dictionary[collection_id]
            engine_set.add(engine)
def external_collection_load_states():
    global external_collections_state, dico_collection_external_searches, dico_collection_seealso

    external_collections_state = {}
    dico_collection_external_searches = {}
    dico_collection_seealso = {}

    query = "SELECT collection_externalcollection.id_collection, collection_externalcollection.type, externalcollection.name FROM collection_externalcollection, externalcollection WHERE collection_externalcollection.id_externalcollection = externalcollection.id;"
    try:
        results = run_sql(query)
    except OperationalError:
        results = None
    if results:
        for result in results:
            collection_id = int(result[0])
            search_type = int(result[1])
            engine_name = result[2]

            if not external_collections_dictionary.has_key(engine_name):
                warning("No search engine : " + engine_name)
                continue

            engine = external_collections_dictionary[engine_name]

            if not external_collections_state.has_key(collection_id):
                external_collections_state[collection_id] = {}
            col_states = external_collections_state[collection_id]

            col_states[engine] = search_type

            dictionary = None

            if search_type == 1:
                dictionary = dico_collection_seealso

            if search_type in [2, 3]:
                dictionary = dico_collection_external_searches

            if dictionary is None:
                continue

            if not dictionary.has_key(collection_id):
                dictionary[collection_id] = set()
            engine_set = dictionary[collection_id]
            engine_set.add(engine)
Пример #7
0
 def calculate_nbrecs_for_external_collection(self, timeout=CFG_EXTERNAL_COLLECTION_TIMEOUT):
     """Calculate the total number of records, aka nbrecs, for given external collection."""
     #if self.calculate_reclist_run_already:
         # do we have to recalculate?
         #return self.nbrecs
     #write_message("... calculating nbrecs of external collection %s" % self.name, verbose=6)
     if external_collections_dictionary.has_key(self.name):
         engine = external_collections_dictionary[self.name]
         if engine.parser:
             self.nbrecs_tmp = engine.parser.parse_nbrecs(timeout)
             if self.nbrecs_tmp >= 0: return self.nbrecs_tmp
             # the parse_nbrecs() function returns negative values for some specific cases
             # maybe we can handle these specific cases, some warnings or something
             # for now the total number of records remains silently the same
             else: return self.nbrecs
         else: write_message("External collection %s does not have a parser!" % self.name, verbose=6)
     else: write_message("External collection %s not found!" % self.name, verbose=6)
     return 0
def select_hosted_search_engines(selected_hosted_collections):
    """Build the set of engines to be used for the hosted collections"""

    if not type(selected_hosted_collections) is list:
        selected_hosted_collections = [selected_hosted_collections]

    hosted_search_engines = set()

    for hosted_collection_name in selected_hosted_collections:
        if external_collections_dictionary.has_key(hosted_collection_name):
            engine = external_collections_dictionary[hosted_collection_name]
            # the hosted collection cannot present its results unless it has a parser implemented
            if engine.parser:
                hosted_search_engines.add(engine)
        else:
            warning('select_hosted_search_engines: %(hosted_collection_name)s unknown.' % locals())

    return hosted_search_engines
 def calculate_nbrecs_for_external_collection(self, timeout=CFG_EXTERNAL_COLLECTION_TIMEOUT):
     """Calculate the total number of records, aka nbrecs, for given external collection."""
     #if self.calculate_reclist_run_already:
         # do we have to recalculate?
         #return self.nbrecs
     #write_message("... calculating nbrecs of external collection %s" % self.name, verbose=6)
     if external_collections_dictionary.has_key(self.name):
         engine = external_collections_dictionary[self.name]
         if engine.parser:
             self.nbrecs_tmp = engine.parser.parse_nbrecs(timeout)
             if self.nbrecs_tmp >= 0: return self.nbrecs_tmp
             # the parse_nbrecs() function returns negative values for some specific cases
             # maybe we can handle these specific cases, some warnings or something
             # for now the total number of records remains silently the same
             else: return self.nbrecs
         else: write_message("External collection %s does not have a parser!" % self.name, verbose=6)
     else: write_message("External collection %s not found!" % self.name, verbose=6)
     return 0
def select_hosted_search_engines(selected_hosted_collections):
    """Build the set of engines to be used for the hosted collections"""

    if not type(selected_hosted_collections) is list:
        selected_hosted_collections = [selected_hosted_collections]

    hosted_search_engines = set()

    for hosted_collection_name in selected_hosted_collections:
        if external_collections_dictionary.has_key(hosted_collection_name):
            engine = external_collections_dictionary[hosted_collection_name]
            # the hosted collection cannot present its results unless it has a parser implemented
            if engine.parser:
                hosted_search_engines.add(engine)
        else:
            warning('select_hosted_search_engines: %(hosted_collection_name)s unknown.' % locals())

    return hosted_search_engines