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


Python search.Query方法代码示例

本文整理汇总了Python中google.appengine.api.search.Query方法的典型用法代码示例。如果您正苦于以下问题:Python search.Query方法的具体用法?Python search.Query怎么用?Python search.Query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在google.appengine.api.search的用法示例。


在下文中一共展示了search.Query方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get

# 需要导入模块: from google.appengine.api import search [as 别名]
# 或者: from google.appengine.api.search import Query [as 别名]
def get(self):
    index_name = self.request.get('index')
    if not index_name:
      self.redirect('/search')
      return
    start = self.request.get_range('start', min_value=0, default=0)
    query = self.request.get('query')
    namespace = self.request.get('namespace')
    index = search.Index(name=index_name, namespace=namespace)
    resp = index.search(query=search.Query(
        query_string=query,
        options=search.QueryOptions(offset=start,
                                    limit=self._MAX_RESULTS_PER_PAGE)))
    has_more = resp.number_found > start + self._MAX_RESULTS_PER_PAGE

    values = {
        'namespace': namespace,
        'index': index_name,
        'start': start,
        'query': query,
        'values': self._process_search_response(resp),
    }
    self._handle_paging(start, has_more, values)
    self.response.write(self.render('search_index.html', values)) 
开发者ID:elsigh,项目名称:browserscope,代码行数:26,代码来源:search_handler.py

示例2: query_offset

# 需要导入模块: from google.appengine.api import search [as 别名]
# 或者: from google.appengine.api.search import Query [as 别名]
def query_offset(index, query_string):
    offset = 0

    while True:
        # Build the query using the current offset.
        options = search.QueryOptions(offset=offset)
        query = search.Query(query_string=query_string, options=options)

        # Get the results
        results = index.search(query)

        number_retrieved = len(results.results)
        if number_retrieved == 0:
            break

        # Add the number of documents found to the offset, so that the next
        # iteration will grab the next page of documents.
        offset += number_retrieved

        # Process the matched documents
        for document in results:
            print(document) 
开发者ID:GoogleCloudPlatform,项目名称:python-docs-samples,代码行数:24,代码来源:snippets.py

示例3: facet_by_name_and_value

# 需要导入模块: from google.appengine.api import search [as 别名]
# 或者: from google.appengine.api.search import Query [as 别名]
def facet_by_name_and_value(index):
    # Create the query and specify to return the "type" facet with values
    # "computer" and "printer" and the "ram_size_gb" facet with value in the
    # ranges [0,4), [4, 8), and [8, max].
    query = search.Query(
        'name:x86',
        return_facets=[
            search.FacetRequest('type', values=['computer', 'printer']),
            search.FacetRequest('ram_size_gb', ranges=[
                search.FacetRange(end=4),
                search.FacetRange(start=4, end=8),
                search.FacetRange(start=8)])
        ])

    results = index.search(query)
    for facet in results.facets:
        print('facet {}'.format(facet.name))
        for value in facet.values:
            print('{}: count={}, refinement_token={}'.format(
                value.label, value.count, value.refinement_token)) 
开发者ID:GoogleCloudPlatform,项目名称:python-docs-samples,代码行数:22,代码来源:snippets.py

示例4: search_query

# 需要导入模块: from google.appengine.api import search [as 别名]
# 或者: from google.appengine.api.search import Query [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

示例5: get

# 需要导入模块: from google.appengine.api import search [as 别名]
# 或者: from google.appengine.api.search import Query [as 别名]
def get(self):
    super(SearchIndexHandler, self).get()
    index_name = self.request.get('index')
    if not index_name:
      self.redirect('/search')
      return
    start = self.request.get_range('start', min_value=0, default=0)
    query = self.request.get('query')
    namespace = self.request.get('namespace')
    index = search.Index(name=index_name, namespace=namespace)
    resp = index.search(query=search.Query(
        query_string=query,
        options=search.QueryOptions(offset=start,
                                    limit=self._MAX_RESULTS_PER_PAGE)))
    has_more = resp.number_found > start + self._MAX_RESULTS_PER_PAGE

    values = {
        'namespace': namespace,
        'index': index_name,
        'start': start,
        'query': query,
        'values': self._process_search_response(resp),
    }
    self._handle_paging(start, has_more, values)
    self.response.write(self.render('search_index.html', values)) 
开发者ID:GoogleCloudPlatform,项目名称:python-compat-runtime,代码行数:27,代码来源:search_handler.py

示例6: search

# 需要导入模块: from google.appengine.api import search [as 别名]
# 或者: from google.appengine.api.search import Query [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

示例7: find

# 需要导入模块: from google.appengine.api import search [as 别名]
# 或者: from google.appengine.api.search import Query [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

示例8: query_options

# 需要导入模块: from google.appengine.api import search [as 别名]
# 或者: from google.appengine.api.search import Query [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

示例9: query_cursor

# 需要导入模块: from google.appengine.api import search [as 别名]
# 或者: from google.appengine.api.search import Query [as 别名]
def query_cursor(index, query_string):
    cursor = search.Cursor()

    while cursor:
        # Build the query using the cursor.
        options = search.QueryOptions(cursor=cursor)
        query = search.Query(query_string=query_string, options=options)

        # Get the results and the next cursor
        results = index.search(query)
        cursor = results.cursor

        for document in results:
            print(document) 
开发者ID:GoogleCloudPlatform,项目名称:python-docs-samples,代码行数:16,代码来源:snippets.py

示例10: query_per_document_cursor

# 需要导入模块: from google.appengine.api import search [as 别名]
# 或者: from google.appengine.api.search import Query [as 别名]
def query_per_document_cursor(index, query_string):
    cursor = search.Cursor(per_result=True)

    # Build the query using the cursor.
    options = search.QueryOptions(cursor=cursor)
    query = search.Query(query_string=query_string, options=options)

    # Get the results.
    results = index.search(query)

    document_cursor = None
    for document in results:
        # discover some document of interest and grab its cursor, for this
        # sample we'll just use the first document.
        document_cursor = document.cursor
        break

    # Start the next search from the document of interest.
    if document_cursor is None:
        return

    options = search.QueryOptions(cursor=document_cursor)
    query = search.Query(query_string=query_string, options=options)
    results = index.search(query)

    for document in results:
        print(document) 
开发者ID:GoogleCloudPlatform,项目名称:python-docs-samples,代码行数:29,代码来源:snippets.py

示例11: facet_discovery

# 需要导入模块: from google.appengine.api import search [as 别名]
# 或者: from google.appengine.api.search import Query [as 别名]
def facet_discovery(index):
    # Create the query and enable facet discovery.
    query = search.Query('name:x86', enable_facet_discovery=True)
    results = index.search(query)

    for facet in results.facets:
        print('facet {}.'.format(facet.name))
        for value in facet.values:
            print('{}: count={}, refinement_token={}'.format(
                value.label, value.count, value.refinement_token)) 
开发者ID:GoogleCloudPlatform,项目名称:python-docs-samples,代码行数:12,代码来源:snippets.py

示例12: employees_matching_prefix

# 需要导入模块: from google.appengine.api import search [as 别名]
# 或者: from google.appengine.api.search import Query [as 别名]
def employees_matching_prefix(prefix):
    """Returns a list of (full name, username) tuples for users that match the given prefix."""
    if not prefix:
        return []

    user_tuples = set()

    search_query = search.Query(
        query_string=prefix,
        options=search.QueryOptions(
            limit=15))
    results = search.Index(name=INDEX_NAME).search(search_query)
    for r in results:
        username, full_name = None, None
        for f in r.fields:
            if f.name == 'full_name':
                full_name = f.value
            elif f.name == 'username':
                username = f.value
            else:
                continue
        if username is not None and full_name is not None:
            photo_url = Employee.query(Employee.username == username).get().get_photo_url()
            user_tuples.add((full_name, username, photo_url))

    user_tuples = list(user_tuples)
    user_tuples.sort()
    return user_tuples 
开发者ID:Yelp,项目名称:love,代码行数:30,代码来源:employee.py

示例13: get

# 需要导入模块: from google.appengine.api import search [as 别名]
# 或者: from google.appengine.api.search import Query [as 别名]
def get(self):
    """Displays documents in a FTS index."""
    start = self.request.get_range('start', min_value=0, default=0)
    query = self.request.get('query')
    namespace = self.request.get('namespace')
    limit = self.request.get_range('num', min_value=1, max_value=100,
                                   default=10)
    index_name = self.request.get('index') or 'index'
    index = search.Index(name=index_name, namespace=namespace)
    resp = index.search(query=search.Query(
        query_string=query,
        options=search.QueryOptions(offset=start, limit=limit)))
    has_more = resp.number_found > start + limit

    current_page = start / limit + 1
    values = {
        'request': self.request,
        'namespace': namespace,
        'index': index_name,
        'query': query,
        'current_page': current_page,
        'next_start': -1,
        'prev_start': -1,
        'start_base_url': self.filter_url([
            'query', 'index', 'num', 'namespace']),
        'next': urllib.quote(ustr(self.request.uri)),
        'values': self._ProcessSearchResponse(resp),
        'prev': self.request.get(
            'next',
            default_value=self.base_path() + SearchIndexesListHandler.PATH)}
    if current_page > 1:
      values['prev_start'] = int((current_page - 2) * limit)
      values['paging'] = True
    if has_more:
      values['next_start'] = int(current_page * limit)
      values['paging'] = True

    self.generate('search_index.html', values) 
开发者ID:GoogleCloudPlatform,项目名称:python-compat-runtime,代码行数:40,代码来源:__init__.py

示例14: execute_query

# 需要导入模块: from google.appengine.api import search [as 别名]
# 或者: from google.appengine.api.search import Query [as 别名]
def execute_query(self, start=0, num=0, no_order=False):
    """Parses the URL arguments and executes the query.

    Args:
      start: How many entities from the beginning of the result list should be
        skipped from the query.
      num: How many entities should be returned, if 0 (default) then a
        reasonable default will be chosen.

    Returns:
      A tuple (list of entities, total entity count).  If inappropriate URL
      arguments are given, we return an empty set of results and 0 for the
      entity count.
    """
    kind = self.request.get('kind')
    namespace = self.request.get('namespace')
    if not namespace:
      namespace = None
    if not kind:
      return ([], 0)
    query = datastore.Query(kind, _namespace=namespace)


    order = self.request.get('order')
    order_type = self.request.get('order_type')
    if order and order_type:
      order_type = DataType.get_by_name(order_type).python_type()
      if order.startswith('-'):
        direction = datastore.Query.DESCENDING
        order = order[1:]
      else:
        direction = datastore.Query.ASCENDING
      try:
        query.Order((order, order_type, direction))
      except datastore_errors.BadArgumentError:

        pass

    if not start:
      start = self.start()
    if not num:
      num = self.num()
    total = query.Count()
    entities = query.Get(start + num)[start:]
    return (entities, total) 
开发者ID:GoogleCloudPlatform,项目名称:python-compat-runtime,代码行数:47,代码来源:__init__.py


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