Match phrase query is similar to match query, but evaluates the position between multiple tokens. A row meets the query condition only when the order and position of the tokens in the row match those of the tokens contained in the tokenized keyword.

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
field_name The name of the column used to match the query conditions.

Match query applies to TEXT columns.

text The keyword used for the query to match the column values.

If the column used for the match query is a TEXT column, the keyword is tokenized into multiple keywords based on the analyzer you set when you create the search index. By default, single-word tokenization is performed if you do not set the analyzer when you create the search index.

For example, if you use the phrase "this is" as the keyword for a query, you can obtain query results such as "..., this is tablestore" and "this is a table". Query results such as "this table is ..." or "is this a table" cannot be obtained.

query The query type. To use phrase query, set this parameter to MatchPhraseQuery.
table_name The name of the table.
index_name The name of the search index.
limit The maximum number of rows that the current query returns.

To query only the number of matched rows but not detailed data, you can set limit to 0. In this case, Tablestore returns the number of matched rows without data from the table.

get_total_count Specify whether to return the total number of rows that match the query conditions. By default, this parameter is set to False, which indicates that the total number of rows that match the query conditions is not returned.

Query performance is affected when this parameter is set to true.

columns_to_get Specifies whether to return all columns of each matched rows.
  • If you set return_type to ColumnReturnType.SPECIFIED, you can use column_names to specify the columns to return.
  • If you set return_type to ColumnReturnType.ALL, all columns are returned.
  • If you set return_type to ColumnReturnType.NONE, only the primary key columns are returned.

Examples

query = MatchPhraseQuery('t', 'this is')
rows, next_token, total_count, is_all_succeed = client.search(
    table_name, index_name, 
    SearchQuery(query, limit=100, get_total_count=True), 
    ColumnsToGet(return_type=ColumnReturnType.ALL)
)