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


Python search.TextField方法代碼示例

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


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

示例1: test_clear_index

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

示例2: _create_doc

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

示例3: create_document

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

示例4: _index_employees

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

# 需要導入模塊: from google.appengine.api import search [as 別名]
# 或者: from google.appengine.api.search import TextField [as 別名]
def create_fields_for_rank(field_name, values):
    """
    Creates fields for ranking. (person name match > location match)
    MatchScorer class(assigns score) doesn't support to assign
    a score based on term frequency in a field.
    So we add 5 fields for each name params.
    Args:
        field_name: field name
        values: field values
    Returns:
        array of appengine_search.TextField(name=field_name, value=value)
           (length: REPEAT_COUNT_FOR_RANK)
    """
    if not values:
        return []

    fields = []
    for index, value in enumerate(values):
        for x in xrange(REPEAT_COUNT_FOR_RANK):
            fields.append(
                appengine_search.TextField(name='%s_%d_for_rank_%d' % (
                    field_name, index, x),
                                           value=value))
    return fields 
開發者ID:google,項目名稱:personfinder,代碼行數:26,代碼來源:full_text_search.py

示例7: create_full_name_without_space_fields

# 需要導入模塊: from google.appengine.api import search [as 別名]
# 或者: from google.appengine.api.search import TextField [as 別名]
def create_full_name_without_space_fields(romanize_method, given_name,
                                          family_name):
    """
    Creates fields with the full name without white spaces.
    Returns:
        fullname fields, romanized_name_list: (for check)
    """
    fields = []
    romanized_name_list = []
    romanized_given_names = romanize_method(given_name)
    romanized_family_names = romanize_method(family_name)
    romanize_method_name = romanize_method.__name__
    full_names = create_full_name_list_without_space(
        romanized_given_names, romanized_family_names)
    for index, full_name in enumerate(full_names):
        fields.append(appengine_search.TextField(
            name='no_space_full_name_romanized_by_%s_%d' % (
                romanize_method_name, index),
            value=full_name))
        romanized_name_list.append(full_name)
    return fields, romanized_name_list 
開發者ID:google,項目名稱:personfinder,代碼行數:23,代碼來源:full_text_search.py

示例8: create_romanized_location_fields

# 需要導入模塊: from google.appengine.api import search [as 別名]
# 或者: from google.appengine.api.search import TextField [as 別名]
def create_romanized_location_fields(romanize_method, **kwargs):
    """
    Creates romanized location fields (romanized by romanize_method)
    for full text search.
    """
    fields = []
    romanize_method_name = romanize_method.__name__
    for field in kwargs:
        romanized_locations = romanize_method(kwargs[field])
        for index, romanized_location in enumerate(romanized_locations):
            fields.append(
                appengine_search.TextField(
                    name='%s_romanized_by_%s_%d' % (
                        field, romanize_method_name, index),
                    value=romanized_location)
            )
    full_romanized_location = ':'.join(
        location.value for location in fields if location.value)
    fields.append(appengine_search.TextField(
        name='full_location_romanized_by_' + romanize_method_name,
        value=full_romanized_location))
    return fields 
開發者ID:google,項目名稱:personfinder,代碼行數:24,代碼來源:full_text_search.py

示例9: _to_search_fields

# 需要導入模塊: from google.appengine.api import search [as 別名]
# 或者: from google.appengine.api.search import TextField [as 別名]
def _to_search_fields(self, key, value):
    """Converts an ndb.Property into a search document field.

    Args:
      key: str, the name of the field.
      value: ndb.Property, the value to convert.

    Returns:
      A list of search fields created from the specified property. Repeated
          properties will create one field per item.
    """
    if value is None:
      return []

    if isinstance(value, list):
      search_fields = []
      for val in value:
        search_fields.extend(self._to_search_fields(key, val))
      return search_fields

    if isinstance(value, ndb.Key):
      return [search.AtomField(name=key, value=value.urlsafe())]

    if isinstance(value, (datetime.datetime, datetime.date)):
      return [search.DateField(name=key, value=value)]

    if isinstance(value, bool):
      return [search.AtomField(name=key, value=str(value))]

    if isinstance(value, numbers.Number) and not isinstance(value, bool):
      return [search.NumberField(name=key, value=value)]

    if isinstance(value, ndb.GeoPt):
      return [search.GeoField(
          name=key, value=search.GeoPoint(value.lat, value.lon))]

    return [
        search.TextField(name=key, value=six.text_type(value)),
        search.AtomField(name=key, value=six.text_type(value))
    ] 
開發者ID:google,項目名稱:loaner,代碼行數:42,代碼來源:base_model.py

示例10: test_index_entities_for_search

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

示例11: test_add_docs_to_index

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

示例12: test_add_docs_to_index_put_error

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

示例13: test_add_docs_to_index_error

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

示例14: test_remove_doc_by_id

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

示例15: test_to_seach_fields

# 需要導入模塊: from google.appengine.api import search [as 別名]
# 或者: from google.appengine.api.search import TextField [as 別名]
def test_to_seach_fields(self):
    # Test list field generation.
    entity = TestEntity(test_repeatedprop=['item_1', 'item_2'])
    search_fields = entity._to_search_fields(
        'test_repeatedprop', ['item_1', 'item_2'])
    expected_fields = [
        search.TextField(name='test_repeatedprop', value='item_1'),
        search.AtomField(name='test_repeatedprop', value='item_1'),
        search.TextField(name='test_repeatedprop', value='item_2'),
        search.AtomField(name='test_repeatedprop', value='item_2')]
    self.assertEqual(expected_fields, search_fields)

    # Test ndb.Key field generation.
    test_key = ndb.Key('Test', 1)
    entity = TestEntity(test_keyproperty=test_key)
    search_field = entity._to_search_fields('test_keyproperty', test_key)
    expected_field = [search.AtomField(
        name='test_keyproperty', value=test_key.urlsafe())]
    self.assertEqual(expected_field, search_field)

    # Test datetime field generation.
    date = datetime.datetime(year=2017, month=1, day=5)
    entity = TestEntity(test_datetime=date)
    search_field = entity._to_search_fields('test_datetime', date)
    expected_field = [search.DateField(name='test_datetime', value=date)]
    self.assertEqual(expected_field, search_field)

    # Test boolean field generation.
    entity = TestEntity(test_bool=True)
    search_field = entity._to_search_fields('test_bool', True)
    expected_field = [search.AtomField(name='test_bool', value='True')]
    self.assertEqual(expected_field, search_field)

    # Test geopt field generation.
    geopt = ndb.GeoPt('52.37, 4.88')
    entity = TestEntity(test_geopt=geopt)
    search_field = entity._to_search_fields('test_geopt', geopt)
    expected_field = [search.GeoField(
        name='test_geopt', value=search.GeoPoint(52.37, 4.88))]
    self.assertEqual(expected_field, search_field) 
開發者ID:google,項目名稱:loaner,代碼行數:42,代碼來源:base_model_test.py


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