When you perform a wildcard query, you can use the asterisk (*) and question mark (?) wildcard characters in the query to search for data. The asterisk (*) matches a string of any length at, before, or after a search term. The question mark (?) matches a single character in a specific position. The string can start with an asterisk (*) or a question mark (?). For example, if you search for the "table*e" string, "tablestore" can be matched.

The *word* string is equivalent to the WHERE field_a LIKE '%word%' clause in SQL. If you want to search for the *word* string, you can perform a fuzzy query that provides higher performance than a wildcard query. For more information about how to perform a fuzzy query, see Fuzzy query. If you perform a fuzzy query, the query performance is not compromised when the data volume increases.

Note If you want to use the NOT LIKE operator, you must use WildcardQuery together with must_not_queries of BoolQuery.

Prerequisites

  • An OTSClient instance is initialized. For more information, see Initialization.
  • A data table is created. Data is written to the table.
  • A search index is created for the data table. For more information, see Create search indexes.

Parameters

ParameterDescription
table_nameThe name of the data table.
index_nameThe name of the search index.
offsetThe position from which the current query starts.
limitThe maximum number of rows that you want the current query to return.
get_total_countSpecifies whether to return the total number of rows that meet the query conditions. The default value of this parameter is false, which indicates that the total number of rows that meet the query conditions is not returned.

If you set the get_total_count parameter to true, the query performance is compromised.

query_typeThe query type. To use wildcard query, set this parameter to QueryTypeConst::WILDCARD_QUERY.
field_nameThe name of the column.
valueThe string that contains wildcard characters. The string cannot exceed 32 characters in length.
sortThe method that you want to use to sort the rows in the response. For more information, see Sorting and paging.
columns_to_getSpecifies whether to return all columns of each row that meets the query conditions. You can configure return_type and return_names for this parameter.
  • If you set the return_type parameter to ColumnReturnTypeConst::RETURN_SPECIFIED, you can use return_names to specify the columns that you want to return.
  • If you set the return_type parameter to ColumnReturnTypeConst::RETURN_ALL, all columns are returned.
  • If you set the return_type parameter to ColumnReturnTypeConst::RETURN_ALL_FROM_INDEX, all columns in the search index are returned.
  • If you set the return_type parameter to ColumnReturnTypeConst::RETURN_NONE, only the primary key columns are returned.

Examples

$request = array(
    'table_name' => 'php_sdk_test',
    'index_name' => 'php_sdk_test_search_index',
    'search_query' => array(
        'offset' => 0,
        'limit' => 2,
        'get_total_count' => true,
        'query' => array(
            'query_type' => QueryTypeConst::WILDCARD_QUERY,
            'query' => array(
                'field_name' => 'keyword',
                'value' => 'key*'
            )
        ),
        'sort' => array(
            array(
                'field_sort' => array(
                    'field_name' => 'keyword',
                    'order' => SortOrderConst::SORT_ORDER_ASC
                )
            ),
        )
    ),
    'columns_to_get' => array(
        'return_type' => ColumnReturnTypeConst::RETURN_SPECIFIED,
        'return_names' => array('keyword')
    )
);
$response = $otsClient->search($request);