use of fr.neamar.kiss.pojo.PojoComparator in project KISS by Neamar.
the class DataHandler method getResults.
/**
* Get records for this query.
*
* @param context android context
* @param query query to run
* @return ordered list of records
*/
public ArrayList<Pojo> getResults(Context context, String query) {
query = query.toLowerCase().trim().replaceAll("<", "<");
currentQuery = query;
// Have we ever made the same query and selected something ?
List<ValuedHistoryRecord> lastIdsForQuery = DBHelper.getPreviousResultsForQuery(context, query);
HashMap<String, Integer> knownIds = new HashMap<>();
for (ValuedHistoryRecord id : lastIdsForQuery) {
knownIds.put(id.record, id.value);
}
// Ask all providers for data
ArrayList<Pojo> allPojos = new ArrayList<>();
for (ProviderEntry entry : this.providers.values()) {
if (entry.provider != null) {
// Retrieve results for query:
List<Pojo> pojos = entry.provider.getResults(query);
// Add results to list
for (Pojo pojo : pojos) {
// Give a boost if item was previously selected for this query
if (knownIds.containsKey(pojo.id)) {
pojo.relevance += 25 * Math.min(5, knownIds.get(pojo.id));
}
allPojos.add(pojo);
}
}
}
// Sort records according to relevance
Collections.sort(allPojos, new PojoComparator());
return allPojos;
}
Aggregations