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


Python DesignDocument.add_search_index方法代码示例

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


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

示例1: test_update_a_search_index_with_analyzer

# 需要导入模块: from cloudant.design_document import DesignDocument [as 别名]
# 或者: from cloudant.design_document.DesignDocument import add_search_index [as 别名]
 def test_update_a_search_index_with_analyzer(self):
     """
     Test that updating a search analyzer updates the contents of the correct
     search index object in the DesignDocument dictionary.
     """
     ddoc = DesignDocument(self.db, '_design/ddoc001')
     ddoc.add_search_index('search001',
                           'not-a-valid-search-index',
                           'email')
     self.assertEqual(
         ddoc.get('indexes')['search001'],
         {'index': 'not-a-valid-search-index', 'analyzer': 'email'}
     )
     ddoc.update_search_index(
         'search001',
         'function (doc) {\n  index("default", doc._id); '
         'if (doc._id) {index("name", doc.name, {"store": true}); }\n}',
         'simple'
     )
     self.assertEqual(
         ddoc.get('indexes')['search001'],
         {'index': 'function (doc) {\n  index("default", doc._id); '
             'if (doc._id) {index("name", doc.name, '
             '{"store": true}); }\n}',
          'analyzer': 'simple'
         }
     )
开发者ID:drarvindsathi,项目名称:python-cloudant,代码行数:29,代码来源:design_document_tests.py

示例2: test_search_index_save_fails_with_existing_text_index

# 需要导入模块: from cloudant.design_document import DesignDocument [as 别名]
# 或者: from cloudant.design_document.DesignDocument import add_search_index [as 别名]
 def test_search_index_save_fails_with_existing_text_index(self):
     """
     Tests that save fails when language is query and both a search index
     and a text index exist in the design document.
     """
     ddoc = DesignDocument(self.db, '_design/ddoc001')
     ddoc['language'] = 'query'
     ddoc['indexes']['index001'] = {
         'index': {'index_array_lengths': True,
                   'fields': [{'name': 'name', 'type': 'string'},
                              {'name': 'age', 'type': 'number'}],
                   'default_field': {'enabled': True, 'analyzer': 'german'},
                   'default_analyzer': 'keyword',
                   'selector': {}},
         'analyzer': {'name': 'perfield','default': 'keyword',
                      'fields': {'$default': 'german'}}}
     ddoc.save()
     self.assertTrue(ddoc['_rev'].startswith('1-'))
     search_index = ('function (doc) {\n  index("default", doc._id); '
                     'if (doc._id) {index("name", doc.name, '
                     '{"store": true}); }\n}')
     ddoc.add_search_index('search001', search_index)
     self.assertIsInstance(
         ddoc['indexes']['search001']['index'], str
     )
     with self.assertRaises(CloudantException) as cm:
         ddoc.save()
     err = cm.exception
     self.assertEqual(
         str(err),
         'Definition for query text index search001 must be of type dict.'
     )
开发者ID:drarvindsathi,项目名称:python-cloudant,代码行数:34,代码来源:design_document_tests.py

示例3: test_search_index_save_succeeds

# 需要导入模块: from cloudant.design_document import DesignDocument [as 别名]
# 或者: from cloudant.design_document.DesignDocument import add_search_index [as 别名]
 def test_search_index_save_succeeds(self):
     """
     Tests that save succeeds when no language is specified for search
     indexes.
     """
     ddoc = DesignDocument(self.db, '_design/ddoc001')
     search_index = ('function (doc) {\n  index("default", doc._id); '
                     'if (doc._id) {index("name", doc.name, '
                     '{"store": true}); }\n}')
     ddoc.add_search_index('search001', search_index)
     ddoc.save()
     self.assertTrue(ddoc['_rev'].startswith('1-'))
开发者ID:drarvindsathi,项目名称:python-cloudant,代码行数:14,代码来源:design_document_tests.py

示例4: test_get_search_index

# 需要导入模块: from cloudant.design_document import DesignDocument [as 别名]
# 或者: from cloudant.design_document.DesignDocument import add_search_index [as 别名]
 def test_get_search_index(self):
     """
     Test retrieval of a search index from the DesignDocument.
     """
     ddoc = DesignDocument(self.db, '_design/ddoc001')
     index = ('function (doc) {\n  index("default", doc._id); '
              'if (doc._id) {index("name", doc.name, '
              '{"store": true}); }\n}')
     ddoc.add_search_index('search001', index)
     ddoc.add_search_index('search002', index)
     ddoc.add_search_index('search003', index)
     self.assertEqual(
         ddoc.get_index('search002'),
         {'index': 'function (doc) {\n  index("default", doc._id); '
             'if (doc._id) {index("name", doc.name, '
             '{"store": true}); }\n}'}
     )
开发者ID:drarvindsathi,项目名称:python-cloudant,代码行数:19,代码来源:design_document_tests.py

示例5: test_iterating_over_search_indexes

# 需要导入模块: from cloudant.design_document import DesignDocument [as 别名]
# 或者: from cloudant.design_document.DesignDocument import add_search_index [as 别名]
 def test_iterating_over_search_indexes(self):
     """
     Test iterating over search indexes within the DesignDocument.
     """
     ddoc = DesignDocument(self.db, '_design/ddoc001')
     search_index = ('function (doc) {\n  index("default", doc._id); '
                     'if (doc._id) {index("name", doc.name, '
                     '{"store": true}); }\n}')
     ddoc.add_search_index('search001', search_index)
     ddoc.add_search_index('search002', search_index)
     ddoc.add_search_index('search003', search_index)
     search_index_names = []
     for search_index_name, search_index in ddoc.iterindexes():
         search_index_names.append(search_index_name)
     self.assertTrue(
         all(x in search_index_names for
             x in ['search001', 'search002', 'search003'])
     )
开发者ID:drarvindsathi,项目名称:python-cloudant,代码行数:20,代码来源:design_document_tests.py

示例6: test_add_a_search_index

# 需要导入模块: from cloudant.design_document import DesignDocument [as 别名]
# 或者: from cloudant.design_document.DesignDocument import add_search_index [as 别名]
 def test_add_a_search_index(self):
     """
     Test that adding a search index adds a search index object to
     the DesignDocument dictionary.
     """
     ddoc = DesignDocument(self.db, '_design/ddoc001')
     self.assertEqual(ddoc.get('indexes'), {})
     ddoc.add_search_index(
         'search001',
         'function (doc) {\n  index("default", doc._id); '
         'if (doc._id) {index("name", doc.name, {"store": true}); }\n}'
     )
     self.assertListEqual(list(ddoc.get('indexes').keys()), ['search001'])
     self.assertEqual(
         ddoc.get('indexes')['search001'],
         {'index': 'function (doc) {\n  index("default", doc._id); '
             'if (doc._id) {index("name", doc.name, {"store": true}); }\n}'}
      )
开发者ID:drarvindsathi,项目名称:python-cloudant,代码行数:20,代码来源:design_document_tests.py

示例7: test_list_search_indexes

# 需要导入模块: from cloudant.design_document import DesignDocument [as 别名]
# 或者: from cloudant.design_document.DesignDocument import add_search_index [as 别名]
 def test_list_search_indexes(self):
     """
     Test the retrieval of search index name list from DesignDocument.
     """
     ddoc = DesignDocument(self.db, '_design/ddoc001')
     index = 'function (doc) {\n  index("default", doc._id); '
     'if (doc._id) {index("name", doc.name, '
     '{"store": true}); }\n}'
     ddoc.add_search_index('search001', index)
     ddoc.add_search_index('search002', index)
     ddoc.add_search_index('search003', index)
     self.assertTrue(
         all(x in ddoc.list_indexes() for x in [
             'search001',
             'search002',
             'search003'
         ])
     )
开发者ID:drarvindsathi,项目名称:python-cloudant,代码行数:20,代码来源:design_document_tests.py

示例8: test_delete_a_search_index

# 需要导入模块: from cloudant.design_document import DesignDocument [as 别名]
# 或者: from cloudant.design_document.DesignDocument import add_search_index [as 别名]
 def test_delete_a_search_index(self):
     """
     Test deleting a search index from the DesignDocument dictionary.
     """
     ddoc = DesignDocument(self.db, '_design/ddoc001')
     ddoc.add_search_index(
         'search001',
         'function (doc) {\n  index("default", doc._id); '
         'if (doc._id) {index("name", doc.name, '
         '{"store": true}); }\n}'
     )
     self.assertEqual(
         ddoc.get('indexes')['search001'],
         {'index': 'function (doc) {\n  index("default", doc._id); '
             'if (doc._id) {index("name", doc.name, '
             '{"store": true}); }\n}'}
     )
     ddoc.delete_index('search001')
     self.assertEqual(ddoc.get('indexes'), {})
开发者ID:drarvindsathi,项目名称:python-cloudant,代码行数:21,代码来源:design_document_tests.py

示例9: test_fetch_search_index

# 需要导入模块: from cloudant.design_document import DesignDocument [as 别名]
# 或者: from cloudant.design_document.DesignDocument import add_search_index [as 别名]
 def test_fetch_search_index(self):
     """
     Ensure that the document fetch from the database returns the
     DesignDocument format as expected when retrieving a design document
     containing search indexes.
     """
     ddoc = DesignDocument(self.db, '_design/ddoc001')
     search_index = ('function (doc) {\n  index("default", doc._id); '
                     'if (doc._id) {index("name", doc.name, '
                     '{"store": true}); }\n} ')
     ddoc.add_search_index('search001', search_index)
     ddoc.add_search_index('search002', search_index, 'simple')
     ddoc.add_search_index('search003', search_index, 'standard')
     ddoc.save()
     ddoc_remote = DesignDocument(self.db, '_design/ddoc001')
     self.assertNotEqual(ddoc_remote, ddoc)
     ddoc_remote.fetch()
     self.assertEqual(ddoc_remote, ddoc)
     self.assertTrue(ddoc_remote['_rev'].startswith('1-'))
     self.assertEqual(ddoc_remote, {
         '_id': '_design/ddoc001',
         '_rev': ddoc['_rev'],
         'indexes': {
             'search001': {'index': search_index},
             'search002': {'index': search_index, 'analyzer': 'simple'},
             'search003': {'index': search_index, 'analyzer': 'standard'}
         },
         'views': {}
     })
开发者ID:drarvindsathi,项目名称:python-cloudant,代码行数:31,代码来源:design_document_tests.py

示例10: test_adding_existing_search_index

# 需要导入模块: from cloudant.design_document import DesignDocument [as 别名]
# 或者: from cloudant.design_document.DesignDocument import add_search_index [as 别名]
 def test_adding_existing_search_index(self):
     """
     Test that adding an existing search index fails as expected.
     """
     ddoc = DesignDocument(self.db, '_design/ddoc001')
     ddoc.add_search_index(
         'search001',
         'function (doc) {\n  index("default", doc._id); '
         'if (doc._id) {index("name", doc.name, {"store": true}); }\n}',
     )
     with self.assertRaises(CloudantArgumentError) as cm:
         ddoc.add_search_index(
             'search001',
             'function (doc) {\n  index("default", doc._id); '
             'if (doc._id) {index("name", doc.name, '
             '{"store": true}); }\n}'
         )
     err = cm.exception
     self.assertEqual(
         str(err),
         'An index with name search001 already exists in this design doc'
     )
开发者ID:drarvindsathi,项目名称:python-cloudant,代码行数:24,代码来源:design_document_tests.py

示例11: test_add_a_search_index_with_analyzer

# 需要导入模块: from cloudant.design_document import DesignDocument [as 别名]
# 或者: from cloudant.design_document.DesignDocument import add_search_index [as 别名]
 def test_add_a_search_index_with_analyzer(self):
     """
     Test that adding a search index with an analyzer adds a search index
     object to the DesignDocument dictionary.
     """
     ddoc = DesignDocument(self.db, '_design/ddoc001')
     self.assertEqual(ddoc.get('indexes'), {})
     ddoc.add_search_index(
         'search001',
         'function (doc) {\n  index("default", doc._id); '
         'if (doc._id) {index("name", doc.name, {"store": true}); }\n}',
         {'name': 'perfield', 'default': 'english', 'fields': {
             'spanish': 'spanish'}}
     )
     self.assertListEqual(list(ddoc.get('indexes').keys()), ['search001'])
     self.assertEqual(
         ddoc.get('indexes')['search001'],
         {'index': 'function (doc) {\n  index("default", doc._id); '
             'if (doc._id) {index("name", doc.name, {"store": true}); }\n}',
             'analyzer': {"name": "perfield", "default": "english", "fields":
                 {"spanish": "spanish"}}}
      )
开发者ID:drarvindsathi,项目名称:python-cloudant,代码行数:24,代码来源:design_document_tests.py


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