All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.ravendb.client.documents.session.DocumentQuery Maven / Gradle / Ivy

package net.ravendb.client.documents.session;

import com.fasterxml.jackson.databind.node.ObjectNode;
import com.google.common.collect.Sets;
import net.ravendb.client.Constants;
import net.ravendb.client.Parameters;
import net.ravendb.client.documents.indexes.spatial.SpatialRelation;
import net.ravendb.client.documents.indexes.spatial.SpatialUnits;
import net.ravendb.client.documents.queries.*;
import net.ravendb.client.documents.queries.explanation.ExplanationOptions;
import net.ravendb.client.documents.queries.explanation.Explanations;
import net.ravendb.client.documents.queries.facets.*;
import net.ravendb.client.documents.queries.highlighting.HighlightingOptions;
import net.ravendb.client.documents.queries.highlighting.Highlightings;
import net.ravendb.client.documents.queries.moreLikeThis.*;
import net.ravendb.client.documents.queries.spatial.DynamicSpatialField;
import net.ravendb.client.documents.queries.spatial.SpatialCriteria;
import net.ravendb.client.documents.queries.spatial.SpatialCriteriaFactory;
import net.ravendb.client.documents.queries.suggestions.*;
import net.ravendb.client.documents.queries.timeSeries.ITimeSeriesQueryBuilder;
import net.ravendb.client.documents.queries.timings.QueryTimings;
import net.ravendb.client.documents.session.loaders.IQueryIncludeBuilder;
import net.ravendb.client.documents.session.loaders.QueryIncludeBuilder;
import net.ravendb.client.documents.session.tokens.DeclareToken;
import net.ravendb.client.documents.session.tokens.FieldsToFetchToken;
import net.ravendb.client.documents.session.tokens.LoadToken;
import net.ravendb.client.primitives.Reference;
import org.apache.commons.lang3.ObjectUtils;

import java.beans.IntrospectionException;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.lang.reflect.Field;
import java.time.Duration;
import java.util.*;
import java.util.function.Consumer;
import java.util.function.Function;

public class DocumentQuery extends AbstractDocumentQuery> implements IDocumentQuery, IAbstractDocumentQueryImpl {

    public DocumentQuery(Class clazz, InMemoryDocumentSessionOperations session, String indexName,
                         String collectionName, boolean isGroupBy) {
        this(clazz, session, indexName, collectionName, isGroupBy, null, null, null, null);
    }

    public DocumentQuery(Class clazz, InMemoryDocumentSessionOperations session, String indexName,
                         String collectionName, boolean isGroupBy,
                         List declareTokens, List loadTokens, String fromAlias) {
        this(clazz, session, indexName, collectionName, isGroupBy, declareTokens, loadTokens, fromAlias, null);
    }

    public DocumentQuery(Class clazz, InMemoryDocumentSessionOperations session, String indexName,
                         String collectionName, boolean isGroupBy, List declareTokens,
                         List loadTokens, String fromAlias, Boolean isProjectInto) {
        super(clazz, session, indexName, collectionName, isGroupBy, declareTokens, loadTokens, fromAlias, isProjectInto);
    }

    public  IDocumentQuery selectFields(Class projectionClass) {
        return selectFields(projectionClass, ProjectionBehavior.DEFAULT);
    }

    @Override
    public  IDocumentQuery selectFields(Class projectionClass, ProjectionBehavior projectionBehavior) {
        try {
            PropertyDescriptor[] propertyDescriptors = Introspector.getBeanInfo(projectionClass).getPropertyDescriptors();

            String[] projections = Arrays.stream(propertyDescriptors)
                    .filter(x -> !Object.class.equals(x.getReadMethod().getDeclaringClass())) // ignore class field etc,
                    .map(x -> x.getName())
                    .toArray(String[]::new);

            String[] fields = Arrays.stream(propertyDescriptors)
                    .filter(x -> !Object.class.equals(x.getReadMethod().getDeclaringClass())) // ignore class field etc,
                    .map(x -> x.getName())
                    .toArray(String[]::new);


            QueryData queryData = new QueryData(fields, projections);
            queryData.setProjectInto(true);
            queryData.setProjectionBehavior(projectionBehavior);
            return selectFields(projectionClass, queryData);
        } catch (IntrospectionException e) {
            throw new RuntimeException("Unable to project to class: " + projectionClass.getName() + e.getMessage(), e);
        }
    }

    @Override
    public  IDocumentQuery selectTimeSeries(Class clazz, Consumer timeSeriesQuery) {
        QueryData queryData = createTimeSeriesQueryData(timeSeriesQuery);
        return selectFields(clazz, queryData);
    }

    @Override
    public IDocumentQuery distinct() {
        _distinct();
        return this;
    }

    @Override
    public IDocumentQuery orderByScore() {
        _orderByScore();
        return this;
    }

    @Override
    public IDocumentQuery orderByScoreDescending() {
        _orderByScoreDescending();
        return this;
    }

    @Override
    public IDocumentQuery includeExplanations(Reference explanations) {
        _includeExplanations(null, explanations);
        return this;
    }

    @Override
    public IDocumentQuery includeExplanations(ExplanationOptions options, Reference explanations) {
        _includeExplanations(options, explanations);
        return this;
    }

    @Override
    public IDocumentQuery timings(Reference timings) {
        _includeTimings(timings);
        return this;
    }

    @Override
    public  IDocumentQuery selectFields(Class projectionClass, String... fields) {
        return selectFields(projectionClass, ProjectionBehavior.DEFAULT, fields);
    }

    @Override
    public  IDocumentQuery selectFields(Class projectionClass, ProjectionBehavior projectionBehavior, String... fields) {
        QueryData queryData = new QueryData(fields, fields);
        queryData.setProjectInto(true);
        queryData.setProjectionBehavior(projectionBehavior);

        IDocumentQuery selectFields = selectFields(projectionClass, queryData);
        return selectFields;
    }

    @Override
    public  IDocumentQuery selectFields(Class projectionClass, QueryData queryData) {
        queryData.setProjectInto(true);
        return createDocumentQueryInternal(projectionClass, queryData);
    }

    @Override
    public IDocumentQuery waitForNonStaleResults() {
        _waitForNonStaleResults(null);
        return this;
    }

    @Override
    public IDocumentQuery waitForNonStaleResults(Duration waitTimeout) {
        _waitForNonStaleResults(waitTimeout);
        return this;
    }

    @Override
    public IDocumentQuery addParameter(String name, Object value) {
        _addParameter(name, value);
        return this;
    }

    @Override
    public IDocumentQuery addOrder(String fieldName, boolean descending) {
        return addOrder(fieldName, descending, OrderingType.STRING);
    }

    @Override
    public IDocumentQuery addOrder(String fieldName, boolean descending, OrderingType ordering) {
        if (descending) {
            orderByDescending(fieldName, ordering);
        } else {
            orderBy(fieldName, ordering);
        }
        return this;
    }

    //TBD expr public IDocumentQuery AddOrder(Expression> propertySelector, bool descending, OrderingType ordering)


    @Override
    public IDocumentQuery addAfterQueryExecutedListener(Consumer action) {
        _addAfterQueryExecutedListener(action);
        return this;
    }

    @Override
    public IDocumentQuery removeAfterQueryExecutedListener(Consumer action) {
        _removeAfterQueryExecutedListener(action);
        return this;
    }

    @Override
    public IDocumentQuery addAfterStreamExecutedListener(Consumer action) {
        _addAfterStreamExecutedListener(action);
        return this;
    }

    @Override
    public IDocumentQuery removeAfterStreamExecutedListener(Consumer action) {
        _removeAfterStreamExecutedListener(action);
        return this;
    }

    public IDocumentQuery openSubclause() {
        _openSubclause();
        return this;
    }

    @Override
    public IDocumentQuery closeSubclause() {
        _closeSubclause();
        return this;
    }

    @Override
    public IDocumentQuery negateNext() {
        _negateNext();
        return this;
    }

    @Override
    public IDocumentQuery search(String fieldName, String searchTerms) {
        _search(fieldName, searchTerms);
        return this;
    }

    @Override
    public IDocumentQuery search(String fieldName, String searchTerms, SearchOperator operator) {
        _search(fieldName, searchTerms, operator);
        return this;
    }

    //TBD expr public IDocumentQuery Search(Expression> propertySelector, string searchTerms, SearchOperator @operator)

    @Override
    public IDocumentQuery intersect() {
        _intersect();
        return this;
    }

    @Override
    public IDocumentQuery containsAny(String fieldName, Collection values) {
        _containsAny(fieldName, values);
        return this;
    }

    //TBD expr public IDocumentQuery ContainsAny(Expression> propertySelector, IEnumerable values)

    @Override
    public IDocumentQuery containsAll(String fieldName, Collection values) {
        _containsAll(fieldName, values);
        return this;
    }

    //TBD expr public IDocumentQuery ContainsAll(Expression> propertySelector, IEnumerable values)

    @Override
    public IDocumentQuery statistics(Reference stats) {
        _statistics(stats);
        return this;
    }

    @Override
    public IDocumentQuery usingDefaultOperator(QueryOperator queryOperator) {
        _usingDefaultOperator(queryOperator);
        return this;
    }

    @Override
    public IDocumentQuery noTracking() {
        _noTracking();
        return this;
    }

    @Override
    public IDocumentQuery noCaching() {
        _noCaching();
        return this;
    }

    @Override
    public IDocumentQuery include(String path) {
        _include(path);
        return this;
    }

    @Override
    public IDocumentQuery include(Consumer includes) {
        QueryIncludeBuilder includeBuilder = new QueryIncludeBuilder(getConventions());
        includes.accept(includeBuilder);
        _include(includeBuilder);
        return this;
    }

    //TBD expr IDocumentQuery IDocumentQueryBase>.Include(Expression> path)

    @Override
    public IDocumentQuery not() {
        negateNext();
        return this;
    }

    @Override
    public IDocumentQuery take(int count) {
        _take(count);
        return this;
    }

    public IDocumentQuery skip(int count) {
        _skip(count);
        return this;
    }

    @Override
    public IDocumentQuery whereLucene(String fieldName, String whereClause) {
        _whereLucene(fieldName, whereClause, false);
        return this;
    }

    @Override
    public IDocumentQuery whereLucene(String fieldName, String whereClause, boolean exact) {
        _whereLucene(fieldName, whereClause, exact);
        return this;
    }

    @Override
    public IDocumentQuery whereEquals(String fieldName, Object value) {
        _whereEquals(fieldName, value, false);
        return this;
    }

    @Override
    public IDocumentQuery whereEquals(String fieldName, Object value, boolean exact) {
        _whereEquals(fieldName, value, exact);
        return this;
    }

    @Override
    public IDocumentQuery whereEquals(String fieldName, MethodCall method) {
        _whereEquals(fieldName, method);
        return this;
    }

    @Override
    public IDocumentQuery whereEquals(String fieldName, MethodCall method, boolean exact) {
        _whereEquals(fieldName, method, exact);
        return this;
    }

    //TBD expr IDocumentQuery IDocumentQueryBase>.WhereEquals(Expression> propertySelector, TValue value, bool exact)
    //TBD expr IDocumentQuery IFilterDocumentQueryBase>.WhereEquals(Expression> propertySelector, MethodCall value, bool exact)

    @Override
    public IDocumentQuery whereEquals(WhereParams whereParams) {
        _whereEquals(whereParams);
        return this;
    }

    @Override
    public IDocumentQuery whereNotEquals(String fieldName, Object value) {
        _whereNotEquals(fieldName, value);
        return this;
    }

    @Override
    public IDocumentQuery whereNotEquals(String fieldName, Object value, boolean exact) {
        _whereNotEquals(fieldName, value, exact);
        return this;
    }

    @Override
    public IDocumentQuery whereNotEquals(String fieldName, MethodCall method) {
        _whereNotEquals(fieldName, method);
        return this;
    }

    @Override
    public IDocumentQuery whereNotEquals(String fieldName, MethodCall method, boolean exact) {
        _whereNotEquals(fieldName, method, exact);
        return this;
    }

    //TBD expr IDocumentQuery IDocumentQueryBase>.WhereNotEquals(Expression> propertySelector, TValue value, bool exact)
    //TBD expr IDocumentQuery IFilterDocumentQueryBase>.WhereNotEquals(Expression> propertySelector, MethodCall value, bool exact)

    @Override
    public IDocumentQuery whereNotEquals(WhereParams whereParams) {
        _whereNotEquals(whereParams);
        return this;
    }

    @Override
    public IDocumentQuery whereIn(String fieldName, Collection values) {
        return whereIn(fieldName, values, false);
    }

    @Override
    public IDocumentQuery whereIn(String fieldName, Collection values, boolean exact) {
        _whereIn(fieldName, values, exact);
        return this;
    }

    //TBD expr public IDocumentQuery WhereIn(Expression> propertySelector, IEnumerable values, bool exact = false)

    @Override
    public IDocumentQuery whereStartsWith(String fieldName, Object value) {
        return whereStartsWith(fieldName, value, false);
    }

    @Override
    public IDocumentQuery whereStartsWith(String fieldName, Object value, boolean exact) {
        _whereStartsWith(fieldName, value, exact);
        return this;
    }

    @Override
    public IDocumentQuery whereEndsWith(String fieldName, Object value) {
        return whereEndsWith(fieldName, value, false);
    }

    @Override
    public IDocumentQuery whereEndsWith(String fieldName, Object value, boolean exact) {
        _whereEndsWith(fieldName, value, exact);
        return this;
    }

    //TBD expr public IDocumentQuery WhereEndsWith(Expression> propertySelector, TValue value)

    @Override
    public IDocumentQuery whereBetween(String fieldName, Object start, Object end) {
        return whereBetween(fieldName, start, end, false);
    }

    @Override
    public IDocumentQuery whereBetween(String fieldName, Object start, Object end, boolean exact) {
        _whereBetween(fieldName, start, end, exact);
        return this;
    }

    //TBD expr public IDocumentQuery WhereBetween(Expression> propertySelector, TValue start, TValue end, bool exact = false)

    @Override
    public IDocumentQuery whereGreaterThan(String fieldName, Object value) {
        return whereGreaterThan(fieldName, value, false);
    }

    @Override
    public IDocumentQuery whereGreaterThan(String fieldName, Object value, boolean exact) {
        _whereGreaterThan(fieldName, value, exact);
        return this;
    }

    @Override
    public IDocumentQuery whereGreaterThanOrEqual(String fieldName, Object value) {
        return whereGreaterThanOrEqual(fieldName, value, false);
    }

    @Override
    public IDocumentQuery whereGreaterThanOrEqual(String fieldName, Object value, boolean exact) {
        _whereGreaterThanOrEqual(fieldName, value, exact);
        return this;
    }

    //TBD expr public IDocumentQuery WhereGreaterThan(Expression> propertySelector, TValue value, bool exact = false)
    //TBD expr public IDocumentQuery WhereGreaterThanOrEqual(Expression> propertySelector, TValue value, bool exact = false)

    public IDocumentQuery whereLessThan(String fieldName, Object value) {
        return whereLessThan(fieldName, value, false);
    }

    public IDocumentQuery whereLessThan(String fieldName, Object value, boolean exact) {
        _whereLessThan(fieldName, value, exact);
        return this;
    }

    //TBD expr public IDocumentQuery WhereLessThanOrEqual(Expression> propertySelector, TValue value, bool exact = false)

    public IDocumentQuery whereLessThanOrEqual(String fieldName, Object value) {
        return whereLessThanOrEqual(fieldName, value, false);
    }

    public IDocumentQuery whereLessThanOrEqual(String fieldName, Object value, boolean exact) {
        _whereLessThanOrEqual(fieldName, value, exact);
        return this;
    }

    //TBD expr public IDocumentQuery WhereLessThanOrEqual(Expression> propertySelector, TValue value, bool exact = false)
    //TBD expr public IDocumentQuery WhereExists(Expression> propertySelector)

    @Override
    public IDocumentQuery whereExists(String fieldName) {
        _whereExists(fieldName);
        return this;
    }

    //TBD expr IDocumentQuery IFilterDocumentQueryBase>.WhereRegex(Expression> propertySelector, string pattern)
    @Override
    public IDocumentQuery whereRegex(String fieldName, String pattern) {
        _whereRegex(fieldName, pattern);
        return this;
    }

    public IDocumentQuery andAlso() {
        _andAlso();
        return this;
    }

    @Override
    public IDocumentQuery andAlso(boolean wrapPreviousQueryClauses) {
        _andAlso(wrapPreviousQueryClauses);
        return this;
    }

    @Override
    public IDocumentQuery orElse() {
        _orElse();
        return this;
    }

    @Override
    public IDocumentQuery boost(double boost) {
        _boost(boost);
        return this;
    }

    @Override
    public IDocumentQuery fuzzy(double fuzzy) {
        _fuzzy(fuzzy);
        return this;
    }

    @Override
    public IDocumentQuery proximity(int proximity) {
        _proximity(proximity);
        return this;
    }

    @Override
    public IDocumentQuery randomOrdering() {
        _randomOrdering();
        return this;
    }

    @Override
    public IDocumentQuery randomOrdering(String seed) {
        _randomOrdering(seed);
        return this;
    }

    //TBD 4.1 public IDocumentQuery customSortUsing(String typeName, boolean descending)

    @Override
    public IGroupByDocumentQuery groupBy(String fieldName, String... fieldNames) {
        _groupBy(fieldName, fieldNames);

        return new GroupByDocumentQuery<>(this);
    }

    @Override
    public IGroupByDocumentQuery groupBy(GroupBy field, GroupBy... fields) {
        _groupBy(field, fields);

        return new GroupByDocumentQuery<>(this);
    }

    @Override
    public  IDocumentQuery ofType(Class tResultClass) {
        return createDocumentQueryInternal(tResultClass);
    }

    public IDocumentQuery orderBy(String field) {
        return orderBy(field, OrderingType.STRING);
    }

    @Override
    public IDocumentQuery orderBy(String field, String sorterName) {
        _orderBy(field, sorterName);
        return this;
    }

    public IDocumentQuery orderBy(String field, OrderingType ordering) {
        _orderBy(field, ordering);
        return this;
    }

    //TBD expr public IDocumentQuery OrderBy(params Expression>[] propertySelectors)


    @Override
    public IDocumentQuery orderByDescending(String field, String sorterName) {
        _orderByDescending(field, sorterName);
        return this;
    }

    public IDocumentQuery orderByDescending(String field) {
        return orderByDescending(field, OrderingType.STRING);
    }

    public IDocumentQuery orderByDescending(String field, OrderingType ordering) {
        _orderByDescending(field, ordering);
        return this;
    }

    //TBD expr public IDocumentQuery OrderByDescending(params Expression>[] propertySelectors)

    @Override
    public IDocumentQuery addBeforeQueryExecutedListener(Consumer action) {
        _addBeforeQueryExecutedListener(action);
        return this;
    }

    @Override
    public IDocumentQuery removeBeforeQueryExecutedListener(Consumer action) {
        _removeBeforeQueryExecutedListener(action);
        return this;
    }

    public  DocumentQuery createDocumentQueryInternal(Class resultClass) {
        return createDocumentQueryInternal(resultClass, null);
    }

    @SuppressWarnings("unchecked")
    public  DocumentQuery createDocumentQueryInternal(Class resultClass, QueryData queryData) {
        FieldsToFetchToken newFieldsToFetch;

        if (queryData != null && queryData.getFields().length > 0) {
            String[] fields = queryData.getFields();

            if (!isGroupBy) {
                Field identityProperty = getConventions().getIdentityProperty(resultClass);

                if (identityProperty != null) {
                    fields = Arrays.stream(queryData.getFields())
                            .map(p -> p.equals(identityProperty.getName()) ? Constants.Documents.Indexing.Fields.DOCUMENT_ID_FIELD_NAME : p)
                            .toArray(String[]::new);
                }
            }

            Reference sourceAliasReference = new Reference<>();
            getSourceAliasIfExists(resultClass, queryData, fields, sourceAliasReference);
            newFieldsToFetch = FieldsToFetchToken.create(fields, queryData.getProjections(), queryData.isCustomFunction(), sourceAliasReference.value);
        } else {
            newFieldsToFetch = null;
        }

        if (newFieldsToFetch != null) {
            updateFieldsToFetchToken(newFieldsToFetch);
        }

        DocumentQuery query = new DocumentQuery<>(resultClass,
                theSession,
                getIndexName(),
                getCollectionName(),
                isGroupBy,
                queryData != null ? queryData.getDeclareTokens() : null,
                queryData != null ? queryData.getLoadTokens() : null,
                queryData != null ? queryData.getFromAlias() : null,
                queryData != null ? queryData.isProjectInto() : null);

        query.queryRaw = queryRaw;
        query.pageSize = pageSize;
        query.selectTokens = new LinkedList<>(selectTokens);
        query.fieldsToFetchToken = fieldsToFetchToken;
        query.whereTokens = new LinkedList<>(whereTokens);
        query.orderByTokens = new LinkedList<>(orderByTokens);
        query.groupByTokens = new LinkedList<>(groupByTokens);
        query.queryParameters = new Parameters(queryParameters);
        query.start = start;
        query.timeout = timeout;
        query.queryStats = queryStats;
        query.theWaitForNonStaleResults = theWaitForNonStaleResults;
        query.negate = negate;
        query.documentIncludes = new HashSet<>(documentIncludes);
        query.counterIncludesTokens = counterIncludesTokens;
        query.timeSeriesIncludesTokens = timeSeriesIncludesTokens;
        query.compareExchangeValueIncludesTokens = compareExchangeValueIncludesTokens;
        query.rootTypes = Sets.newHashSet(clazz);
        query.beforeQueryExecutedCallback = beforeQueryExecutedCallback;
        query.afterQueryExecutedCallback = afterQueryExecutedCallback;
        query.afterStreamExecutedCallback = afterStreamExecutedCallback;
        query.highlightingTokens = highlightingTokens;
        query.queryHighlightings = queryHighlightings;
        query.disableEntitiesTracking = disableEntitiesTracking;
        query.disableCaching = disableCaching;
        query.projectionBehavior = ObjectUtils.firstNonNull(queryData != null ? queryData.getProjectionBehavior() : null, projectionBehavior);
        query.queryTimings = queryTimings;
        query.explanations = explanations;
        query.explanationToken = explanationToken;
        query.isIntersect = isIntersect;
        query.defaultOperator = defaultOperator;

        return query;
    }

    @Override
    public IAggregationDocumentQuery aggregateBy(Consumer> builder) {
        FacetBuilder ff = new FacetBuilder<>();
        builder.accept(ff);

        return aggregateBy(ff.getFacet());
    }

    @Override
    public IAggregationDocumentQuery aggregateBy(FacetBase facet) {
        _aggregateBy(facet);

        return new AggregationDocumentQuery<>(this);
    }

    @Override
    public IAggregationDocumentQuery aggregateBy(FacetBase... facets) {
        for (FacetBase facet : facets) {
            _aggregateBy(facet);
        }

        return new AggregationDocumentQuery<>(this);
    }

    @Override
    public IAggregationDocumentQuery aggregateUsing(String facetSetupDocumentId) {
        _aggregateUsing(facetSetupDocumentId);

        return new AggregationDocumentQuery<>(this);
    }

    @Override
    public IDocumentQuery highlight(String fieldName, int fragmentLength, int fragmentCount, Reference highlightings) {
        _highlight(fieldName, fragmentLength, fragmentCount, null, highlightings);
        return this;
    }

    @Override
    public IDocumentQuery highlight(String fieldName, int fragmentLength, int fragmentCount, HighlightingOptions options, Reference highlightings) {
        _highlight(fieldName, fragmentLength, fragmentCount, options, highlightings);
        return this;
    }

    //TBD expr IDocumentQuery IDocumentQueryBase>.Highlight(Expression> path, int fragmentLength, int fragmentCount, out Highlightings highlightings)
    //TBD expr IDocumentQuery IDocumentQueryBase>.Highlight(Expression> path, int fragmentLength, int fragmentCount, HighlightingOptions options, out Highlightings highlightings)
    //TBD expr public IDocumentQuery Spatial(Expression> path, Func clause)

    @Override
    public IDocumentQuery spatial(String fieldName, Function clause) {
        SpatialCriteria criteria = clause.apply(SpatialCriteriaFactory.INSTANCE);
        _spatial(fieldName, criteria);
        return this;
    }

    @Override
    public IDocumentQuery spatial(DynamicSpatialField field, Function clause) {
        SpatialCriteria criteria = clause.apply(SpatialCriteriaFactory.INSTANCE);
        _spatial(field, criteria);
        return this;
    }

    //TBD expr public IDocumentQuery Spatial(Func, DynamicSpatialField> field, Func clause)
    //TBD expr IDocumentQuery IDocumentQueryBase>.WithinRadiusOf(Expression> propertySelector, double radius, double latitude, double longitude, SpatialUnits? radiusUnits, double distanceErrorPct)

    @Override
    public IDocumentQuery withinRadiusOf(String fieldName, double radius, double latitude, double longitude) {
        return withinRadiusOf(fieldName, radius, latitude, longitude, null, Constants.Documents.Indexing.Spatial.DEFAULT_DISTANCE_ERROR_PCT);
    }

    @Override
    public IDocumentQuery withinRadiusOf(String fieldName, double radius, double latitude, double longitude, SpatialUnits radiusUnits) {
        return withinRadiusOf(fieldName, radius, latitude, longitude, radiusUnits, Constants.Documents.Indexing.Spatial.DEFAULT_DISTANCE_ERROR_PCT);
    }

    @Override
    public IDocumentQuery withinRadiusOf(String fieldName, double radius, double latitude, double longitude, SpatialUnits radiusUnits, double distanceErrorPct) {
        _withinRadiusOf(fieldName, radius, latitude, longitude, radiusUnits, distanceErrorPct);
        return this;
    }

    //TBD expr IDocumentQuery IDocumentQueryBase>.RelatesToShape(Expression> propertySelector, string shapeWkt, SpatialRelation relation, double distanceErrorPct)

    @Override
    public IDocumentQuery relatesToShape(String fieldName, String shapeWkt, SpatialRelation relation) {
        return relatesToShape(fieldName, shapeWkt, relation, Constants.Documents.Indexing.Spatial.DEFAULT_DISTANCE_ERROR_PCT);
    }

    @Override
    public IDocumentQuery relatesToShape(String fieldName, String shapeWkt, SpatialRelation relation, double distanceErrorPct) {
        _spatial(fieldName, shapeWkt, relation, null, distanceErrorPct);
        return this;
    }

    @Override
    public IDocumentQuery relatesToShape(String fieldName, String shapeWkt, SpatialRelation relation, SpatialUnits units, double distanceErrorPct) {
        _spatial(fieldName, shapeWkt, relation, units, distanceErrorPct);
        return this;
    }

    @Override
    public IDocumentQuery orderByDistance(DynamicSpatialField field, double latitude, double longitude) {
        _orderByDistance(field, latitude, longitude);
        return this;
    }

    //TBD expr IDocumentQuery IDocumentQueryBase>.OrderByDistance(Func, DynamicSpatialField> field, double latitude, double longitude)

    @Override
    public IDocumentQuery orderByDistance(DynamicSpatialField field, String shapeWkt) {
        _orderByDistance(field, shapeWkt);
        return this;
    }

    //TBD expr IDocumentQuery IDocumentQueryBase>.OrderByDistance(Func, DynamicSpatialField> field, string shapeWkt)


    //TBD expr IDocumentQuery IDocumentQueryBase>.OrderByDistance(Expression> propertySelector, double latitude, double longitude)

    @Override
    public IDocumentQuery orderByDistance(String fieldName, double latitude, double longitude) {
        orderByDistance(fieldName, latitude, longitude, 0);
        return this;
    }

    @Override
    public IDocumentQuery orderByDistance(String fieldName, double latitude, double longitude, double roundFactor) {
        _orderByDistance(fieldName, latitude, longitude, roundFactor);
        return this;
    }

    //TBD expr IDocumentQuery IDocumentQueryBase>.OrderByDistance(Expression> propertySelector, string shapeWkt)

    @Override
    public IDocumentQuery orderByDistance(String fieldName, String shapeWkt) {
        _orderByDistance(fieldName, shapeWkt);
        return this;
    }

    @Override
    public IDocumentQuery orderByDistanceDescending(DynamicSpatialField field, double latitude, double longitude) {
        _orderByDistanceDescending(field, latitude, longitude);
        return this;
    }

    //TBD expr IDocumentQuery IDocumentQueryBase>.OrderByDistanceDescending(Func, DynamicSpatialField> field, double latitude, double longitude)

    @Override
    public IDocumentQuery orderByDistanceDescending(DynamicSpatialField field, String shapeWkt) {
        _orderByDistanceDescending(field, shapeWkt);
        return this;
    }

    //TBD expr IDocumentQuery IDocumentQueryBase>.OrderByDistanceDescending(Func, DynamicSpatialField> field, string shapeWkt)

    //TBD expr IDocumentQuery IDocumentQueryBase>.OrderByDistanceDescending(Expression> propertySelector, double latitude, double longitude)

    @Override
    public IDocumentQuery orderByDistanceDescending(String fieldName, double latitude, double longitude) {
        return orderByDistanceDescending(fieldName, latitude, longitude, 0);
    }

    @Override
    public IDocumentQuery orderByDistanceDescending(String fieldName, double latitude, double longitude, double roundFactor) {
        _orderByDistanceDescending(fieldName, latitude, longitude, roundFactor);
        return this;
    }

    //TBD expr IDocumentQuery IDocumentQueryBase>.OrderByDistanceDescending(Expression> propertySelector, string shapeWkt)

    @Override
    public IDocumentQuery orderByDistanceDescending(String fieldName, String shapeWkt) {
        _orderByDistanceDescending(fieldName, shapeWkt);
        return this;
    }

    @Override
    public IDocumentQuery moreLikeThis(MoreLikeThisBase moreLikeThis) {
        try (MoreLikeThisScope mlt = _moreLikeThis()) {
            mlt.withOptions(moreLikeThis.getOptions());

            if (moreLikeThis instanceof MoreLikeThisUsingDocument) {
                mlt.withDocument(((MoreLikeThisUsingDocument) moreLikeThis).getDocumentJson());
            }
        }

        return this;
    }

    @SuppressWarnings("unchecked")
    @Override
    public IDocumentQuery moreLikeThis(Consumer> builder) {
        MoreLikeThisBuilder f = new MoreLikeThisBuilder<>();
        builder.accept(f);

        try (MoreLikeThisScope moreLikeThis = _moreLikeThis()) {
            moreLikeThis.withOptions(f.getMoreLikeThis().getOptions());

            if (f.getMoreLikeThis() instanceof MoreLikeThisUsingDocument) {
                moreLikeThis.withDocument(((MoreLikeThisUsingDocument) f.getMoreLikeThis()).getDocumentJson());
            } else if (f.getMoreLikeThis() instanceof MoreLikeThisUsingDocumentForDocumentQuery) {
                ((MoreLikeThisUsingDocumentForDocumentQuery) f.getMoreLikeThis()).getForDocumentQuery().accept(this);
            }
        }

        return this;
    }

    @Override
    public ISuggestionDocumentQuery suggestUsing(SuggestionBase suggestion) {
        _suggestUsing(suggestion);
        return new SuggestionDocumentQuery<>(this);
    }

    @Override
    public ISuggestionDocumentQuery suggestUsing(Consumer> builder) {
        SuggestionBuilder f = new SuggestionBuilder<>();
        builder.accept(f);

        suggestUsing(f.getSuggestion());
        return new SuggestionDocumentQuery<>(this);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy