<commit_before># -*- coding: utf-8 -*-
# © 2016 <NAME>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from openerp.tests.common import TransactionCase, at_install, post_install


@at_install(False)
@post_install(True)
class NameSearchCase(TransactionCase):

    def setUp(self):
        super(NameSearchCase, self).setUp()
        phone_field = self.env.ref('base.field_res_partner_phone')
        model_partner = self.env.ref('base.model_res_partner')
        model_partner.name_search_ids = phone_field
        self.Partner = self.env['res.partner']
        self.partner1 = self.Partner.create(
            {'name': '<NAME>',
             'phone': '+351 555 777 333'})
        self.partner2 = self.Partner.create(
            {'name': '<NAME>',
             'phone': '+351 555 333 777'})
        self.partner3 = self.Partner.create(
            {'name': '<NAME> Ulm',
             'phone': '+351 777 333 555'})

    def test_RelevanceOrderedResults(self):
        """Return results ordered by relevance"""
        res = self.Partner.name_search('555 777')
        self.assertEqual(
            res[0][0], self.partner1.id,
            'Match full string honoring spaces')
        self.assertEqual(
            res[1][0], self.partner2.id,
            'Match words honoring order of appearance')
        self.assertEqual(
            res[2][0], self.partner3.id,
            'Match all words, regardless of order of appearance')

    def test_NameSearchMustMatchAllWords(self):
        """Must Match All Words"""
        res = self.Partner.name_search('ulm 555 777')
        self.assertFalse(res)<commit_msg>Test if additional domain is honored<commit_after># -*- coding: utf-8 -*-
# © 2016 <NAME>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from openerp.tests.common import TransactionCase, at_install, post_install


@at_install(False)
@post_install(True)
class NameSearchCase(TransactionCase):

    def setUp(self):
        super(NameSearchCase, self).setUp()
        phone_field = self.env.ref('base.field_res_partner_phone')
        model_partner = self.env.ref('base.model_res_partner')
        model_partner.name_search_ids = phone_field
        self.Partner = self.env['res.partner']
        self.partner1 = self.Partner.create(
            {'name': '<NAME>',
             'customer': True,
             'phone': '+351 555 777 333'})
        self.partner2 = self.Partner.create(
            {'name': '<NAME>',
             'customer': True,
             'phone': '+351 555 333 777'})
        self.partner3 = self.Partner.create(
            {'name': '<NAME> Ulm',
             'supplier': True,
             'phone': '+351 777 333 555'})

    def test_RelevanceOrderedResults(self):
        """Return results ordered by relevance"""
        res = self.Partner.name_search('555 777')
        self.assertEqual(
            res[0][0], self.partner1.id,
            'Match full string honoring spaces')
        self.assertEqual(
            res[1][0], self.partner2.id,
            'Match words honoring order of appearance')
        self.assertEqual(
            res[2][0], self.partner3.id,
            'Match all words, regardless of order of appearance')

    def test_NameSearchMustMatchAllWords(self):
        """Must Match All Words"""
        res = self.Partner.name_search('ulm 555 777')
        self.assertFalse(res)

    def test_MustHonorDomain(self):
        """Must also honor a provided Domain"""
        res = self.Partner.name_search('+351', args=[('supplier', '=', True)])
        gambulputty = self.partner3.id
        self.assertEqual(len(res), 1)
        self.assertEqual(res[0][0], gambulputty)
{'fraction_non_alphanumeric': 0.13524590163934427, 'fraction_numerical': 0.038524590163934426, 'mean_word_length': 2.47673314339981, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6641275', 'n_tokens_mistral': 1224, 'n_tokens_neox': 1098, 'n_words': 248}