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


Python whoosh_backend.WhooshBackend类代码示例

本文整理汇总了Python中bhsearch.whoosh_backend.WhooshBackend的典型用法代码示例。如果您正苦于以下问题:Python WhooshBackend类的具体用法?Python WhooshBackend怎么用?Python WhooshBackend使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: ChangesetIndexerEventsTestCase

class ChangesetIndexerEventsTestCase(BaseBloodhoundSearchTest):
    def setUp(self):
        super(ChangesetIndexerEventsTestCase, self).setUp()
        self.whoosh_backend = WhooshBackend(self.env)
        self.whoosh_backend.recreate_index()
        self.search_api = BloodhoundSearchApi(self.env)
        self.repository_manager = RepositoryManager(self.env)
        self.inject_dummy_repository()

    def test_can_index_added_changeset(self):
        rev = self.insert_changeset("Changed document 1.")

        results = self.search_api.query("*:*")

        self.assertEqual(1, results.hits)
        doc = results.docs[0]
        self.assertEqual('%s/dummy' % rev, doc["id"])
        self.assertEqual('dummy', doc["repository"])
        self.assertEqual('1', doc["revision"])
        self.assertEqual("Changed document 1.", doc["message"])

    def test_can_index_modified_changeset(self):
        rev = self.insert_changeset("Changed document 1.")
        self.modify_changeset(rev, "Added document 1.")

        results = self.search_api.query("*:*")

        self.assertEqual(1, results.hits)
        doc = results.docs[0]
        self.assertEqual('%s/dummy' % rev, doc["id"])
        self.assertEqual('dummy', doc["repository"])
        self.assertEqual('1', doc["revision"])
        self.assertEqual("Added document 1.", doc["message"])

    def insert_changeset(self, message, author=None, date=None, revision=None):
        rev = self.repository.add_changeset(revision, message, author, date)
        self.repository_manager.notify("changeset_added", 'dummy', [rev])
        return rev

    def modify_changeset(self, rev, message=None, author=None, date=None):
        changeset = self.repository.get_changeset(rev)
        if message is not None:
            changeset.message = message
        if author is not None:
            changeset.author = author
        if date is not None:
            changeset.date = date
        self.repository_manager.notify("changeset_modified", "dummy", [rev])

    def inject_dummy_repository(self):
        # pylint: disable=protected-access,attribute-defined-outside-init
        self.repository = DummyRepositry()
        self.repository_connector = DummyRepositoryConnector(self.env)
        self.repository_connector.repository = self.repository
        self.repository_manager._all_repositories = {
            'dummy': dict(dir='dirname', type='dummy')}
        self.repository_manager._connectors = {
            'dummy': (self.repository_connector, 100)}
开发者ID:thimalk,项目名称:bloodhound,代码行数:58,代码来源:changeset_search.py

示例2: test_detects_that_index_needs_upgrade

    def test_detects_that_index_needs_upgrade(self):
        wrong_schema = Schema(content=TEXT())
        index.create_in(self.index_dir, schema=wrong_schema)

        whoosh_backend = WhooshBackend(self.env)
        self.assertEqual(whoosh_backend.is_index_outdated(), True)

        whoosh_backend.recreate_index()
        self.assertEqual(whoosh_backend.is_index_outdated(), False)
开发者ID:Stackato-Apps,项目名称:bloodhound,代码行数:9,代码来源:whoosh_backend.py

示例3: test_does_not_automatically_create_index

    def test_does_not_automatically_create_index(self):
        whoosh_backend = WhooshBackend(self.env)

        self.assertIs(whoosh_backend.index, None)
        self.assertEqual(whoosh_backend.is_index_outdated(), True)

        whoosh_backend.recreate_index()
        self.assertEqual(whoosh_backend.is_index_outdated(), False)
        self.assertIsNot(whoosh_backend.index, None)
开发者ID:Stackato-Apps,项目名称:bloodhound,代码行数:9,代码来源:whoosh_backend.py

示例4: QuerySuggestionTestCase

class QuerySuggestionTestCase(BaseBloodhoundSearchTest):
    def setUp(self):
        super(QuerySuggestionTestCase, self).setUp(create_req=True)
        self.whoosh_backend = WhooshBackend(self.env)
        self.whoosh_backend.recreate_index()

        self.search_api = BloodhoundSearchApi(self.env)

    def test_fills_suggestion_field(self):
        self.insert_ticket("test")
        self.insert_milestone("test")
        self.insert_wiki("name", "test")

        results = self.search_api.query("%s:test" % SuggestionFields.BASKET)

        self.assertEqual(results.hits, 3)

    def test_provides_suggestions(self):
        self.insert_ticket("test")
        self.req.args[RequestParameters.QUERY] = "tesk"

        data = self.process_request()

        self.assertIn(RequestContext.DATA_QUERY_SUGGESTION, data)
        suggestion = data[RequestContext.DATA_QUERY_SUGGESTION]
        self.assertEqual(suggestion['query'], 'test')
        self.assertIn('q=test', suggestion['href'])

    def test_provides_suggestions_for_multi_term_queries(self):
        self.insert_ticket("another test")
        self.req.args[RequestParameters.QUERY] = "another tesk"

        data = self.process_request()

        suggestion = data[RequestContext.DATA_QUERY_SUGGESTION]
        self.assertEqual(suggestion['query'], 'another test')

    def test_provides_suggestions_for_queries_with_unknown_words(self):
        self.insert_ticket("test")
        self.req.args[RequestParameters.QUERY] = "another tesk"

        data = self.process_request()

        suggestion = data[RequestContext.DATA_QUERY_SUGGESTION]
        self.assertEqual(suggestion['query'], 'another test')

    def test_suggestion_href_contains_used_filters(self):
        self.insert_ticket("test")
        self.req.args[RequestParameters.QUERY] = "tesk"
        self.req.args[RequestParameters.FILTER_QUERY] = ['filter']

        data = self.process_request()

        suggestion = data[RequestContext.DATA_QUERY_SUGGESTION]
        self.assertIn('fq=filter', suggestion['href'])
开发者ID:thimalk,项目名称:bloodhound-789,代码行数:55,代码来源:query_suggestion.py

示例5: RealIndexTestCase

class RealIndexTestCase(BaseBloodhoundSearchTest):
    """
    This test case is not supposed to be run from CI tool.
    The purpose of the class is to work with real Bloodhound Search Index and
    should be used for debugging purposes only
    """
    def setUp(self):
        self.env = EnvironmentStub(enable=['bhsearch.*'])
        current_current_dir = os.getcwd()

        real_env_path = os.path.join(
            current_current_dir,
            "../../../installer/bloodhound/environments/main")
        self.env.path = real_env_path
        self.whoosh_backend = WhooshBackend(self.env)

        self.req = Mock(
            perm=MockPerm(),
            chrome={'logo': {}},
            href=Href("/main"),
            args=arg_list_to_args([]),
        )

    def test_read_all(self):
        result = self.whoosh_backend.query(
            query.Every()
        )
        self.print_result(result)

        result = self.whoosh_backend.query(
            query.Every()
        )
        self.print_result(result)
        self.assertLessEqual(1, result.hits)

    def test_read_with_type_facet(self):
        result = self.whoosh_backend.query(
            query.Every()
        )
        self.print_result(result)

        result = self.whoosh_backend.query(
            query.Every(),
            facets=["type"]
        )
        self.print_result(result)
        self.assertLessEqual(1, result.hits)

    def test_read_from_search_module(self):
        self.req.args[RequestParameters.QUERY] = "*"
        self.process_request()
开发者ID:thimalk,项目名称:bloodhound,代码行数:51,代码来源:real_index_view.py

示例6: setUp

    def setUp(self):
        super(WebUiTestCaseWithWhoosh, self).setUp(
            create_req=True,
        )
        self.req.redirect = self.redirect

        whoosh_backend = WhooshBackend(self.env)
        whoosh_backend.recreate_index()

        self.req.redirect = self.redirect
        self.redirect_url = None
        self.redirect_permanent = None

        self.old_product_environment = web_ui.ProductEnvironment
        self._inject_mocked_product_environment()
开发者ID:thimalk,项目名称:bloodhound,代码行数:15,代码来源:web_ui.py

示例7: setUp

 def setUp(self):
     super(TicketIndexerTestCase, self).setUp()
     self.whoosh_backend = WhooshBackend(self.env)
     self.whoosh_backend.recreate_index()
     self.ticket_indexer = TicketIndexer(self.env)
     self.search_api = BloodhoundSearchApi(self.env)
     self.env.config.set('bhsearch', 'silence_on_error', "False")
开发者ID:Stackato-Apps,项目名称:bloodhound,代码行数:7,代码来源:ticket_search.py

示例8: setUp

 def setUp(self):
     super(ChangesetIndexerEventsTestCase, self).setUp()
     self.whoosh_backend = WhooshBackend(self.env)
     self.whoosh_backend.recreate_index()
     self.search_api = BloodhoundSearchApi(self.env)
     self.repository_manager = RepositoryManager(self.env)
     self.inject_dummy_repository()
开发者ID:thimalk,项目名称:bloodhound,代码行数:7,代码来源:changeset_search.py

示例9: setUp

 def setUp(self):
     super(WikiIndexerEventsTestCase, self).setUp()
     self.wiki_system = WikiSystem(self.env)
     self.whoosh_backend = WhooshBackend(self.env)
     self.whoosh_backend.recreate_index()
     self.search_api = BloodhoundSearchApi(self.env)
     self.wiki_participant = WikiSearchParticipant(self.env)
     self.query_parser = DefaultQueryParser(self.env)
开发者ID:mohsadki,项目名称:dargest,代码行数:8,代码来源:wiki_search.py

示例10: WhooshEmptyFacetErrorWorkaroundTestCase

class WhooshEmptyFacetErrorWorkaroundTestCase(BaseBloodhoundSearchTest):
    def setUp(self):
        super(WhooshEmptyFacetErrorWorkaroundTestCase, self).setUp()
        self.whoosh_backend = WhooshBackend(self.env)
        self.whoosh_backend.recreate_index()
        self.parser = DefaultQueryParser(self.env)
        self.empty_facet_workaround = WhooshEmptyFacetErrorWorkaround(self.env)

    def tearDown(self):
        shutil.rmtree(self.env.path)
        self.env.reset_db()

    def test_set_should_not_be_empty_fields(self):
        self.insert_ticket("test x")
        result = self.whoosh_backend.query(query.Every())
        self.print_result(result)
        doc = result.docs[0]
        null_marker = WhooshEmptyFacetErrorWorkaround.NULL_MARKER
        self.assertEqual(null_marker, doc["component"])
        self.assertEqual(null_marker, doc["status"])
        self.assertEqual(null_marker, doc["milestone"])

    def test_can_fix_query_filter(self):
        parsed_filter = self.parser.parse_filters(
            ["type:ticket", "NOT (milestone:*)"])
        query_parameters = dict(filter=parsed_filter)
        self.empty_facet_workaround.query_pre_process(
            query_parameters)

        result_filter = query_parameters["filter"]
        self.assertEquals('(type:ticket AND milestone:empty)',
            str(result_filter))

    def test_does_interfere_query_filter_if_not_needed(self):
        parsed_filter = self.parser.parse_filters(
            ["type:ticket", "milestone:aaa"])
        query_parameters = dict(filter=parsed_filter)
        self.empty_facet_workaround.query_pre_process(
            query_parameters)

        result_filter = query_parameters["filter"]
        self.assertEquals('(type:ticket AND milestone:aaa)',
            str(result_filter))
开发者ID:Stackato-Apps,项目名称:bloodhound,代码行数:43,代码来源:whoosh_backend.py

示例11: setUp

    def setUp(self):
        super(WebUiTestCaseWithWhoosh, self).setUp(
            create_req=True,
        )
        self.req.redirect = self.redirect

        whoosh_backend = WhooshBackend(self.env)
        whoosh_backend.recreate_index()

        self.req = Mock(
            perm=MockPerm(),
            chrome={'logo': {}},
            href=Href("/main"),
            base_path=BASE_PATH,
            args=arg_list_to_args([]),
            redirect=self.redirect
        )

        self.redirect_url = None
        self.redirect_permanent = None
开发者ID:domaemon,项目名称:bloodhound-qa,代码行数:20,代码来源:web_ui.py

示例12: setUp

    def setUp(self):
        self.env = EnvironmentStub(enable=['bhsearch.*'])
        current_current_dir = os.getcwd()

        real_env_path = os.path.join(
            current_current_dir,
            "../../../installer/bloodhound/environments/main")
        self.env.path = real_env_path
        self.whoosh_backend = WhooshBackend(self.env)

        self.req = Mock(
            perm=MockPerm(),
            chrome={'logo': {}},
            href=Href("/main"),
            args=arg_list_to_args([]),
        )
开发者ID:thimalk,项目名称:bloodhound,代码行数:16,代码来源:real_index_view.py

示例13: setUp

 def setUp(self):
     super(MilestoneIndexerEventsTestCase, self).setUp()
     self.whoosh_backend = WhooshBackend(self.env)
     self.whoosh_backend.recreate_index()
     self.search_api = BloodhoundSearchApi(self.env)
开发者ID:Stackato-Apps,项目名称:bloodhound,代码行数:5,代码来源:milestone_search.py

示例14: MilestoneIndexerEventsTestCase

class MilestoneIndexerEventsTestCase(BaseBloodhoundSearchTest):
    DUMMY_MILESTONE_NAME = "dummyName"

    def setUp(self):
        super(MilestoneIndexerEventsTestCase, self).setUp()
        self.whoosh_backend = WhooshBackend(self.env)
        self.whoosh_backend.recreate_index()
        self.search_api = BloodhoundSearchApi(self.env)

    def test_can_index_created_milestone(self):
        #arrange
        self.insert_milestone(self.DUMMY_MILESTONE_NAME, "dummy text")
        #act
        results = self.search_api.query("*:*")
        #assert
        self.print_result(results)
        self.assertEqual(1, results.hits)
        doc = results.docs[0]
        self.assertEqual(self.DUMMY_MILESTONE_NAME, doc["id"])
        self.assertEqual("dummy text", doc["content"])
        self.assertEqual("milestone", doc["type"])
        self.assertNotIn("due", doc )

    def test_can_index_minimal_milestone(self):
        #arrange
        self.insert_milestone(self.DUMMY_MILESTONE_NAME)
        #act
        results = self.search_api.query("*:*")
        #assert
        self.print_result(results)
        self.assertEqual(1, results.hits)
        doc = results.docs[0]
        self.assertEqual(self.DUMMY_MILESTONE_NAME, doc["id"])
        self.assertNotIn("content", doc)


    def test_can_index_renamed_milestone(self):
        #arrange
        self.insert_milestone(self.DUMMY_MILESTONE_NAME, "dummy text")
        self.change_milestone(
            self.DUMMY_MILESTONE_NAME,
            name="updated name",
            description="updated description",
        )
        #act
        results = self.search_api.query("*:*")
        #assert
        self.print_result(results)
        self.assertEqual(1, results.hits)
        doc = results.docs[0]
        self.assertEqual("updated name", doc["id"])
        self.assertEqual("updated description", doc["content"])

    def test_can_index_changed_milestone(self):
        #arrange
        self.insert_milestone(self.DUMMY_MILESTONE_NAME, "dummy text")
        self.change_milestone(
            self.DUMMY_MILESTONE_NAME,
            description="updated description",
        )
        #act
        results = self.search_api.query("*:*")
        #assert
        self.print_result(results)
        self.assertEqual(1, results.hits)
        doc = results.docs[0]
        self.assertEqual(self.DUMMY_MILESTONE_NAME, doc["id"])
        self.assertEqual("updated description", doc["content"])

    def test_can_index_delete(self):
        #arrange
        self.insert_milestone(self.DUMMY_MILESTONE_NAME)
        results = self.search_api.query("*")
        self.assertEqual(1, results.hits)
        #act
        Milestone(self.env, self.DUMMY_MILESTONE_NAME).delete()
        #assert
        results = self.search_api.query("*")
        self.print_result(results)
        self.assertEqual(0, results.hits)

    def test_can_reindex_minimal_milestone(self):
        #arrange
        self.insert_milestone(self.DUMMY_MILESTONE_NAME)
        self.whoosh_backend.recreate_index()
        #act
        self.search_api.rebuild_index()
        #assert
        results = self.search_api.query("*:*")
        self.print_result(results)
        self.assertEqual(1, results.hits)
        doc = results.docs[0]
        self.assertEqual(self.DUMMY_MILESTONE_NAME, doc["id"])
        self.assertEqual("milestone", doc["type"])

    def test_that_tickets_updated_after_milestone_renaming(self):
        #asser
        INITIAL_MILESTONE = "initial_milestone"
        RENAMED_MILESTONE = "renamed_name"
        milestone = self.insert_milestone(INITIAL_MILESTONE)
#.........这里部分代码省略.........
开发者ID:Stackato-Apps,项目名称:bloodhound,代码行数:101,代码来源:milestone_search.py

示例15: setUp

    def setUp(self):
        super(QuerySuggestionTestCase, self).setUp(create_req=True)
        self.whoosh_backend = WhooshBackend(self.env)
        self.whoosh_backend.recreate_index()

        self.search_api = BloodhoundSearchApi(self.env)
开发者ID:thimalk,项目名称:bloodhound-789,代码行数:6,代码来源:query_suggestion.py


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