MatchAllQuery

MatchAllQuery用于匹配所有行,常用于查询表中数据总行数,或者查看表中任意几条数据。

query = MatchAllQuery()
all_rows = []
next_token = None

while not all_rows or next_token:
    rows, next_token, total_count, is_all_succeed = client.search(table_name, index_name,
        SearchQuery(query, next_token=next_token, limit=100, get_total_count=True),
        columns_to_get=ColumnsToGet(['k', 't', 'g', 'ka', 'la'], ColumnReturnType.SPECIFIED))
    all_rows.extend(rows)

for row in all_rows:
    print row

print 'Total rows:', len(all_rows)

MatchQuery

MatchQuery采用近似匹配的方式查询表中的数据。

比如查询的值为"this is", 可以匹配到“...,this is tablestore”、“is this tablestore”、“tablestore is cool”、“this"、“is”等。

query = MatchQuery('t', 'this is 0')
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)
)

MatchPhraseQuery

使用MatchPhraseQuery进行短语匹配查询。短语匹配查询与匹配查询类似,但是要求查询的短语必须完整的按照顺序匹配。比如查询的值为“this is”,可以匹配到“...,this is tablestore”、"this is a table”,但是无法匹配到"this table is ..."以及"is this a table"。

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)
)