当前位置: 首页>>代码示例>>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;未经允许,请勿转载。