org.modeshape.jcr.query.lucene

## Class CompareStringQuery

- java.lang.Object
- - org.apache.lucene.search.Query
  - - org.modeshape.jcr.query.lucene.CompareQuery<String>
    - - org.modeshape.jcr.query.lucene.CompareStringQuery

- All Implemented Interfaces:
    Serializable, Cloneable

      public class CompareStringQuery
      extends CompareQuery<String>

  A Lucene `Query` implementation that is used to apply a `Comparison` constraint against a string field. This query implementation works by using the weight and `scorer` of the wrapped query to score (and return) only those documents with string fields that satisfy the constraint.
  See Also:
    Serialized Form

- - ### Nested Class Summary

    - ### Nested classes/interfaces inherited from class org.modeshape.jcr.query.lucene.CompareQuery

      `CompareQuery.CompareScorer, CompareQuery.CompareWeight, CompareQuery.Evaluator<ValueType>`

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected static CompareQuery.Evaluator<String>` | `EQUAL_TO`
    `protected static CompareQuery.Evaluator<String>` | `IS_GREATER_THAN`
    `protected static CompareQuery.Evaluator<String>` | `IS_GREATER_THAN_OR_EQUAL_TO`
    `protected static CompareQuery.Evaluator<String>` | `IS_LESS_THAN`
    `protected static CompareQuery.Evaluator<String>` | `IS_LESS_THAN_OR_EQUAL_TO`

    - ### Fields inherited from class org.modeshape.jcr.query.lucene.CompareQuery

      `constraintValue, evaluator, fieldName, fieldSelector, stringFactory, valueTypeFactory`

  - ### Constructor Summary

    Constructors
    Modifier | Constructor and Description
    --- | ---
    `protected` | `CompareStringQuery(String fieldName, String constraintValue, ValueFactory<String> valueFactory, ValueFactory<String> stringFactory, CompareQuery.Evaluator<String> evaluator, CaseOperations.CaseOperation caseOperation)` Construct a `Query` implementation that scores nodes according to the supplied comparator.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `Object` | `clone()`
    `static org.apache.lucene.search.Query` | `createQueryForNodesWithFieldEqualTo(String constraintValue, String fieldName, ValueFactories factories, CaseOperations.CaseOperation caseOperation)` Construct a `Query` implementation that scores documents with a string field value that is equal to the supplied constraint value.
    `static CompareStringQuery` | `createQueryForNodesWithFieldGreaterThan(String constraintValue, String fieldName, ValueFactories factories, CaseOperations.CaseOperation caseOperation)` Construct a `Query` implementation that scores documents with a string field value that is greater than the supplied constraint value.
    `static CompareStringQuery` | `createQueryForNodesWithFieldGreaterThanOrEqualTo(String constraintValue, String fieldName, ValueFactories factories, CaseOperations.CaseOperation caseOperation)` Construct a `Query` implementation that scores documents with a string field value that is greater than or equal to the supplied constraint value.
    `static CompareStringQuery` | `createQueryForNodesWithFieldLessThan(String constraintValue, String fieldName, ValueFactories factories, CaseOperations.CaseOperation caseOperation)` Construct a `Query` implementation that scores documents with a string field value that is less than the supplied constraint value.
    `static CompareStringQuery` | `createQueryForNodesWithFieldLessThanOrEqualTo(String constraintValue, String fieldName, ValueFactories factories, CaseOperations.CaseOperation caseOperation)` Construct a `Query` implementation that scores documents with a string field value that is less than or equal to the supplied constraint value.
    `static org.apache.lucene.search.Query` | `createQueryForNodesWithFieldLike(String likeExpression, String fieldName, ValueFactories factories, CaseOperations.CaseOperation caseOperation)` Construct a `Query` implementation that scores documents with a string field value that is LIKE the supplied constraint value, where the LIKE expression contains the SQL wildcard characters '%' and '_' or the regular expression wildcard characters '*' and '?'.
    `protected static boolean` | `hasWildcardCharacters(String expression)`
    `protected String` | `readFromDocument(org.apache.lucene.index.IndexReader reader, int docId)`
    `static String` | `toRegularExpression(String likeExpression)` Convert the JCR like expression to a regular expression.
    `String` | `toString(String field)`
    `protected static String` | `toWildcardExpression(String likeExpression)` Convert the JCR like expression to a Lucene wildcard expression.

    - ### Methods inherited from class org.modeshape.jcr.query.lucene.CompareQuery

      `createWeight`

    - ### Methods inherited from class org.apache.lucene.search.Query

      `combine, equals, extractTerms, getBoost, getSimilarity, hashCode, mergeBooleanQueries, rewrite, setBoost, toString, weight`

    - ### Methods inherited from class java.lang.Object

      `finalize, getClass, notify, notifyAll, wait, wait, wait`

- - ### Field Detail

    - #### EQUAL_TO

          protected static final CompareQuery.Evaluator<String> EQUAL_TO

    - #### IS_LESS_THAN

          protected static final CompareQuery.Evaluator<String> IS_LESS_THAN

    - #### IS_LESS_THAN_OR_EQUAL_TO

          protected static final CompareQuery.Evaluator<String> IS_LESS_THAN_OR_EQUAL_TO

    - #### IS_GREATER_THAN

          protected static final CompareQuery.Evaluator<String> IS_GREATER_THAN

    - #### IS_GREATER_THAN_OR_EQUAL_TO

          protected static final CompareQuery.Evaluator<String> IS_GREATER_THAN_OR_EQUAL_TO

  - ### Constructor Detail

    - #### CompareStringQuery

          protected CompareStringQuery(String fieldName,
                            String constraintValue,
                            ValueFactory<String> valueFactory,
                            ValueFactory<String> stringFactory,
                            CompareQuery.Evaluator<String> evaluator,
                            CaseOperations.CaseOperation caseOperation)

      Construct a `Query` implementation that scores nodes according to the supplied comparator.
      Parameters:
        `fieldName` - the name of the document field containing the value; may not be null
        `constraintValue` - the constraint value; may not be null
        `valueFactory` - the value factory that can be used during the scoring; may not be null
        `stringFactory` - the string factory that can be used during the scoring; may not be null
        `evaluator` - the `CompareQuery.Evaluator` implementation that returns whether the node path satisfies the constraint; may not be null
        `caseOperation` - the operation that should be performed on the indexed values before the constraint value is being evaluated; may not be null

  - ### Method Detail

    - #### createQueryForNodesWithFieldEqualTo

          public static org.apache.lucene.search.Query createQueryForNodesWithFieldEqualTo(String constraintValue,
                                                                           String fieldName,
                                                                           ValueFactories factories,
                                                                           CaseOperations.CaseOperation caseOperation)

      Construct a `Query` implementation that scores documents with a string field value that is equal to the supplied constraint value.
      Parameters:
        `constraintValue` - the constraint value; may not be null
        `fieldName` - the name of the document field containing the value; may not be null
        `factories` - the value factories that can be used during the scoring; may not be null
        `caseOperation` - the operation that should be performed on the indexed values before the constraint value is being evaluated; may not be null
      Returns:
        the query; never null

    - #### createQueryForNodesWithFieldGreaterThan

          public static CompareStringQuery createQueryForNodesWithFieldGreaterThan(String constraintValue,
                                                                   String fieldName,
                                                                   ValueFactories factories,
                                                                   CaseOperations.CaseOperation caseOperation)

      Construct a `Query` implementation that scores documents with a string field value that is greater than the supplied constraint value.
      Parameters:
        `constraintValue` - the constraint value; may not be null
        `fieldName` - the name of the document field containing the value; may not be null
        `factories` - the value factories that can be used during the scoring; may not be null
        `caseOperation` - the operation that should be performed on the indexed values before the constraint value is being evaluated; may not be null
      Returns:
        the query; never null

    - #### createQueryForNodesWithFieldGreaterThanOrEqualTo

          public static CompareStringQuery createQueryForNodesWithFieldGreaterThanOrEqualTo(String constraintValue,
                                                                            String fieldName,
                                                                            ValueFactories factories,
                                                                            CaseOperations.CaseOperation caseOperation)

      Construct a `Query` implementation that scores documents with a string field value that is greater than or equal to the supplied constraint value.
      Parameters:
        `constraintValue` - the constraint value; may not be null
        `fieldName` - the name of the document field containing the value; may not be null
        `factories` - the value factories that can be used during the scoring; may not be null
        `caseOperation` - the operation that should be performed on the indexed values before the constraint value is being evaluated; may not be null
      Returns:
        the query; never null

    - #### createQueryForNodesWithFieldLessThan

          public static CompareStringQuery createQueryForNodesWithFieldLessThan(String constraintValue,
                                                                String fieldName,
                                                                ValueFactories factories,
                                                                CaseOperations.CaseOperation caseOperation)

      Construct a `Query` implementation that scores documents with a string field value that is less than the supplied constraint value.
      Parameters:
        `constraintValue` - the constraint value; may not be null
        `fieldName` - the name of the document field containing the value; may not be null
        `factories` - the value factories that can be used during the scoring; may not be null
        `caseOperation` - the operation that should be performed on the indexed values before the constraint value is being evaluated; may not be null
      Returns:
        the query; never null

    - #### createQueryForNodesWithFieldLessThanOrEqualTo

          public static CompareStringQuery createQueryForNodesWithFieldLessThanOrEqualTo(String constraintValue,
                                                                         String fieldName,
                                                                         ValueFactories factories,
                                                                         CaseOperations.CaseOperation caseOperation)

      Construct a `Query` implementation that scores documents with a string field value that is less than or equal to the supplied constraint value.
      Parameters:
        `constraintValue` - the constraint value; may not be null
        `fieldName` - the name of the document field containing the value; may not be null
        `factories` - the value factories that can be used during the scoring; may not be null
        `caseOperation` - the operation that should be performed on the indexed values before the constraint value is being evaluated; may not be null
      Returns:
        the query; never null

    - #### hasWildcardCharacters

          protected static boolean hasWildcardCharacters(String expression)

    - #### createQueryForNodesWithFieldLike

          public static org.apache.lucene.search.Query createQueryForNodesWithFieldLike(String likeExpression,
                                                                        String fieldName,
                                                                        ValueFactories factories,
                                                                        CaseOperations.CaseOperation caseOperation)

      Construct a `Query` implementation that scores documents with a string field value that is LIKE the supplied constraint value, where the LIKE expression contains the SQL wildcard characters '%' and '_' or the regular expression wildcard characters '*' and '?'.
      Parameters:
        `likeExpression` - the LIKE expression; may not be null
        `fieldName` - the name of the document field containing the value; may not be null
        `factories` - the value factories that can be used during the scoring; may not be null
        `caseOperation` - the operation that should be performed on the indexed values before the constraint value is being evaluated; may not be null
      Returns:
        the query; never null

    - #### toWildcardExpression

          protected static String toWildcardExpression(String likeExpression)

      Convert the JCR like expression to a Lucene wildcard expression. The JCR like expression uses '%' to match 0 or more characters, '_' to match any single character, '\x' to match the 'x' character, and all other characters to match themselves.
      Parameters:
        `likeExpression` - the like expression; may not be null
      Returns:
        the expression that can be used with a WildcardQuery; never null

    - #### toRegularExpression

          public static String toRegularExpression(String likeExpression)

      Convert the JCR like expression to a regular expression. The JCR like expression uses '%' to match 0 or more characters, '_' to match any single character, '\x' to match the 'x' character, and all other characters to match themselves. Note that if any regex metacharacters appear in the like expression, they will be escaped within the resulting regular expression.
      Parameters:
        `likeExpression` - the like expression; may not be null
      Returns:
        the expression that can be used with a WildcardQuery; never null

    - #### readFromDocument

          protected String readFromDocument(org.apache.lucene.index.IndexReader reader,
                                int docId)
                                     throws IOException

      Overrides:
        `readFromDocument` in class `CompareQuery<String>`
      Throws:
        `IOException`

    - #### clone

          public Object clone()

      Overrides:
        `clone` in class `org.apache.lucene.search.Query`

    - #### toString

          public String toString(String field)

      Description copied from class: `CompareQuery`
      Overrides:
        `toString` in class `CompareQuery<String>`
      See Also:
        `Query.toString(java.lang.String)`

Copyright © 2008-2014 JBoss, a division of Red Hat. All Rights Reserved.