use of com.couchbase.client.core.error.FeatureNotAvailableException in project couchbase-jvm-clients by couchbase.
the class AsyncSearchIndexManager method analyzeDocument.
/**
* Allows to see how a document is analyzed against a specific index.
*
* @param name the name of the search index.
* @param document the document to analyze.
* @return a {@link CompletableFuture} with analyzed document parts once complete.
*/
public CompletableFuture<List<JsonObject>> analyzeDocument(final String name, final JsonObject document, final AnalyzeDocumentOptions options) {
notNullOrEmpty(name, "Search Index Name");
notNull(document, "Document");
return searchHttpClient.post(path(analyzeDocumentPath(name)), options.build()).trace(TracingIdentifiers.SPAN_REQUEST_MS_ANALYZE_DOCUMENT).json(Mapper.encodeAsBytes(document.toMap())).exec(core).exceptionally(throwable -> {
if (throwable.getMessage().contains("Page not found")) {
throw new FeatureNotAvailableException("Document analysis is not available on this server version!");
} else if (throwable instanceof RuntimeException) {
throw (RuntimeException) throwable;
} else {
throw new CouchbaseException("Failed to analyze search document", throwable);
}
}).thenApply(response -> {
JsonNode rootNode = Mapper.decodeIntoTree(response.content());
List<Map<String, Object>> analyzed = Mapper.convertValue(rootNode.get("analyzed"), new TypeReference<List<Map<String, Object>>>() {
});
return analyzed.stream().filter(Objects::nonNull).map(JsonObject::from).collect(Collectors.toList());
});
}
use of com.couchbase.client.core.error.FeatureNotAvailableException in project couchbase-jvm-clients by couchbase.
the class QueryIntegrationTest method preserveExpiryThrowsFeatureNotAvailable.
@Test
@IgnoreWhen(hasCapabilities = Capabilities.QUERY_PRESERVE_EXPIRY)
void preserveExpiryThrowsFeatureNotAvailable() {
FeatureNotAvailableException ex = assertThrows(FeatureNotAvailableException.class, () -> cluster.query("select 1=1", queryOptions().preserveExpiry(true)));
assertTrue(ex.getMessage().contains("Preserving expiry for the query service is not supported"));
}
Aggregations