當前位置: 首頁>>代碼示例>>Python>>正文


Python search.SortOptions方法代碼示例

本文整理匯總了Python中google.appengine.api.search.SortOptions方法的典型用法代碼示例。如果您正苦於以下問題:Python search.SortOptions方法的具體用法?Python search.SortOptions怎麽用?Python search.SortOptions使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在google.appengine.api.search的用法示例。


在下文中一共展示了search.SortOptions方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: search_query

# 需要導入模塊: from google.appengine.api import search [as 別名]
# 或者: from google.appengine.api.search import SortOptions [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: search

# 需要導入模塊: from google.appengine.api import search [as 別名]
# 或者: from google.appengine.api.search import SortOptions [as 別名]
def search(
      cls, query_string='', query_limit=20, cursor=None, sort_options=None,
      returned_fields=None):
    """Searches for documents that match a given query string.

    Args:
      query_string: str, the query to match against documents in the index
      query_limit: int, the limit on number of documents to return in results.
      cursor: search.Cursor, a cursor describing where to get the next set of
          results, or to provide next cursors in SearchResults.
      sort_options: search.SortOptions, an object specifying a multi-dimensional
          sort over search results.
      returned_fields: List[str], an iterable of names of fields to return in
          search results.

    Returns:
      A SearchResults object containing a list of documents matched by the
          query.
    """
    index = cls.get_index()

    try:
      query = search.Query(
          query_string=cls.format_query(query_string),
          options=search.QueryOptions(
              cursor=cursor, limit=query_limit, sort_options=sort_options,
              returned_fields=returned_fields),
      )
    except search.QueryError:
      return search.SearchResults(number_found=0)

    return index.search(query) 
開發者ID:google,項目名稱:loaner,代碼行數:34,代碼來源:base_model.py

示例3: set_search_query_options

# 需要導入模塊: from google.appengine.api import search [as 別名]
# 或者: from google.appengine.api.search import SortOptions [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

示例4: find

# 需要導入模塊: from google.appengine.api import search [as 別名]
# 或者: from google.appengine.api.search import SortOptions [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

示例5: query_options

# 需要導入模塊: from google.appengine.api import search [as 別名]
# 或者: from google.appengine.api.search import SortOptions [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


注:本文中的google.appengine.api.search.SortOptions方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。