List of usage examples for org.apache.commons.collections MapUtils getIntValue
public static int getIntValue(final Map map, final Object key)
From source file:grails.plugin.searchable.internal.compass.search.DefaultSearchableSubsetHitCollector.java
/** * Collect and return the subset of hits with the range offset..offset + max * * @param hits/*w w w . j a v a 2 s. com*/ * @param options * @return */ @Override public Object collect(CompassHits hits, boolean reload, Map options) { if (hits.length() == 0) { return Collections.EMPTY_LIST; } int offset = MapUtils.getIntValue(options, "offset"); int max = MapUtils.getIntValue(options, "max"); List collectedHits = new ArrayList(max); int low = offset; int high = Math.min(low + max, hits.length()); while (low < high) { collectedHits.add(getObject(hits.data(low++), reload)); } return collectedHits; }
From source file:grails.plugin.searchable.internal.compass.search.SearchableSubsetSearchResultFactory.java
public Object buildSearchResult(final CompassHits hits, final Object collectedHits, final Object collectedCompassHits, Map options) { final int offset = MapUtils.getIntValue(options, "offset"); final int max = MapUtils.getIntValue(options, "max"); final List scores = new ArrayList(max); for (int i = offset; i < Math.min(offset + max, hits.length()); i++) { scores.add(i - offset, Float.valueOf(hits.score(i))); }/*from ww w .j a v a2s .c o m*/ Map map = new HashMap(); map.put("offset", offset); map.put("max", max); map.put("results", collectedHits); map.put("scores", scores); map.put("total", hits.length()); //need to return the compass hits also! map.put("hits", collectedCompassHits); return map; }
From source file:org.codehaus.groovy.grails.plugins.searchable.compass.search.DefaultSearchableSubsetHitCollector.java
/** * Collect and return the subset of hits with the range offset..offset + max * /* w w w . j a v a 2s .co m*/ * @param hits * @param options * @return */ public Object collect(CompassHits hits, boolean reload, Map options) { if (hits.length() == 0) { return Collections.EMPTY_LIST; } int offset = MapUtils.getIntValue(options, "offset"); int max = MapUtils.getIntValue(options, "max"); List collectedHits = new ArrayList(max); int low = offset; int high = Math.min(low + max, hits.length()); while (low < high) { collectedHits.add(getObject(hits.data(low++), reload)); } return collectedHits; }
From source file:org.codehaus.groovy.grails.plugins.searchable.compass.search.SearchableSubsetSearchResultFactory.java
public Object buildSearchResult(final CompassHits hits, final Object collectedHits, Map options) { final int offset = MapUtils.getIntValue(options, "offset"); final int max = MapUtils.getIntValue(options, "max"); final List scores = new ArrayList(max); for (int i = offset; i < Math.min(offset + max, hits.length()); i++) { scores.add(i - offset, new Float(hits.score(i))); // "new Float" instead of "Float.valueOf" for 1.4 compatibility }//from w w w. j a va2 s.co m return new HashMap() { { put("offset", new Integer(offset)); put("max", new Integer(max)); put("results", collectedHits); put("scores", scores); put("total", new Integer(hits.length())); } }; }