use of fr.neamar.kiss.pojo.ShortcutsPojo in project KISS by Neamar.
the class ShortcutsProvider method getResults.
@Override
public ArrayList<Pojo> getResults(String query) {
ArrayList<Pojo> results = new ArrayList<>();
int relevance;
int matchPositionStart;
int matchPositionEnd;
String shortcutNameLowerCased;
final String queryWithSpace = " " + query;
for (ShortcutsPojo shortcut : pojos) {
relevance = 0;
shortcutNameLowerCased = shortcut.nameNormalized;
matchPositionEnd = 0;
if (shortcutNameLowerCased.startsWith(query)) {
relevance = 75;
matchPositionStart = 0;
matchPositionEnd = query.length();
} else if ((matchPositionStart = shortcutNameLowerCased.indexOf(queryWithSpace)) > -1) {
relevance = 50;
matchPositionEnd = matchPositionStart + queryWithSpace.length();
} else if ((matchPositionStart = shortcutNameLowerCased.indexOf(query)) > -1) {
relevance = 1;
matchPositionEnd = matchPositionStart + query.length();
}
if (relevance > 0) {
shortcut.setDisplayNameHighlightRegion(matchPositionStart, matchPositionEnd);
shortcut.relevance = relevance;
results.add(shortcut);
}
}
return results;
}
Aggregations