Search in sources :

Example 1 with InverseSearchSliceResult

use of com.rbmhtechnology.vind.api.result.InverseSearchSliceResult in project vind by RBMHTechnology.

the class ElasticSearchServer method execute.

@Override
public InverseSearchResult execute(InverseSearch inverseSearch, DocumentFactory documentFactory) {
    final StopWatch elapsedtime = StopWatch.createStarted();
    final List<Map<String, Object>> mapDocs = inverseSearch.getDocs().parallelStream().map(DocumentUtil::createInputDocument).collect(Collectors.toList());
    final QueryBuilder query = ElasticQueryBuilder.buildFilterQuery(inverseSearch.getQueryFilter(), documentFactory, null, currentFootprint);
    // query
    try {
        elasticClientLogger.debug(">>> query({})", query.toString());
        // TODO: inverse search support multiple docs
        final SearchResponse response = elasticSearchClient.percolatorDocQuery(mapDocs, query);
        if (Objects.nonNull(response) && Objects.nonNull(response.getHits()) && Objects.nonNull(response.getHits().getHits())) {
            final List<InverseSearchQuery> resultQueries = Arrays.stream(response.getHits().getHits()).map(hit -> DocumentUtil.buildVindDoc(hit, InverseSearchQueryFactory.getQueryFactory(), null)).map(doc -> documentFactory.createInverseSearchQuery(doc.getId(), deserializeByteArrayFilter(((ByteBuffer) doc.getValue(InverseSearchQueryFactory.BINARY_QUERY_FIELD)).array()))).collect(Collectors.toList());
            elapsedtime.stop();
            final long totalHits = response.getHits().getTotalHits().value;
            switch(inverseSearch.getResultSet().getType()) {
                case page:
                    {
                        return new InverseSearchPageResult(totalHits, response.getTook().getMillis(), resultQueries, inverseSearch, this, documentFactory).setElapsedTime(elapsedtime.getTime());
                    }
                case slice:
                    {
                        return new InverseSearchSliceResult(totalHits, response.getTook().getMillis(), resultQueries, inverseSearch, this, documentFactory).setElapsedTime(elapsedtime.getTime());
                    }
                default:
                    return new InverseSearchPageResult(totalHits, response.getTook().getMillis(), resultQueries, inverseSearch, this, documentFactory).setElapsedTime(elapsedtime.getTime());
            }
        } else {
            throw new ElasticsearchException("Empty result from ElasticClient");
        }
    } catch (ElasticsearchException | IOException e) {
        throw new SearchServerException(String.format("Cannot issue inverse search: %s", e.getMessage()), e);
    }
}
Also used : ElasticsearchException(org.elasticsearch.ElasticsearchException) PageResult(com.rbmhtechnology.vind.api.result.PageResult) Arrays(java.util.Arrays) Delete(com.rbmhtechnology.vind.api.query.delete.Delete) InverseSearchSliceResult(com.rbmhtechnology.vind.api.result.InverseSearchSliceResult) FieldUtil(com.rbmhtechnology.vind.elasticsearch.backend.util.FieldUtil) SearchServerException(com.rbmhtechnology.vind.SearchServerException) LoggerFactory(org.slf4j.LoggerFactory) ObjectInputStream(java.io.ObjectInputStream) Asserts(org.apache.http.util.Asserts) QueryBuilders(org.elasticsearch.index.query.QueryBuilders) DocumentUtil(com.rbmhtechnology.vind.elasticsearch.backend.util.DocumentUtil) ByteBuffer(java.nio.ByteBuffer) ByteArrayInputStream(java.io.ByteArrayInputStream) FulltextSearch(com.rbmhtechnology.vind.api.query.FulltextSearch) UpdateResponse(org.elasticsearch.action.update.UpdateResponse) Map(java.util.Map) SearchResponse(org.elasticsearch.action.search.SearchResponse) DocumentUtil.createEmptyDocument(com.rbmhtechnology.vind.elasticsearch.backend.util.DocumentUtil.createEmptyDocument) DeleteResponse(org.elasticsearch.action.delete.DeleteResponse) TypeReference(com.fasterxml.jackson.core.type.TypeReference) Failure(org.elasticsearch.action.bulk.BulkItemResponse.Failure) ElasticQueryBuilder(com.rbmhtechnology.vind.elasticsearch.backend.util.ElasticQueryBuilder) InverseSearch(com.rbmhtechnology.vind.api.query.inverseSearch.InverseSearch) InverseSearchQueryFactory(com.rbmhtechnology.vind.api.query.inverseSearch.InverseSearchQueryFactory) SearchResult(com.rbmhtechnology.vind.api.result.SearchResult) MultiGetResponse(org.elasticsearch.action.get.MultiGetResponse) AnnotationUtil(com.rbmhtechnology.vind.annotations.AnnotationUtil) BulkItemResponse(org.elasticsearch.action.bulk.BulkItemResponse) Update(com.rbmhtechnology.vind.api.query.update.Update) Collection(java.util.Collection) BulkResponse(org.elasticsearch.action.bulk.BulkResponse) ServiceLoader(java.util.ServiceLoader) StopWatch(org.apache.commons.lang3.time.StopWatch) GetResult(com.rbmhtechnology.vind.api.result.GetResult) Collectors(java.util.stream.Collectors) SuggestionResult(com.rbmhtechnology.vind.api.result.SuggestionResult) Objects(java.util.Objects) RealTimeGet(com.rbmhtechnology.vind.api.query.get.RealTimeGet) CursorResult(com.rbmhtechnology.vind.api.result.CursorResult) List(java.util.List) Stream(java.util.stream.Stream) InverseSearchResult(com.rbmhtechnology.vind.api.result.InverseSearchResult) ValidateQueryResponse(org.elasticsearch.action.admin.indices.validate.query.ValidateQueryResponse) ServiceProvider(com.rbmhtechnology.vind.api.ServiceProvider) ElasticVindClient(com.rbmhtechnology.vind.elasticsearch.backend.client.ElasticVindClient) BeanGetResult(com.rbmhtechnology.vind.api.result.BeanGetResult) NotImplementedException(org.apache.commons.lang3.NotImplementedException) SpecialCharacterEscaping.escapeSpecialCharacters(com.rbmhtechnology.vind.utils.SpecialCharacterEscaping.escapeSpecialCharacters) ExecutableSuggestionSearch(com.rbmhtechnology.vind.api.query.suggestion.ExecutableSuggestionSearch) IndexResult(com.rbmhtechnology.vind.api.result.IndexResult) FieldDescriptor(com.rbmhtechnology.vind.model.FieldDescriptor) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SliceResult(com.rbmhtechnology.vind.api.result.SliceResult) CollectionUtils(org.apache.commons.collections.CollectionUtils) PainlessScript(com.rbmhtechnology.vind.elasticsearch.backend.util.PainlessScript) SearchSourceBuilder(org.elasticsearch.search.builder.SearchSourceBuilder) StatusResult(com.rbmhtechnology.vind.api.result.StatusResult) SmartSearchServerBase(com.rbmhtechnology.vind.api.SmartSearchServerBase) BeanSearchResult(com.rbmhtechnology.vind.api.result.BeanSearchResult) BulkByScrollResponse(org.elasticsearch.index.reindex.BulkByScrollResponse) SearchServerInstantiateException(com.rbmhtechnology.vind.SearchServerInstantiateException) TermFacetResult(com.rbmhtechnology.vind.api.result.facet.TermFacetResult) SearchConfiguration(com.rbmhtechnology.vind.configure.SearchConfiguration) InverseSearchQuery(com.rbmhtechnology.vind.model.InverseSearchQuery) DeleteResult(com.rbmhtechnology.vind.api.result.DeleteResult) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) FacetResults(com.rbmhtechnology.vind.api.result.FacetResults) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) DivisionType.cursor(com.rbmhtechnology.vind.api.query.division.ResultSubset.DivisionType.cursor) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IOException(java.io.IOException) Document(com.rbmhtechnology.vind.api.Document) InverseSearchPageResult(com.rbmhtechnology.vind.api.result.InverseSearchPageResult) ElasticMappingUtils(com.rbmhtechnology.vind.elasticsearch.backend.util.ElasticMappingUtils) TimeUnit(java.util.concurrent.TimeUnit) ResultUtils(com.rbmhtechnology.vind.elasticsearch.backend.util.ResultUtils) DocumentFactory(com.rbmhtechnology.vind.model.DocumentFactory) SearchServerProviderLoaderException(com.rbmhtechnology.vind.SearchServerProviderLoaderException) Cursor(com.rbmhtechnology.vind.api.query.division.Cursor) Filter(com.rbmhtechnology.vind.api.query.filter.Filter) Collections(java.util.Collections) InverseSearchSliceResult(com.rbmhtechnology.vind.api.result.InverseSearchSliceResult) InverseSearchQuery(com.rbmhtechnology.vind.model.InverseSearchQuery) ElasticQueryBuilder(com.rbmhtechnology.vind.elasticsearch.backend.util.ElasticQueryBuilder) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) ElasticsearchException(org.elasticsearch.ElasticsearchException) IOException(java.io.IOException) ByteBuffer(java.nio.ByteBuffer) StopWatch(org.apache.commons.lang3.time.StopWatch) SearchResponse(org.elasticsearch.action.search.SearchResponse) InverseSearchPageResult(com.rbmhtechnology.vind.api.result.InverseSearchPageResult) Map(java.util.Map) HashMap(java.util.HashMap) SearchServerException(com.rbmhtechnology.vind.SearchServerException)

Aggregations

TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 SearchServerException (com.rbmhtechnology.vind.SearchServerException)1 SearchServerInstantiateException (com.rbmhtechnology.vind.SearchServerInstantiateException)1 SearchServerProviderLoaderException (com.rbmhtechnology.vind.SearchServerProviderLoaderException)1 AnnotationUtil (com.rbmhtechnology.vind.annotations.AnnotationUtil)1 Document (com.rbmhtechnology.vind.api.Document)1 ServiceProvider (com.rbmhtechnology.vind.api.ServiceProvider)1 SmartSearchServerBase (com.rbmhtechnology.vind.api.SmartSearchServerBase)1 FulltextSearch (com.rbmhtechnology.vind.api.query.FulltextSearch)1 Delete (com.rbmhtechnology.vind.api.query.delete.Delete)1 Cursor (com.rbmhtechnology.vind.api.query.division.Cursor)1 DivisionType.cursor (com.rbmhtechnology.vind.api.query.division.ResultSubset.DivisionType.cursor)1 Filter (com.rbmhtechnology.vind.api.query.filter.Filter)1 RealTimeGet (com.rbmhtechnology.vind.api.query.get.RealTimeGet)1 InverseSearch (com.rbmhtechnology.vind.api.query.inverseSearch.InverseSearch)1 InverseSearchQueryFactory (com.rbmhtechnology.vind.api.query.inverseSearch.InverseSearchQueryFactory)1 ExecutableSuggestionSearch (com.rbmhtechnology.vind.api.query.suggestion.ExecutableSuggestionSearch)1 Update (com.rbmhtechnology.vind.api.query.update.Update)1 BeanGetResult (com.rbmhtechnology.vind.api.result.BeanGetResult)1