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


Python search.DateField方法代码示例

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


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

示例1: _create_doc

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

示例2: create_document

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

示例3: put_one_document

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

示例4: _to_search_fields

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

示例5: test_to_seach_fields

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

示例6: add

# 需要导入模块: from google.appengine.api import search [as 别名]
# 或者: from google.appengine.api.search import DateField [as 别名]
def add(doc_id, message):
    index.put(search.
              Document(doc_id=doc_id,
                       fields=
                       [search.TextField(name='author',
                                         value=message.author.nickname),
                        search.TextField(name='email',
                                         value=message.author.email),
                        search.TextField(name='topic',
                                         value=message.topic),
                        search.TextField(name='content',
                                         value=message.content),
                        search.DateField(name='date', value=message.date)])) 
开发者ID:colohan,项目名称:dschat,代码行数:15,代码来源:messageindex.py


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