use of org.apache.lucene.document.DocumentStoredFieldVisitor in project cxf by apache.
the class Catalog method getBooks.
// CHECKSTYLE:ON: ReturnCount
@GET
@Produces(MediaType.APPLICATION_JSON)
public JsonArray getBooks() throws IOException {
final IndexReader reader = DirectoryReader.open(directory);
final IndexSearcher searcher = new IndexSearcher(reader);
final JsonArrayBuilder builder = Json.createArrayBuilder();
try {
final Query query = new MatchAllDocsQuery();
for (final ScoreDoc scoreDoc : searcher.search(query, 1000).scoreDocs) {
final DocumentStoredFieldVisitor fieldVisitor = new DocumentStoredFieldVisitor(LuceneDocumentMetadata.SOURCE_FIELD);
reader.document(scoreDoc.doc, fieldVisitor);
builder.add(fieldVisitor.getDocument().getField(LuceneDocumentMetadata.SOURCE_FIELD).stringValue());
}
return builder.build();
} finally {
reader.close();
}
}
Aggregations