當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。