当前位置: 首页>>代码示例>>Python>>正文


Python search.SortExpression方法代码示例

本文整理汇总了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 
开发者ID:tkm2261,项目名称:kaggler_ja_slack_archiver,代码行数:27,代码来源:search_api.py

示例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 
开发者ID:google,项目名称:loaner,代码行数:42,代码来源:search_utils.py

示例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 
开发者ID:colohan,项目名称:dschat,代码行数:12,代码来源:messageindex.py

示例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) 
开发者ID:GoogleCloudPlatform,项目名称:python-docs-samples,代码行数:36,代码来源:snippets.py

示例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
    )] 
开发者ID:google,项目名称:personfinder,代码行数:13,代码来源:full_text_search.py


注:本文中的google.appengine.api.search.SortExpression方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。