use of org.apache.cxf.rs.security.cors.CrossOriginResourceSharing in project cxf by apache.
the class Catalog method findBook.
@GET
@Produces(MediaType.APPLICATION_JSON)
@CrossOriginResourceSharing(allowAllOrigins = true)
@Path("/search")
public Response findBook(@Context SearchContext searchContext, @Context final UriInfo uri) throws IOException {
final IndexReader reader = DirectoryReader.open(directory);
final IndexSearcher searcher = new IndexSearcher(reader);
final JsonArrayBuilder builder = Json.createArrayBuilder();
try {
visitor.reset();
visitor.visit(searchContext.getCondition(SearchBean.class));
final Query query = visitor.getQuery();
if (query != null) {
final TopDocs topDocs = searcher.search(query, 1000);
for (final ScoreDoc scoreDoc : topDocs.scoreDocs) {
final Document document = reader.document(scoreDoc.doc);
final String source = document.getField(LuceneDocumentMetadata.SOURCE_FIELD).stringValue();
builder.add(Json.createObjectBuilder().add("source", source).add("score", scoreDoc.score).add("url", uri.getBaseUriBuilder().path(Catalog.class).path(source).build().toString()));
}
}
return Response.ok(builder.build()).build();
} finally {
reader.close();
}
}
Aggregations