コード例 #1
0
    def get(self, term):
        """
        Returns list of matching concepts or entities using lexical search
        """

        input_args = layperson_parser.parse_args()
        # params that don't directly translate to solr controller
        filtered_params = [
            'phenotype_group', 'phenotype_group_label', 'anatomical_system',
            'anatomical_system_label'
        ]
        args = {
            k: v
            for k, v in input_args.items() if k not in filtered_params
        }

        args['fq'] = {}
        if input_args['phenotype_group'] is not None:
            args['fq']['phenotype_closure'] = input_args['phenotype_group']
        if input_args['phenotype_group_label'] is not None:
            args['fq']['phenotype_closure_label'] = input_args[
                'phenotype_group_label']
        if input_args['anatomical_system'] is not None:
            args['fq']['anatomy_closure'] = input_args['anatomical_system']
        if input_args['anatomical_system_label'] is not None:
            args['fq']['anatomy_closure_label'] = input_args[
                'anatomical_system_label']

        q = GolrLayPersonSearch(term, user_agent=USER_AGENT, **args)
        results = q.autocomplete()
        return results
コード例 #2
0
    def setup_class(self):
        self.manager = GolrLayPersonSearch()

        # Mock the PySolr search function to
        # return our test docs
        input_fh = os.path.join(os.path.dirname(__file__),
                                'resources/solr/layperson-docs.json')
        input_docs = json.load(open(input_fh))
        self.test_results = pysolr.Results(input_docs)
        self.manager.solr.search = MagicMock(return_value=self.test_results)
コード例 #3
0
class TestGolrSearchParams():

    @classmethod
    def setup_class(self):
        self.manager = GolrLayPersonSearch()

    @classmethod
    def teardown_class(self):
        self.manager = None

    def test_prefix_filters(self):
        """
        Test that prefix filters are converted
        properly to solr params
        """
        prefix_filter = [
            '-OMIA',
            '-Orphanet',
            'DO',
            'OMIM',
            'MONDO'
        ]
        expected = [
            '-prefix:"OMIA"',
            '-prefix:"Orphanet"',
            'prefix:"DO" OR prefix:"OMIM" OR prefix:"MONDO"'
        ]
        self.manager.prefix = prefix_filter
        params = self.manager.solr_params()
        assert params['fq'] == expected
コード例 #4
0
class TestGolrLayPersonSearch():
    @classmethod
    def setup_class(self):
        self.manager = GolrLayPersonSearch()

        # Mock the PySolr search function to
        # return our test docs
        input_fh = os.path.join(os.path.dirname(__file__),
                                'resources/solr/input/layperson-docs.json')
        input_docs = json.load(open(input_fh))
        self.pysolr_results = pysolr.Results(input_docs)
        self.manager.solr.search = MagicMock(return_value=self.pysolr_results)

    @classmethod
    def teardown_class(self):
        self.manager = None

    def test_lay_doc_conversion(self):
        """
        Given a sample solr output as a pysolr.Results object
        test that _process_layperson_results returns the
        expected object
        """
        expected_fh = os.path.join(os.path.dirname(__file__),
                                   'resources/solr/expected/layperson.json')
        processed_docs = json.load(open(expected_fh))
        output_docs = self.manager._process_layperson_results(
            self.pysolr_results)

        assert json.dumps(processed_docs,
                          sort_keys=True) == json.dumps(output_docs,
                                                        sort_keys=True)

    def test_autocomplete(self):
        """
        Given a mock PySolr.search method test that
        autocomplete() returns the expected object
        """
        expected_fh = os.path.join(os.path.dirname(__file__),
                                   'resources/solr/expected/layperson.json')
        processed_docs = json.load(open(expected_fh))
        output_docs = self.manager.autocomplete()

        assert json.dumps(processed_docs,
                          sort_keys=True) == json.dumps(output_docs,
                                                        sort_keys=True)
コード例 #5
0
class TestGolrSearchParams():
    @classmethod
    def setup_class(self):
        self.manager = GolrLayPersonSearch()

    @classmethod
    def teardown_class(self):
        self.manager = None

    def test_prefix_filters(self):
        """
        Test that prefix filters are converted
        properly to solr params
        """
        prefix_filter = ['-OMIA', '-Orphanet', 'DO', 'OMIM', 'MONDO']
        expected = [
            '-prefix:("OMIA" OR "Orphanet")',
            'prefix:("DO" OR "OMIM" OR "MONDO")'
        ]
        self.manager.prefix = prefix_filter
        params = self.manager.solr_params()
        assert params['fq'] == expected

    def test_prefix_filters_include_eq(self):
        """
        Test that prefix filters are converted
        properly to solr params
        """
        prefix_filter = ['-OMIA', '-Orphanet', 'DO', 'OMIM', 'MONDO']
        expected = [
            '(-prefix:"OMIA" OR -equivalent_curie:OMIA\:*)',
            '(-prefix:"Orphanet" OR -equivalent_curie:Orphanet\:*)',
            '((prefix:"DO" OR equivalent_curie:DO\:*) OR (prefix:"OMIM" OR '
            'equivalent_curie:OMIM\:*) OR (prefix:"MONDO" OR equivalent_curie:MONDO\:*))'
        ]
        self.manager.prefix = prefix_filter
        self.manager.include_eqs = True
        params = self.manager.solr_params()
        assert params['fq'] == expected
コード例 #6
0
 def setup_class(self):
     self.manager = GolrLayPersonSearch()