return getSearcher().hasChanges(docid);
}
@Override
public SearchResults search(Query query, int start, int limit, int scoringFunctionIndex, Map<String, String> extraParameters) throws InterruptedException {
TopMatches matches = this.findMatches(query, start+limit, scoringFunctionIndex);
Iterable<ScoredMatch> ids = matches;
// apply pagination
ids = SkippingIterable.skipping(ids, start);
ids = CollectionsUtil.limit(ids, limit);
// base transform function
final Function<ScoredMatch, SearchResult> baseTransform = ScoredMatch.SEARCH_RESULT_FUNCTION;
Function<ScoredMatch, SearchResult> transformFunction = baseTransform;
String fetchCategories = extraParameters.get("fetch_categories");
String fetchVariables = extraParameters.get("fetch_variables");
// adds fetch variables to the transform function
if ("*".equals(fetchVariables) || "true".equalsIgnoreCase(fetchVariables)) {
transformFunction = new Function<ScoredMatch, SearchResult>() {
@Override
public SearchResult apply(ScoredMatch scoredMatch) {
SearchResult searchResult = baseTransform.apply(scoredMatch);
searchResult.setVariables(boostsManager.getVariablesAsMap(scoredMatch.getDocId()));
return searchResult;
}
};
}
// adds fetch categories to the transform function
final Function<ScoredMatch, SearchResult> prevTransform = transformFunction;
if ("*".equals(fetchCategories) || "true".equalsIgnoreCase(fetchCategories)) {
transformFunction = new Function<ScoredMatch, SearchResult>() {
@Override
public SearchResult apply(ScoredMatch scoredMatch) {
SearchResult searchResult = prevTransform.apply(scoredMatch);
searchResult.setCategories(boostsManager.getCategoryValues(scoredMatch.getDocId()));
return searchResult;
}
};
}
// convert to search results
Iterable<SearchResult> results = Iterables.transform(ids, transformFunction);
// fix'em in a list
results = Lists.newArrayList(results);
return new SearchResults(results, matches.getTotalMatches(), matches.getFacetingResults());
}