本文整理匯總了Python中google.appengine.api.search.SortExpression方法的典型用法代碼示例。如果您正苦於以下問題:Python search.SortExpression方法的具體用法?Python search.SortExpression怎麽用?Python search.SortExpression使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類google.appengine.api.search
的用法示例。
在下文中一共展示了search.SortExpression方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: search_query
# 需要導入模塊: from google.appengine.api import search [as 別名]
# 或者: from google.appengine.api.search import SortExpression [as 別名]
def search_query(self, query_string, page=0):
# Create sort options to sort on price and brand.
sort_ts = search.SortExpression(
expression='ts',
direction=search.SortExpression.DESCENDING,
default_value=0)
sort_options = search.SortOptions(expressions=[sort_ts])
# Create query options using the sort options and expressions created
# above.
query_options = search.QueryOptions(
limit=self.MSG_PER_PAGE_NUM,
offset=page * self.MSG_PER_PAGE_NUM,
returned_fields=['msg_key'],
sort_options=sort_options)
# Build the Query and run the search
try:
query = search.Query(query_string=query_string, options=query_options)
except search.QueryError:
return []
results = self.index.search(query)
return results
示例2: set_search_query_options
# 需要導入模塊: from google.appengine.api import search [as 別名]
# 或者: from google.appengine.api.search import SortExpression [as 別名]
def set_search_query_options(request):
"""Sets the search query options based on a ProtoRPC request message.
Args:
request: messages.Message, The message that contains the values of the
query options.
Returns:
A tuple containing the values of query options if they exist in the
message.
"""
try:
query = request.query_string
except AttributeError:
query = None
expressions = []
sort_options = None
try:
for message_expression in request.expressions:
direction = search.SortExpression.DESCENDING
if (message_expression.direction ==
shared_messages.SortDirection.ASCENDING):
direction = search.SortExpression.ASCENDING
expressions.append(
search.SortExpression(
expression=message_expression.expression, direction=direction))
if expressions:
sort_options = search.SortOptions(expressions=expressions)
except AttributeError:
# We do not want to do anything if the message does not have expressions
# since sort_options is already set to None above.
pass
try:
returned_fields = request.returned_fields
except AttributeError:
returned_fields = None
return query, sort_options, returned_fields
示例3: find
# 需要導入模塊: from google.appengine.api import search [as 別名]
# 或者: from google.appengine.api.search import SortExpression [as 別名]
def find(query, count=10):
sort_opts = search.SortOptions(expressions=[search.SortExpression(
expression="date", direction=search.SortExpression.ASCENDING)])
query_options = search.QueryOptions(limit=count, sort_options=sort_opts)
query_obj = search.Query(query_string=query, options=query_options)
results = index.search(query=query_obj)
keys = []
for result in results:
keys.append(result.doc_id)
return keys
示例4: query_options
# 需要導入模塊: from google.appengine.api import search [as 別名]
# 或者: from google.appengine.api.search import SortExpression [as 別名]
def query_options():
index = search.Index('products')
query_string = "product: piano AND price < 5000"
# Create sort options to sort on price and brand.
sort_price = search.SortExpression(
expression='price',
direction=search.SortExpression.DESCENDING,
default_value=0)
sort_brand = search.SortExpression(
expression='brand',
direction=search.SortExpression.DESCENDING,
default_value="")
sort_options = search.SortOptions(expressions=[sort_price, sort_brand])
# Create field expressions to add new fields to the scored documents.
price_per_note_expression = search.FieldExpression(
name='price_per_note', expression='price/88')
ivory_expression = search.FieldExpression(
name='ivory', expression='snippet("ivory", summary, 120)')
# Create query options using the sort options and expressions created
# above.
query_options = search.QueryOptions(
limit=25,
returned_fields=['model', 'price', 'description'],
returned_expressions=[price_per_note_expression, ivory_expression],
sort_options=sort_options)
# Build the Query and run the search
query = search.Query(query_string=query_string, options=query_options)
results = index.search(query)
for scored_document in results:
print(scored_document)
示例5: create_sort_expressions
# 需要導入模塊: from google.appengine.api import search [as 別名]
# 或者: from google.appengine.api.search import SortExpression [as 別名]
def create_sort_expressions():
"""
Creates SortExpression's for ranking.
Returns:
array of SortExpression
"""
return [appengine_search.SortExpression(
expression='_score',
direction=appengine_search.SortExpression.DESCENDING,
default_value=0.0
)]