@SuppressWarnings("unchecked")
public static Tube getById(String id) {
try {
initCache();
String prefix = cachePrefix + "id_" + id;
Tube obj = new Tube();
if (cache != null && cache.containsKey(prefix)) {
obj = (Tube) cache.get(prefix);
} else {
QueryOptions options = QueryOptions.newBuilder().setLimit(1)
.build();
Query query = Query.newBuilder().setOptions(options)
.build("id:\"" + id + "\"");
Results<ScoredDocument> docResult = INDEX.search(query);
if (docResult.getNumberFound() > 0) {
for (ScoredDocument scoredDocument : docResult) {
obj = TubeSearchEngine
.documentToObjectByReflection(scoredDocument);
}
}
if (obj != null && obj.getId().length() > 0) {
cache.put(prefix, obj);
} else {
obj = null;
}
}