Search in sources :

Example 1 with SearchException

use of com.biglybt.pif.utils.search.SearchException in project BiglyBT by BiglySoftware.

the class RelatedContentManager method searchRCMSupport.

SearchInstance searchRCMSupport(Map<String, Object> search_parameters, SearchObserver observer) throws SearchException {
    initialisation_complete_sem.reserve();
    if (!enabled) {
        throw (new SearchException("rcm is disabled"));
    }
    String[] networks = (String[]) search_parameters.get(SearchProvider.SP_NETWORKS);
    String target_net = AENetworkClassifier.AT_PUBLIC;
    if (networks != null) {
        for (String net : networks) {
            if (net == AENetworkClassifier.AT_PUBLIC) {
                target_net = AENetworkClassifier.AT_PUBLIC;
                break;
            } else if (net == AENetworkClassifier.AT_I2P) {
                target_net = AENetworkClassifier.AT_I2P;
            }
        }
    }
    if (target_net == AENetworkClassifier.AT_I2P) {
        checkI2PSearcher(true);
    } else if (prefer_i2p) {
        RelatedContentSearcher searcher = checkMixSearcher();
        if (searcher != null) {
            return (searcher.searchRCM(search_parameters, observer));
        }
    }
    for (RelatedContentSearcher searcher : searchers) {
        String net = searcher.getDHTPlugin().getNetwork();
        if (net == target_net) {
            return (searcher.searchRCM(search_parameters, observer));
        }
    }
    throw (new SearchException("no searchers available"));
}
Also used : SearchException(com.biglybt.pif.utils.search.SearchException)

Example 2 with SearchException

use of com.biglybt.pif.utils.search.SearchException in project BiglyBT by BiglySoftware.

the class RelatedContentManager method searchRCM.

public SearchInstance searchRCM(final Map<String, Object> search_parameters, final SearchObserver observer) throws SearchException {
    if (!initialisation_complete_sem.isReleasedForever()) {
        AsyncDispatcher dispatcher = new AsyncDispatcher();
        final boolean[] cancelled = { false };
        final boolean[] went_async = { false };
        final SearchInstance[] si = { null };
        final SearchException[] error = { null };
        final AESemaphore temp_sem = new AESemaphore("");
        dispatcher.dispatch(new AERunnable() {

            @Override
            public void runSupport() {
                try {
                    si[0] = searchRCMSupport(search_parameters, observer);
                    synchronized (cancelled) {
                        if (cancelled[0]) {
                            si[0].cancel();
                        }
                    }
                } catch (Throwable e) {
                    Debug.out(e);
                    SearchException se;
                    if (e instanceof SearchException) {
                        se = (SearchException) e;
                    } else {
                        se = new SearchException("Search failed", e);
                    }
                    synchronized (cancelled) {
                        error[0] = se;
                        if (went_async[0]) {
                            // error won't be returned to caller, signify that things
                            // ain't going anywhere
                            observer.complete();
                        }
                    }
                } finally {
                    temp_sem.release();
                }
            }
        });
        temp_sem.reserve(500);
        synchronized (cancelled) {
            if (si[0] != null) {
                return (si[0]);
            }
            if (error[0] != null) {
                throw (error[0]);
            }
            went_async[0] = true;
        }
        SearchInstance result = new SearchInstance() {

            @Override
            public void cancel() {
                synchronized (cancelled) {
                    if (si[0] != null) {
                        si[0].cancel();
                    }
                    cancelled[0] = true;
                }
            }
        };
        return (result);
    } else {
        return (searchRCMSupport(search_parameters, observer));
    }
}
Also used : SearchException(com.biglybt.pif.utils.search.SearchException) SearchInstance(com.biglybt.pif.utils.search.SearchInstance)

Example 3 with SearchException

use of com.biglybt.pif.utils.search.SearchException in project BiglyBT by BiglySoftware.

the class MetaSearchManagerImpl method createSearch.

protected Search createSearch(long[] provider_ids, Map<String, String> properties, SearchListener listener) throws SearchException {
    List<SearchParameter> sps = new ArrayList<>();
    String search_term = properties.get(SearchInitiator.PR_SEARCH_TERM);
    if (search_term == null) {
        throw (new SearchException("Search term is mandatory"));
    }
    sps.add(new SearchParameter("s", search_term));
    String mature = properties.get(SearchInitiator.PR_MATURE);
    if (mature != null) {
        sps.add(new SearchParameter("m", mature.toString()));
    }
    SearchParameter[] parameters = (SearchParameter[]) sps.toArray(new SearchParameter[sps.size()]);
    Map<String, String> context = new HashMap<>();
    context.put(Engine.SC_FORCE_FULL, "true");
    String headers = null;
    int max_per_engine = 256;
    SearchObject search = new SearchObject(listener);
    Engine[] used_engines;
    if (provider_ids.length == 0) {
        used_engines = getMetaSearch().search(search, parameters, headers, context, max_per_engine);
    } else {
        List<Engine> selected_engines = new ArrayList<>();
        for (long id : provider_ids) {
            Engine engine = meta_search.getEngine(id);
            if (engine == null) {
                throw (new SearchException("Unknown engine id - " + id));
            } else {
                selected_engines.add(engine);
            }
        }
        Engine[] engines = selected_engines.toArray(new Engine[selected_engines.size()]);
        used_engines = getMetaSearch().search(engines, search, parameters, headers, context, max_per_engine);
    }
    search.setEnginesUsed(used_engines);
    return (search);
}
Also used : SearchException(com.biglybt.pif.utils.search.SearchException) PluginEngine(com.biglybt.core.metasearch.impl.plugin.PluginEngine)

Example 4 with SearchException

use of com.biglybt.pif.utils.search.SearchException in project BiglyBT by BiglySoftware.

the class MetaSearchManagerImpl method createSearch.

@Override
public Search createSearch(SearchProvider[] providers, Map<String, String> properties, SearchListener listener) throws SearchException {
    long[] pids;
    if (providers == null) {
        pids = new long[0];
    } else {
        pids = new long[providers.length];
        for (int i = 0; i < pids.length; i++) {
            Long id = (Long) providers[i].getProperty(SearchProvider.PR_ID);
            if (id == null) {
                throw (new SearchException("Unknown provider - no id available"));
            }
            pids[i] = id;
        }
    }
    return (createSearch(pids, properties, listener));
}
Also used : SearchException(com.biglybt.pif.utils.search.SearchException)

Aggregations

SearchException (com.biglybt.pif.utils.search.SearchException)4 PluginEngine (com.biglybt.core.metasearch.impl.plugin.PluginEngine)1 SearchInstance (com.biglybt.pif.utils.search.SearchInstance)1