Class CombinedQueryDefinitionBuilder

  • All Implemented Interfaces:
    com.marklogic.client.pojo.PojoQueryDefinition, com.marklogic.client.query.QueryDefinition, com.marklogic.client.query.StructuredQueryDefinition, com.marklogic.client.query.ValueQueryDefinition, CombinedQueryDefinition

    public class CombinedQueryDefinitionBuilder
    extends com.marklogic.client.impl.AbstractQueryDefinition
    implements CombinedQueryDefinition
    Allow us to keep a running build of query/options so we can set them throughout the different processing levels. The CombinedQueryDefinition in the driver library is for a specific purpose and not modifiable, nor is it passable down to the template methods. Since the structure is well-defined as part of MarkLogic's REST API we can create the appropriate combined query from what we have.
    • Method Detail

      • combine

        public static CombinedQueryDefinition combine​(com.marklogic.client.query.StructuredQueryDefinition query)
      • serialize

        public String serialize()
        Description copied from interface: CombinedQueryDefinition
        Used by the MarkLogic Java Client Library to get the "low-level" representation of the query that can be submitted to the MarkLogic REST API.
        Specified by:
        serialize in interface CombinedQueryDefinition
        Specified by:
        serialize in interface com.marklogic.client.query.StructuredQueryDefinition
        Returns:
        JSON/XML string of a combined query.
      • isQbe

        public boolean isQbe()
        Description copied from interface: CombinedQueryDefinition
        Indicates whether or not this combined query is a raw Query By Example query.
        Specified by:
        isQbe in interface CombinedQueryDefinition
        Returns:
        True if the combined query contains a raw QBE.
      • getRawQbe

        public com.marklogic.client.query.RawQueryByExampleDefinition getRawQbe()
        Description copied from interface: CombinedQueryDefinition
        Gets the raw Query By Example definition from the combined query.
        Specified by:
        getRawQbe in interface CombinedQueryDefinition
        Returns:
        the raw QBE object.
      • getQbe

        public com.marklogic.client.query.RawQueryByExampleDefinition getQbe()
      • setQbe

        public void setQbe​(com.marklogic.client.query.RawQueryByExampleDefinition qbe)
      • byExample

        public CombinedQueryDefinition byExample​(com.marklogic.client.query.RawQueryByExampleDefinition qbe,
                                                 com.marklogic.client.io.Format format)
        Description copied from interface: CombinedQueryDefinition
        Adds a raw Query By Example definition to the current combined query. This will supercede any structured query that currently exists in the combined query, so use one or the other.
        Specified by:
        byExample in interface CombinedQueryDefinition
        Parameters:
        qbe - the raw QBE object.
        format - Either JSON or XML, using the Format enum.
        Returns:
        The current query definition for use in continued building.
      • and

        public CombinedQueryDefinition and​(com.marklogic.client.query.StructuredQueryDefinition... queries)
        Description copied from interface: CombinedQueryDefinition
        Combine the current structured queries in the combined query with the specified queries using an "and".
        Specified by:
        and in interface CombinedQueryDefinition
        Parameters:
        queries - Queries to add to the combined query
        Returns:
        The current query definition for use in continued building.
      • or

        public CombinedQueryDefinition or​(com.marklogic.client.query.StructuredQueryDefinition... queries)
        Description copied from interface: CombinedQueryDefinition
        Combine the current structured queries in the combined query with the specified queries using an "or".
        Specified by:
        or in interface CombinedQueryDefinition
        Parameters:
        queries - Queries to add to the combined query
        Returns:
        The current query definition for use in continued building.
      • collections

        public CombinedQueryDefinition collections​(String... collections)
        Description copied from interface: CombinedQueryDefinition
        Adds constraints to limit results to only documents contained in one of the specified collections. This can be called multiple times and the result is additive. By default all documents are in a collection named after the entity class, i.e. a Person entity is stored in a collection with the URI "Person".
        Specified by:
        collections in interface CombinedQueryDefinition
        Parameters:
        collections - A list of collection URIs
        Returns:
        The current query definition for use in continued building.
      • directory

        public CombinedQueryDefinition directory​(String directory)
        Description copied from interface: CombinedQueryDefinition
        Adds contraints to limit results to only documents contained in the specified directory. Multiple calls to this function will replace the value of previous calls. By default all documents are stored under a path named after the entity class (to avoid ID clashes, since the database URI is the "true" primary key). So a Person entity is stored under the path "/Person/".
        Specified by:
        directory in interface CombinedQueryDefinition
        Parameters:
        directory - The directory path under which to limit results.
        Returns:
        The current query definition for use in continued building.
      • optionsName

        public CombinedQueryDefinition optionsName​(String name)
        Description copied from interface: CombinedQueryDefinition
        Sets the query to use persisted options that have the specified name. If you find you are adding lots of ad-hoc options to your queries or that you are having performance issues because of building them each time you can save those options and reference them in your query. For more information see http://docs.marklogic.com/guide/java/query-options#id_20346.
        Specified by:
        optionsName in interface CombinedQueryDefinition
        Parameters:
        name - The name of the options as they are saved in the database.
        Returns:
        The current query definition for use in continued building.
      • options

        public CombinedQueryDefinition options​(String... options)
        Description copied from interface: CombinedQueryDefinition
        Add a snippet of XML query options to the combined query. If you wanted to configure the query to return the metrics of the query you would call the method like so: combinedQuery.options("<return-metrics>true</return-metrics>");
        Specified by:
        options in interface CombinedQueryDefinition
        Parameters:
        options - Variable number of options XML strings to add to the query.
        Returns:
        The current query definition for use in continued building.
      • sort

        public CombinedQueryDefinition sort​(org.springframework.data.domain.Sort sort)
        Description copied from interface: CombinedQueryDefinition
        Add sorting configuration to the query. The default sort algorithm will expect to use a path range index, i.e. if sorting on "name" then a path index of "/name" should exist. Through use of the Indexed annotation you can indicate use of a different type of range index for the property sorting, or specify the full path that should be used in creation of the sort options. This requires that CombinedQueryDefinition.type(Class) be called first to specify the entity type.
        Specified by:
        sort in interface CombinedQueryDefinition
        Parameters:
        sort - Sort information for the query, i.e. which properties and which orders.
        Returns:
        The current query definition for use in continued building.
      • sort

        public CombinedQueryDefinition sort​(org.springframework.data.domain.Sort sort,
                                            IndexType type)
        Description copied from interface: CombinedQueryDefinition
        Add sorting configuration to the query. The type that is specified will be used on all sort properties specified in the Sort object, and the assumption will be that how they are specified in that object is exactly how the index is defined in the configuration. For example, if you have a sort property of "name" and you specify the type of IndexType.PATH then you would need a path range index defined for "name". If the property is "/pets/name" with the same index type then a path range index would need to be defined for "/pets/name". Usually it is better to be consistent in how you define your indexes (i.e. use either path range or element (property) range indexes) so that the same type of index can be configured for many properties in a sort.
        Specified by:
        sort in interface CombinedQueryDefinition
        Parameters:
        sort - Sort information for the query, i.e. which properties and which orders.
        type - The type of index that is configured for the properties. Used to create the correct options in the combined query.
        Returns:
        The current query definition for use in continued building.
      • sort

        public CombinedQueryDefinition sort​(String propertyName,
                                            String order,
                                            IndexType type)
        Description copied from interface: CombinedQueryDefinition
        Adds sorting configuration to the query. This is the most fine-grained control of sort index configuration - you can specify details for each property. The downside would be typically you would have to iterate over a Sort yourself and perform logic to determine index type yourself.
        Specified by:
        sort in interface CombinedQueryDefinition
        Parameters:
        propertyName - The name of the property, or path, or whatever (depending on index type used)
        order - The order, either "descending" or "ascending"
        type - The type of index that is configured for the properties. Used to create the correct options in the combined query.
        Returns:
        The current query definition for use in continued building.
      • extracts

        public CombinedQueryDefinition extracts​(List<String> extracts,
                                                SelectedMode mode)
        Description copied from interface: CombinedQueryDefinition
        Specify which properties of a document will be included/excluded from the results. The default is for the entire document to be returned. Ideally you keep the mode as SelectedMode.HIERARCHICAL so that your entities will be de-serialized correctly. If you create a custom entity to handle the results of just the properties flattened out then you can just use the SelectedMode.INCLUDE. For more information see http://docs.marklogic.com/guide/java/searches#id_90087.
        Specified by:
        extracts in interface CombinedQueryDefinition
        Parameters:
        extracts - A list of XPaths that describe which properties in a document to include/exclude
        mode - Specify whether to include or exclude the specified properties.
        Returns:
        The current query definition for use in continued building.
      • transform

        public CombinedQueryDefinition transform​(com.marklogic.client.document.ServerTransform transform)
        Description copied from interface: CombinedQueryDefinition
        Specify a server transform to use on the results that are matched in the database. This server transform will be applied to each document before the set is returned from the database, so for complicated transformation logic this could be more efficient than trying to do it in the Java layer. For more information see http://docs.marklogic.com/guide/java/transforms.
        Specified by:
        transform in interface CombinedQueryDefinition
        Returns:
        The current query definition for use in continued building.
      • term

        public CombinedQueryDefinition term​(String qtext)
        Description copied from interface: CombinedQueryDefinition
        Add a search term to the current query. This is used for word searches across your entire document. For more fine-grained control use StructuredQueryBuilder.word(StructuredQueryBuilder.TextIndex, String...) to specify specific properties or fields into which to scope the word search.
        Specified by:
        term in interface CombinedQueryDefinition
        Parameters:
        qtext - A search phrase.
        Returns:
        The current query definition for use in continued building.
      • type

        public CombinedQueryDefinition type​(Class entityClass)
        Description copied from interface: CombinedQueryDefinition
        Specified the entity type to use when building the query. There are various annotations that can be used on your entity classes. If you want those to be used in making decisions on how to build certain options then make sure to use this to "add" it to the query. If not specified then the defaults will always be used.
        Specified by:
        type in interface CombinedQueryDefinition
        Parameters:
        entityClass - The type of the entity.
        Returns:
        The current query definition for use in continued building.
      • context

        public CombinedQueryDefinition context​(org.springframework.data.mapping.context.MappingContext mappingContext)
        Description copied from interface: CombinedQueryDefinition
        Override the default mapping context to use when building queries.
        Specified by:
        context in interface CombinedQueryDefinition
        Parameters:
        mappingContext - A mapping context that maps entity information for methods that specify entity types.
        Returns:
        The current query definition for use in continued building.
      • getCriteria

        public String getCriteria()
        Specified by:
        getCriteria in interface com.marklogic.client.query.StructuredQueryDefinition
      • setCriteria

        public void setCriteria​(String criteria)
        Specified by:
        setCriteria in interface com.marklogic.client.query.StructuredQueryDefinition
      • withCriteria

        public CombinedQueryDefinition withCriteria​(String criteria)
        Specified by:
        withCriteria in interface com.marklogic.client.query.StructuredQueryDefinition
      • getQbeFormat

        public com.marklogic.client.io.Format getQbeFormat()
      • getStructuredQuery

        public com.marklogic.client.query.StructuredQueryDefinition getStructuredQuery()
      • getQtext

        public String getQtext()
      • getSparql

        public String getSparql()
      • getEntityClass

        public Class getEntityClass()