Search in sources :

Example 1 with SearchPojo

use of fr.neamar.kiss.pojo.SearchPojo in project KISS by Neamar.

the class SearchProvider method getResults.

public ArrayList<Pojo> getResults(String query) {
    ArrayList<Pojo> pojos = new ArrayList<>();
    Set<String> selectedProviders = new TreeSet<>();
    selectedProviders.addAll(PreferenceManager.getDefaultSharedPreferences(this).getStringSet("search-providers", new HashSet<>(Arrays.asList("Google"))));
    for (String searchProvider : selectedProviders) {
        SearchPojo pojo = new SearchPojo();
        pojo.query = query;
        pojo.relevance = 10;
        pojo.url = searchProviderUrls.get(searchProvider);
        pojo.name = searchProvider;
        pojos.add(pojo);
    }
    Matcher m = p.matcher(query);
    if (m.find()) {
        String guessedUrl = URLUtil.guessUrl(query);
        if (URLUtil.isValidUrl(guessedUrl)) {
            SearchPojo pojo = new SearchPojo();
            pojo.query = "";
            pojo.relevance = 50;
            pojo.name = guessedUrl;
            pojo.url = guessedUrl;
            pojo.direct = true;
            pojos.add(pojo);
        }
    }
    return pojos;
}
Also used : Pojo(fr.neamar.kiss.pojo.Pojo) SearchPojo(fr.neamar.kiss.pojo.SearchPojo) Matcher(java.util.regex.Matcher) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) SearchPojo(fr.neamar.kiss.pojo.SearchPojo) HashSet(java.util.HashSet)

Aggregations

Pojo (fr.neamar.kiss.pojo.Pojo)1 SearchPojo (fr.neamar.kiss.pojo.SearchPojo)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 TreeSet (java.util.TreeSet)1 Matcher (java.util.regex.Matcher)1