query = Query.newBuilder().setOptions(options)
.build(queryString.toString());
docResult = INDEX.search(query);
if (docResult.getNumberFound() > 0) {
Tube tub = new Tube();
for (ScoredDocument scoredDocument : docResult) {
tub = TubeSearchEngine
.documentToObjectByReflection(scoredDocument);
keyPool.add(tub.getId());
}
}
cache.put(playlistKeyPoolPrefix, keyPool);
}
// get list id random from pool
List<String> relateKey = new ArrayList<String>();
if (keyPool.size() > 20) {
System.out.println(">20");
Random randomGenerator = new Random();
int index = randomGenerator
.nextInt((int) (keyPool.size() / 2));
relateKey = keyPool.subList(index, (index + 10));
} else if (keyPool.size() < 5) {
System.out.println("<5");
options = QueryOptions.newBuilder().setLimit(10).build();
query = Query.newBuilder().setOptions(options).build("");
docResult = INDEX.search(query);
if (docResult.getNumberFound() > 0) {
Tube tub = new Tube();
for (ScoredDocument scoredDocument : docResult) {
tub = TubeSearchEngine
.documentToObjectByReflection(scoredDocument);
relateKey.add(tub.getId());
}
}
} else {
System.out.println(">5<20");
relateKey = keyPool;
}
for (String string : relateKey) {
Tube tub = getById(string);
if (tub != null) {
listResult.add(tub);
}
}
if (listResult.size() > 0) {