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


Python search.Document方法代碼示例

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


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

示例1: to_document

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

# 需要導入模塊: from google.appengine.api import search [as 別名]
# 或者: from google.appengine.api.search import Document [as 別名]
def test_clear_index(self):
    test_index = Test.get_index()
    test_index.put([
        search.Document(
            doc_id='test_id_one', fields=[
                search.TextField(name='field_one', value='value_one')]),
        search.Document(
            doc_id='test_id_two', fields=[
                search.AtomField(name='field_two', value='value_two')]),
        search.Document(
            doc_id='test_id_three', fields=[
                search.NumberField(name='field_three', value=3)])])
    # Ensure both docs were added to the index.
    self.assertLen(test_index.get_range(ids_only=True), 3)
    Test.clear_index()
    # Ensure the index was cleared.
    self.assertFalse(test_index.get_range(ids_only=True)) 
開發者ID:google,項目名稱:loaner,代碼行數:19,代碼來源:base_model_test.py

示例3: test_search

# 需要導入模塊: from google.appengine.api import search [as 別名]
# 或者: from google.appengine.api.search import Document [as 別名]
def test_search(self):
    index = Test.get_index()
    test_doc = search.Document(
        doc_id='test_doc_id_1',
        fields=[search.TextField(name='text_field', value='item 1')])
    not_used_doc = search.Document(
        doc_id='test_doc_id_2',
        fields=[search.TextField(name='text_field', value='item 2')])
    not_used_doc2 = search.Document(
        doc_id='test_doc_id_3',
        fields=[search.TextField(name='text_field', value='notused')])
    index.put(test_doc)
    index.put(not_used_doc)
    index.put(not_used_doc2)
    actual_search_result = Test.search(query_string='item', query_limit=1)
    self.assertEqual(actual_search_result.number_found, 2)
    self.assertLen(actual_search_result.results, 1)

    no_search_results = Test.search(query_string='does_not_exist')
    self.assertEqual(no_search_results.number_found, 0) 
開發者ID:google,項目名稱:loaner,代碼行數:22,代碼來源:base_model_test.py

示例4: _create_doc

# 需要導入模塊: from google.appengine.api import search [as 別名]
# 或者: from google.appengine.api.search import Document [as 別名]
def _create_doc(self, report):
        doc_fields = [
            search.TextField(name='report_type', value=report.report_type),
            search.TextField(name='thread_id', value=report.thread_id),
            search.TextField(name='history_id', value=report.history_id),
            search.DateField(name='date_received', value=report.date_received),
            search.DateField(name='date_reported', value=report.date_reported),
            search.DateField(name='date_responded', value=report.date_responded),
            search.TextField(name='has_responded', value=str(report.has_responded)),
            search.TextField(name='status', value=report.status),
            search.TextField(name='sender', value=str(report.sender)),
            search.TextField(name='reported_by', value=report.reported_by),
            search.TextField(name='subject', value=report.subject),
            search.HtmlField(name='html', value=report.html),
            search.TextField(name='text', value=report.text)
        ]
        return search.Document(doc_id=str(report.key.id()), fields=doc_fields) 
開發者ID:duo-labs,項目名稱:isthislegit,代碼行數:19,代碼來源:search.py

示例5: create_document

# 需要導入模塊: from google.appengine.api import search [as 別名]
# 或者: from google.appengine.api.search import Document [as 別名]
def create_document():
    document = search.Document(
        # Setting the doc_id is optional. If omitted, the search service will
        # create an identifier.
        doc_id='PA6-5000',
        fields=[
            search.TextField(name='customer', value='Joe Jackson'),
            search.HtmlField(
                name='comment', value='this is <em>marked up</em> text'),
            search.NumberField(name='number_of_visits', value=7),
            search.DateField(name='last_visit', value=datetime.now()),
            search.DateField(
                name='birthday', value=datetime(year=1960, month=6, day=19)),
            search.GeoField(
                name='home_location', value=search.GeoPoint(37.619, -122.37))
        ])
    return document 
開發者ID:GoogleCloudPlatform,項目名稱:python-docs-samples,代碼行數:19,代碼來源:snippets.py

示例6: _index_employees

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

示例7: put_one_document

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

示例8: test_index_entities_for_search

# 需要導入模塊: from google.appengine.api import search [as 別名]
# 或者: from google.appengine.api.search import Document [as 別名]
def test_index_entities_for_search(self, mock_to_document):
    base_model.search.MAXIMUM_DOCUMENTS_PER_PUT_REQUEST = 1
    test_entity_1_key = Test(text_field='item_1').put()
    test_entity_2_key = Test(text_field='item_2').put()
    documents = [
        search.Document(
            doc_id=test_entity_1_key.urlsafe(),
            fields=[search.TextField(name='text_field', value='item_1')]),
        search.Document(
            doc_id=test_entity_2_key.urlsafe(),
            fields=[search.TextField(name='text_field', value='item_2')]),]
    mock_to_document.side_effect = documents
    Test.index_entities_for_search()
    self.assertEqual(mock_to_document.call_count, 2) 
開發者ID:google,項目名稱:loaner,代碼行數:16,代碼來源:base_model_test.py

示例9: test_add_docs_to_index

# 需要導入模塊: from google.appengine.api import search [as 別名]
# 或者: from google.appengine.api.search import Document [as 別名]
def test_add_docs_to_index(self):
    base_model.BaseModel._INDEX_NAME = 'test'
    test_index = base_model.BaseModel.get_index()
    base_model.BaseModel.add_docs_to_index([search.Document(
        doc_id='test_id', fields=[
            search.TextField(name='field_one', value='value_one')])])
    self.assertIsInstance(
        test_index.get_range(
            start_id='test_id', limit=1, include_start_object=True)[0],
        search.Document) 
開發者ID:google,項目名稱:loaner,代碼行數:12,代碼來源:base_model_test.py

示例10: test_add_docs_to_index_put_error

# 需要導入模塊: from google.appengine.api import search [as 別名]
# 或者: from google.appengine.api.search import Document [as 別名]
def test_add_docs_to_index_put_error(self, mock_put):
    mock_put.side_effect = [
        search.PutError(message='Fail!', results=[
            search.PutResult(code=search.OperationResult.TRANSIENT_ERROR)]),
        None]
    base_model.BaseModel.add_docs_to_index([search.Document(
        doc_id='test_id', fields=[
            search.TextField(name='field_one', value='value_one')])])
    self.assertEqual(mock_put.call_count, 2) 
開發者ID:google,項目名稱:loaner,代碼行數:11,代碼來源:base_model_test.py

示例11: test_add_docs_to_index_error

# 需要導入模塊: from google.appengine.api import search [as 別名]
# 或者: from google.appengine.api.search import Document [as 別名]
def test_add_docs_to_index_error(self, mock_error, mock_put, mock_logging):
    mock_put.side_effect = mock_error
    base_model.BaseModel.add_docs_to_index([search.Document(
        doc_id='test_id', fields=[
            search.TextField(name='field_one', value='value_one')])])
    self.assertEqual(mock_put.call_count, 1)
    self.assertEqual(mock_logging.error.call_count, 1) 
開發者ID:google,項目名稱:loaner,代碼行數:9,代碼來源:base_model_test.py

示例12: test_remove_doc_by_id

# 需要導入模塊: from google.appengine.api import search [as 別名]
# 或者: from google.appengine.api.search import Document [as 別名]
def test_remove_doc_by_id(self):
    base_model.BaseModel._INDEX_NAME = 'test'
    test_index = base_model.BaseModel.get_index()
    test_index.put([search.Document(
        doc_id='test_id', fields=[
            search.TextField(name='field_one', value='value_one')])])
    base_model.BaseModel.remove_doc_by_id('test_id')
    test_response = test_index.get_range(
        start_id='test_id', limit=1, include_start_object=True)
    self.assertIsInstance(test_response, search.GetResponse)
    self.assertEqual(test_response.results, []) 
開發者ID:google,項目名稱:loaner,代碼行數:13,代碼來源:base_model_test.py

示例13: test_to_document

# 需要導入模塊: from google.appengine.api import search [as 別名]
# 或者: from google.appengine.api.search import Document [as 別名]
def test_to_document(self, mock_get_document_fields):
    test_model = Test(id='fake')
    fields = [search.AtomField(name='text_field', value='12345ABC')]
    mock_get_document_fields.return_value = fields
    test_document = search.Document(
        doc_id=six.ensure_str(test_model.key.urlsafe()), fields=fields)
    result = test_model.to_document()
    self.assertEqual(result, test_document) 
開發者ID:google,項目名稱:loaner,代碼行數:10,代碼來源:base_model_test.py

示例14: add_faceted_document

# 需要導入模塊: from google.appengine.api import search [as 別名]
# 或者: from google.appengine.api.search import Document [as 別名]
def add_faceted_document(index):
    document = search.Document(
        doc_id='doc1',
        fields=[
            search.AtomField(name='name', value='x86')],
        facets=[
            search.AtomFacet(name='type', value='computer'),
            search.NumberFacet(name='ram_size_gb', value=8)])

    index.put(document) 
開發者ID:GoogleCloudPlatform,項目名稱:python-docs-samples,代碼行數:12,代碼來源:snippets.py

示例15: document

# 需要導入模塊: from google.appengine.api import search [as 別名]
# 或者: from google.appengine.api.search import Document [as 別名]
def document():
    return search.Document(
        doc_id='doc1',
        fields=[
            search.TextField(name='title', value='Meep: A biography')]) 
開發者ID:GoogleCloudPlatform,項目名稱:python-docs-samples,代碼行數:7,代碼來源:snippets_test.py


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