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.
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
Parameter | Description |
---|---|
table_name | The name of the data table. |
index_name | The name of the search index. |
offset | The position from which the current query starts. |
limit | The maximum number of rows that you want the current query to return. |
get_total_count | Specifies 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_type | The query type. To use wildcard query, set this parameter to QueryTypeConst::WILDCARD_QUERY . |
field_name | The name of the column. |
value | The string that contains wildcard characters. The string cannot exceed 32 characters in length. |
sort | The method that you want to use to sort the rows in the response. For more information, see Sorting and paging. |
columns_to_get | Specifies whether to return all columns of each row that meets the query conditions. You can configure return_type and return_names for this parameter.
|
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);