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


Python search.Index方法代码示例

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


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

示例1: to_document

# 需要导入模块: from google.appengine.api import search [as 别名]
# 或者: from google.appengine.api.search import Index [as 别名]
def to_document(self):
    """Creates a search.Document representation of a model.

    Returns:
      search.Document of the current model to be indexed with a valid doc_id. A
          doc_id will be autogenerated when inserted into the Index if one is
          not provided.

    Raises:
      DocumentCreationError: when unable to create a document for the
          model.
    """
    try:
      return search.Document(
          doc_id=six.ensure_str(self.key.urlsafe()),
          fields=self._get_document_fields())

    except (TypeError, ValueError) as e:
      raise DocumentCreationError(e) 
开发者ID:google,项目名称:loaner,代码行数:21,代码来源:base_model.py

示例2: get

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

示例3: post

# 需要导入模块: from google.appengine.api import search [as 别名]
# 或者: from google.appengine.api.search import Index [as 别名]
def post(self):
    index_name = self.request.get('index')
    namespace = self.request.get('namespace')
    start = self.request.get_range('start', min_value=0, default=0)

    index = 0
    num_docs = int(self.request.get('numdocs'))
    docs = self.request.params.getall('doc_id')
    if len(docs) == num_docs:
      start = max(0, start - self._MAX_RESULTS_PER_PAGE)

    index = search.Index(name=index_name, namespace=namespace)
    index.delete(docs)
    self.redirect('/search/index?%s' % urllib.urlencode(
        {'namespace': namespace,
         'index': index_name,
         'start': start})) 
开发者ID:elsigh,项目名称:browserscope,代码行数:19,代码来源:search_handler.py

示例4: _index_employees

# 需要导入模块: from google.appengine.api import search [as 别名]
# 或者: from google.appengine.api.search import Index [as 别名]
def _index_employees(employees):
    logging.info('Indexing employees... {}MB'.format(memory_usage().current()))
    index = search.Index(name=INDEX_NAME)
    # According to appengine, put can handle a maximum of 200 documents,
    # and apparently batching is more efficient
    for chunk_of_200 in chunk(employees, 200):
        documents = []
        for employee in chunk_of_200:
            if employee is not None:
                # Gross hack to support prefix matching, see documentation for _generate_substrings
                substrings = u' '.join([
                    _generate_substrings(employee.first_name),
                    _generate_substrings(employee.last_name),
                    _generate_substrings(employee.username),
                ])
                doc = search.Document(fields=[
                    # Full name is already unicode
                    search.TextField(name='full_name', value=employee.full_name),
                    search.TextField(name='username', value=unicode(employee.username)),
                    search.TextField(name='substrings', value=substrings),
                ])
                documents.append(doc)
        index.put(documents)
    logging.info('Done indexing employees. {}MB'.format(memory_usage().current())) 
开发者ID:Yelp,项目名称:love,代码行数:26,代码来源:employee.py

示例5: put_one_document

# 需要导入模块: from google.appengine.api import search [as 别名]
# 或者: from google.appengine.api.search import Index [as 别名]
def put_one_document(self, msg):
        doc_id = '{channel_id}_{user}_{ts}'.format(channel_id=msg.channel_id, user=msg.user, ts=int(msg.ts))

        doc = search.Document(
            doc_id=doc_id,
            fields=[search.TextField(name='text', value=msg.text),
                    search.AtomField(name='user_name', value=msg.get_user_name()),
                    search.AtomField(name='channel_id', value=msg.channel_id),
                    search.AtomField(name='msg_key', value=str(msg.key.id())),
                    search.DateField(name='ts', value=msg.get_datetime()),
                    ]
        )
        # Index the document.
        try:
            self.index.put(doc)
        except search.PutError, e:
            result = e.results[0]
            if result.code == search.OperationResult.TRANSIENT_ERROR:
                # possibly retry indexing result.object_id
                return self.put_one_document(msg) 
开发者ID:tkm2261,项目名称:kaggler_ja_slack_archiver,代码行数:22,代码来源:search_api.py

示例6: get

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

示例7: post

# 需要导入模块: from google.appengine.api import search [as 别名]
# 或者: from google.appengine.api.search import Index [as 别名]
def post(self):
    super(SearchIndexHandler, self).post()
    index_name = self.request.get('index')
    namespace = self.request.get('namespace')
    start = self.request.get_range('start', min_value=0, default=0)

    index = 0
    num_docs = int(self.request.get('numdocs'))
    docs = self.request.params.getall('doc_id')
    if len(docs) == num_docs:
      start = max(0, start - self._MAX_RESULTS_PER_PAGE)

    index = search.Index(name=index_name, namespace=namespace)
    index.delete(docs)
    self.redirect('/search/index?%s' % urllib.urlencode(
        {'namespace': namespace,
         'index': index_name,
         'start': start})) 
开发者ID:GoogleCloudPlatform,项目名称:python-compat-runtime,代码行数:20,代码来源:search_handler.py

示例8: post

# 需要导入模块: from google.appengine.api import search [as 别名]
# 或者: from google.appengine.api.search import Index [as 别名]
def post(self):
    """Handle POST."""
    index_name = self.request.get('index')
    namespace = self.request.get('namespace')

    docs = []
    index = 0
    num_docs = int(self.request.get('numdocs'))
    for i in xrange(1, num_docs+1):
      key = self.request.get('doc%d' % i)
      if key:
        docs.append(key)

    index = search.Index(name=index_name, namespace=namespace)
    index.delete(docs)
    self.redirect(self.request.get('next')) 
开发者ID:GoogleCloudPlatform,项目名称:python-compat-runtime,代码行数:18,代码来源:__init__.py

示例9: test_get_search_index

# 需要导入模块: from google.appengine.api import search [as 别名]
# 或者: from google.appengine.api.search import Index [as 别名]
def test_get_search_index(self):
    self.assertIsInstance(device_model.Device.get_index(), search.Index) 
开发者ID:google,项目名称:loaner,代码行数:4,代码来源:device_model_test.py

示例10: get_index

# 需要导入模块: from google.appengine.api import search [as 别名]
# 或者: from google.appengine.api.search import Index [as 别名]
def get_index(cls):
    """Returns the search Index for a given model."""
    return search.Index(name=cls._INDEX_NAME) 
开发者ID:google,项目名称:loaner,代码行数:5,代码来源:base_model.py

示例11: test_get_search_index

# 需要导入模块: from google.appengine.api import search [as 别名]
# 或者: from google.appengine.api.search import Index [as 别名]
def test_get_search_index(self):
    self.assertIsInstance(shelf_model.Shelf.get_index(), search.Index) 
开发者ID:google,项目名称:loaner,代码行数:4,代码来源:shelf_model_test.py

示例12: __init__

# 需要导入模块: from google.appengine.api import search [as 别名]
# 或者: from google.appengine.api.search import Index [as 别名]
def __init__(self):
        self.store = search.Index(name='isthislegit', namespace='reports') 
开发者ID:duo-labs,项目名称:isthislegit,代码行数:4,代码来源:search.py

示例13: delete

# 需要导入模块: from google.appengine.api import search [as 别名]
# 或者: from google.appengine.api.search import Index [as 别名]
def delete():
  """Deletes a document from the index."""
  try:
    response_dict = {}
    doc_id = request.args.get('id')
    search.Index(name='imagesearch').delete([doc_id])
    response_dict['result'] = 'ok'

  except search.DeleteError:
    logging.exception('Something went wrong in delete()')

  return jsonify(response_dict) 
开发者ID:GoogleCloudPlatform,项目名称:solutions-vision-search,代码行数:14,代码来源:main.py

示例14: add_document_to_index

# 需要导入模块: from google.appengine.api import search [as 别名]
# 或者: from google.appengine.api.search import Index [as 别名]
def add_document_to_index(document):
    index = search.Index('products')
    index.put(document) 
开发者ID:GoogleCloudPlatform,项目名称:python-docs-samples,代码行数:5,代码来源:snippets.py

示例15: add_document_and_get_doc_id

# 需要导入模块: from google.appengine.api import search [as 别名]
# 或者: from google.appengine.api.search import Index [as 别名]
def add_document_and_get_doc_id(documents):
    index = search.Index('products')
    results = index.put(documents)
    document_ids = [document.id for document in results]
    return document_ids 
开发者ID:GoogleCloudPlatform,项目名称:python-docs-samples,代码行数:7,代码来源:snippets.py


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