示例#1
0
    def test_partial_mappings_french_diacritics(self):
        """
        Make sure words ending in "icité" are analyzed the same way whether or not there
        is an accent.
        """
        index_name = "stub_index"
        mapping = {"dynamic_templates": MULTILINGUAL_TEXT}

        # Create the index and set a mapping that includes the pattern we want to test
        ES_INDICES_CLIENT.create(index=index_name)
        ES_INDICES_CLIENT.put_mapping(index=index_name, body=mapping)
        # The index needs to be closed before we set an analyzer
        ES_INDICES_CLIENT.close(index=index_name)
        ES_INDICES_CLIENT.put_settings(body=ANALYSIS_SETTINGS,
                                       index=index_name)
        ES_INDICES_CLIENT.open(index=index_name)

        self.assertEqual(
            ES_INDICES_CLIENT.analyze(
                body='{"analyzer": "french", "text": "électricité"}',
                index=index_name)["tokens"][0]["token"],
            "electricit",
        )
        self.assertEqual(
            ES_INDICES_CLIENT.analyze(
                body='{"analyzer": "french", "text": "electricite"}',
                index=index_name)["tokens"][0]["token"],
            "electricit",
        )
示例#2
0
    def test_partial_mappings_code(self):
        """Make sure our code analyzer works as expected."""
        index_name = "stub_index"

        # Create the index and set a mapping that includes the pattern we want to test
        ES_INDICES_CLIENT.create(index=index_name)
        # The index needs to be closed before we set an analyzer
        ES_INDICES_CLIENT.close(index=index_name)
        ES_INDICES_CLIENT.put_settings(body=ANALYSIS_SETTINGS,
                                       index=index_name)
        ES_INDICES_CLIENT.open(index=index_name)

        self.assertEqual(
            [
                t["token"] for t in ES_INDICES_CLIENT.analyze(
                    body='{"analyzer": "code_trigram", "text": "003rst"}',
                    index=index_name,
                )["tokens"]
            ],
            [
                "003",
                "003r",
                "003rs",
                "003rst",
                "03r",
                "03rs",
                "03rst",
                "3rs",
                "3rst",
                "rst",
            ],
        )

        self.assertEqual(
            [
                t["token"] for t in ES_INDICES_CLIENT.analyze(
                    body='{"analyzer": "code", "text": "003rst"}',
                    index=index_name)["tokens"]
            ],
            ["003rst"],
        )