Interface CombinedQueryDefinition

  • All Superinterfaces:
    com.marklogic.client.pojo.PojoQueryDefinition, com.marklogic.client.query.QueryDefinition, com.marklogic.client.query.StructuredQueryDefinition, com.marklogic.client.query.ValueQueryDefinition
    All Known Implementing Classes:
    CombinedQueryDefinitionBuilder

    public interface CombinedQueryDefinition
    extends com.marklogic.client.query.StructuredQueryDefinition
    Convenience interface provided to allow easy creation of "combined" queries. These type of queries combined structured queries and ad-hoc options (not persisted to the database) (see http://docs.marklogic.com/guide/rest-dev/search#id_69918) for more information. This interface follows the Java "builder" pattern to make it easier to construct queries. As much as possible any defaults for these methods follow conventions used in the MarkLogic Java Client Library. This interface also has helper methods to add some of the more common query options like sorting, extractions, and term searches.
    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      CombinedQueryDefinition and​(com.marklogic.client.query.StructuredQueryDefinition... queries)
      Combine the current structured queries in the combined query with the specified queries using an "and".
      CombinedQueryDefinition byExample​(com.marklogic.client.query.RawQueryByExampleDefinition qbe)
      Adds a raw Query By Example definition to the current combined query.
      CombinedQueryDefinition byExample​(com.marklogic.client.query.RawQueryByExampleDefinition qbe, com.marklogic.client.io.Format format)
      Adds a raw Query By Example definition to the current combined query.
      CombinedQueryDefinition collections​(String... collections)
      Adds constraints to limit results to only documents contained in one of the specified collections.
      CombinedQueryDefinition context​(org.springframework.data.mapping.context.MappingContext mappingContext)
      Override the default mapping context to use when building queries.
      CombinedQueryDefinition directory​(String directory)
      Adds contraints to limit results to only documents contained in the specified directory.
      CombinedQueryDefinition extracts​(List<String> extracts)
      Specify which properties of a document will be included/excluded from the results.
      CombinedQueryDefinition extracts​(List<String> extracts, SelectedMode mode)
      Specify which properties of a document will be included/excluded from the results.
      int getLimit()
      Gets the configured limit for the current limit.
      com.marklogic.client.query.RawQueryByExampleDefinition getRawQbe()
      Gets the raw Query By Example definition from the combined query.
      boolean isLimiting()
      Indicates whether or not a limit has been specified on this query.
      boolean isQbe()
      Indicates whether or not this combined query is a raw Query By Example query.
      CombinedQueryDefinition limit​(int limit)
      Limit the results that come back to the specified number.
      CombinedQueryDefinition options​(String... options)
      Add a snippet of XML query options to the combined query.
      CombinedQueryDefinition optionsName​(String name)
      Sets the query to use persisted options that have the specified name.
      CombinedQueryDefinition or​(com.marklogic.client.query.StructuredQueryDefinition... queries)
      Combine the current structured queries in the combined query with the specified queries using an "or".
      String serialize()
      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.
      CombinedQueryDefinition sort​(String propertyName, String order, IndexType type)
      Adds sorting configuration to the query.
      CombinedQueryDefinition sort​(org.springframework.data.domain.Sort sort)
      Add sorting configuration to the query.
      CombinedQueryDefinition sort​(org.springframework.data.domain.Sort sort, IndexType type)
      Add sorting configuration to the query.
      CombinedQueryDefinition sparql​(String sparql)
      Add SPARQL queries to constraint results to only documents that have the matched triples.
      CombinedQueryDefinition term​(String qtext)
      Add a search term to the current query.
      CombinedQueryDefinition transform​(com.marklogic.client.document.ServerTransform transform)
      Specify a server transform to use on the results that are matched in the database.
      CombinedQueryDefinition type​(Class entityClass)
      Specified the entity type to use when building the query.
      • Methods inherited from interface com.marklogic.client.query.QueryDefinition

        getCollections, getDirectory, getOptionsName, getResponseTransform, setCollections, setDirectory, setOptionsName, setResponseTransform
      • Methods inherited from interface com.marklogic.client.query.StructuredQueryDefinition

        getCriteria, setCriteria, withCriteria
    • Method Detail

      • getRawQbe

        com.marklogic.client.query.RawQueryByExampleDefinition getRawQbe()
        Gets the raw Query By Example definition from the combined query.
        Returns:
        the raw QBE object.
      • byExample

        CombinedQueryDefinition byExample​(com.marklogic.client.query.RawQueryByExampleDefinition qbe,
                                          com.marklogic.client.io.Format format)
        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.
        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

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

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

        CombinedQueryDefinition collections​(String... collections)
        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".
        Parameters:
        collections - A list of collection URIs
        Returns:
        The current query definition for use in continued building.
      • directory

        CombinedQueryDefinition directory​(String directory)
        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/".
        Parameters:
        directory - The directory path under which to limit results.
        Returns:
        The current query definition for use in continued building.
      • optionsName

        CombinedQueryDefinition optionsName​(String name)
        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.
        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

        CombinedQueryDefinition options​(String... options)
        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>");
        Parameters:
        options - Variable number of options XML strings to add to the query.
        Returns:
        The current query definition for use in continued building.
      • sort

        CombinedQueryDefinition sort​(org.springframework.data.domain.Sort sort)
        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 type(Class) be called first to specify the entity type.
        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

        CombinedQueryDefinition sort​(org.springframework.data.domain.Sort sort,
                                     IndexType type)
        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.
        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

        CombinedQueryDefinition sort​(String propertyName,
                                     String order,
                                     IndexType type)
        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.
        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

        CombinedQueryDefinition extracts​(List<String> extracts,
                                         SelectedMode mode)
        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.
        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

        CombinedQueryDefinition transform​(com.marklogic.client.document.ServerTransform transform)
        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.
        Returns:
        The current query definition for use in continued building.
      • term

        CombinedQueryDefinition term​(String qtext)
        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.
        Parameters:
        qtext - A search phrase.
        Returns:
        The current query definition for use in continued building.
      • sparql

        CombinedQueryDefinition sparql​(String sparql)
        Add SPARQL queries to constraint results to only documents that have the matched triples.
        Parameters:
        sparql - The SPARQL query.
        Returns:
        The current query definition for use in continued building.
      • type

        CombinedQueryDefinition type​(Class entityClass)
        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.
        Parameters:
        entityClass - The type of the entity.
        Returns:
        The current query definition for use in continued building.
      • context

        CombinedQueryDefinition context​(org.springframework.data.mapping.context.MappingContext mappingContext)
        Override the default mapping context to use when building queries.
        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.
      • isQbe

        boolean isQbe()
        Indicates whether or not this combined query is a raw Query By Example query.
        Returns:
        True if the combined query contains a raw QBE.
      • isLimiting

        boolean isLimiting()
        Indicates whether or not a limit has been specified on this query.
        Returns:
        True if the query is limiting.
      • getLimit

        int getLimit()
        Gets the configured limit for the current limit.
        Returns:
        The limit, or -1 if not set.
      • serialize

        String serialize()
        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 com.marklogic.client.query.StructuredQueryDefinition
        Returns:
        JSON/XML string of a combined query.