com.groupdocs.search

Class SearchQuery



  • public abstract class SearchQuery
    extends Object

    Represents a search query in object form.

    The example demonstrates a typical usage of the class.

     String indexFolder = "c:\\MyIndex\\";
     String documentsFolder = "c:\\MyDocuments\\";
     Index index = new Index(indexFolder); // Creating index in the specified folder
     index.add(documentsFolder); // Indexing documents from the specified folder
     // Creating subquery of date range search
     SearchQuery subquery1 = SearchQuery.createDateRangeQuery(new Date(2011, 6, 17), new Date(2013, 1, 1));
     // Creating subquery of wildcard with number of missed words from 0 to 2
     SearchQuery subquery2 = SearchQuery.createWildcardQuery(0, 2);
     // Creating subquery of simple word
     SearchQuery subquery3 = SearchQuery.createWordQuery("birth");
     subquery3.setSearchOptions(new SearchOptions()); // Setting search options only for subquery 3
     subquery3.getSearchOptions().getFuzzySearch().setEnabled(true);
     subquery3.getSearchOptions().getFuzzySearch().setFuzzyAlgorithm(new TableDiscreteFunction(1));
     // Combining subqueries into one query
     SearchQuery query = SearchQuery.createPhraseSearchQuery(subquery1, subquery2, subquery3);
     // Creating search options object with increased capacity of found occurrences
     SearchOptions options = new SearchOptions(); // Overall search options
     options.setMaxOccurrenceCountPerTerm(1000000);
     options.setMaxTotalOccurrenceCount(10000000);
     SearchResult result = index.search(query, options); // Searching
     
    • Constructor Detail

      • SearchQuery

        protected SearchQuery()
    • Method Detail

      • getFieldName

        public String getFieldName()

        Gets the field name.

        Returns:
        The field name.
      • getChildCount

        public int getChildCount()

        Gets the number of child queries.

        Returns:
        The number of child queries.
      • getFirstChild

        public SearchQuery getFirstChild()

        Gets the first child query.

        Returns:
        The first child query.
      • getSecondChild

        public SearchQuery getSecondChild()

        Gets the second child query.

        Returns:
        The second child query.
      • getChild

        public abstract SearchQuery getChild(int index)

        Gets a child query by an index.

        Parameters:
        index - The index.
        Returns:
        A child query corresponding the specified index.
      • getSearchOptions

        public final SearchOptions getSearchOptions()

        Gets the search options of this seach query.

        Returns:
        The search options.
      • setSearchOptions

        public final void setSearchOptions(SearchOptions value)

        Sets the search options of this seach query.

        Parameters:
        value - The search options.
      • toString

        public abstract String toString()

        Returns a String that represents the current SearchQuery instance.

        Overrides:
        toString in class Object
        Returns:
        A String that represents the current SearchQuery instance.
      • createWordQuery

        public static SearchQuery createWordQuery(String term)

        Creates a simple word query.

        Parameters:
        term - The term to search for.
        Returns:
        A simple word query.
      • createWordPatternQuery

        public static SearchQuery createWordPatternQuery(WordPattern pattern)

        Creates a word pattern query.

        Parameters:
        pattern - The word pattern.
        Returns:
        A word pattern query.
      • createRegexQuery

        public static SearchQuery createRegexQuery(String pattern)

        Creates a regular expression query.

        Parameters:
        pattern - The regular expression pattern to match.
        Returns:
        A regular expression query.
      • createRegexQuery

        public static SearchQuery createRegexQuery(String pattern,
                                   int options)

        Creates a regular expression query.

        Parameters:
        pattern - The regular expression pattern to match.
        options - A bitwise combination of the enumeration values that modify the regular expression. This value must contain RegexOptions.IgnoreCase flag.
        Returns:
        A regular expression query.
      • createNumericRangeQuery

        public static SearchQuery createNumericRangeQuery(long start,
                                          long end)

        Creates a numeric range query.

        Parameters:
        start - The start value of a range.
        end - The end value of a range.
        Returns:
        A numeric range query.
      • createDateRangeQuery

        public static SearchQuery createDateRangeQuery(Date start,
                                       Date end)

        Creates a date range query.

        Parameters:
        start - The start value of a range.
        end - The end value of a range.
        Returns:
        A date range query.
      • createPhraseSearchQuery

        public static SearchQuery createPhraseSearchQuery(SearchQuery... queries)

        Creates a phrase search query.

        Parameters:
        queries - The child queries.
        Returns:
        A phrase search query.
      • createFieldQuery

        public static SearchQuery createFieldQuery(String fieldName,
                                   SearchQuery query)

        Adds a field to the specified query.

        Parameters:
        fieldName - The field name to search in.
        query - The query to add the field.
        Returns:
        A query with the field to search in.
      • createNotQuery

        public static SearchQuery createNotQuery(SearchQuery query)

        Creates an inverted query that will find the rest documents in an index against ones which will be found for the original query.

        Parameters:
        query - The query to invert.
        Returns:
        A combined NOT query.
      • createAndQuery

        public static SearchQuery createAndQuery(SearchQuery leftQuery,
                                 SearchQuery rightQuery)

        Creates a combined query that will find only documents which will be found for each original query.

        Parameters:
        leftQuery - The left child query.
        rightQuery - The right child query.
        Returns:
        A combined AND query.
      • createOrQuery

        public static SearchQuery createOrQuery(SearchQuery leftQuery,
                                SearchQuery rightQuery)

        Creates a combined query that will find all the documents which will be found at least for one of the original queries.

        Parameters:
        leftQuery - The left child query.
        rightQuery - The right child query.
        Returns:
        A combined OR query.
      • createWildcardQuery

        public static SearchQuery createWildcardQuery(int count)

        Creates a wildcard for the phrase search.

        Parameters:
        count - The number of words in the wildcard.
        Returns:
        A wildcard for the phrase search.
      • createWildcardQuery

        public static SearchQuery createWildcardQuery(int minCount,
                                      int maxCount)

        Creates a wildcard for the phrase search.

        Parameters:
        minCount - The minimum number of words in the wildcard.
        maxCount - The maximum number of words in the wildcard.
        Returns:
        A wildcard for the phrase search.
      • deserialize

        protected static SearchQuery deserialize(byte[] array)
      • serialize

        protected static byte[] serialize(SearchQuery searchQuery)