You can use asterisks (*) and question marks (?) as wildcards to search for data. An asterisk (*) can represent any number of characters. A question mark (?) can represent any single character. The value to query can start with an asterisk (*) or a question mark (?). For example, you can match query results such as "tablestore" by searching for "table*e".

Prerequisites

  • The 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 table. For more information, see Create search indexes.

Parameters

Parameter Description
table_name The name of the table.
index_name The name of the search index.
offset Specifies the position from which the current query starts.
limit Specifies the maximum number of items that the current query returns.
get_total_count Specifies whether to return the total number of matched rows. The default value is false, which indicates that the total number of rows in the table is not returned.

If get_total_count is set to true, the query performance is affected.

query_type The query type. Set the query type to QueryTypeConst::WILDCARD_QUERY.
field_name The column name.
value The string that contains wildcards. The string cannot exceed 20 characters in length.
sort The sorting method. Sort based on the specified method. For more information, see Sorting and pagination.
columns_to_get Specifies whether to return all columns.
  • If you set return_type to ColumnReturnTypeConst::RETURN_SPECIFIED, you must use return_names to specify the columns to be returned.
  • If return_type is set to ColumnReturnTypeConst::RETURN_ALL, all columns are returned.
  • If you set return_type 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);