Exemplo n.º 1
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 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)
Exemplo n.º 3
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)
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 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