← Back to team overview

openerp-india team mailing list archive

[Bug 1049653] Re: --unaccent option does not work

 

I think that the problem is when searching in Products, because it uses
a subquery here. The subqueries are not parsed correctly to use
unaccent(). I made a few changes in the 'expression.py' files and now it
is working. I include the new 'expression.py' file that makes things
work correctly.

In the file 'openerp/osv/expression.py' In line 639, the lines:

else:
    subselect += '     AND value ' + sql_operator + instr +   \
         ') UNION ('                \
         '  SELECT id'              \
         '    FROM "' + working_table._table + '"'       \
         '   WHERE "' + left + '" ' + sql_operator + instr + ")"

should be replaced by the lines:

else:
    if sql_operator in ['like','ilike'] and self.has_unaccent:
        subselect += '     AND value ' + sql_operator + instr +   \
             ') UNION ('                \
             '  SELECT id'              \
             '    FROM "' + working_table._table + '"'       \
             '   WHERE unaccent("' + left + '") ' + sql_operator + ' unaccent(' + instr + "))"
    else:
        subselect += '     AND value ' + sql_operator + instr +   \
             ') UNION ('                \
             '  SELECT id'              \
             '    FROM "' + working_table._table + '"'       \
             '   WHERE "' + left + '" ' + sql_operator + instr + ")"

With this modifications, if searching in products, the unaccent()
function is used.

Also I think (but not quite sure about it) that in line 625 the lines:

subselect = '( SELECT res_id'          \
         '    FROM ir_translation'  \
         '   WHERE name = %s'       \
         '     AND lang = %s'       \
         '     AND type = %s'

should be changed with something like this:

if self.has_unaccent:
    subselect = '( SELECT res_id'          \
             '    FROM ir_translation'  \
             '   WHERE unaccent(name) = unaccent(%s)'       \
             '     AND lang = %s'       \
             '     AND type = %s'
else:
    subselect = '( SELECT res_id'          \
             '    FROM ir_translation'  \
             '   WHERE name = %s'       \
             '     AND lang = %s'       \
             '     AND type = %s'

** Attachment added: "expression.py"
   https://bugs.launchpad.net/openobject-server/+bug/1049653/+attachment/3312601/+files/expression.py

-- 
You received this bug notification because you are a member of OpenERP
Indian Team, which is subscribed to OpenERP Server.
https://bugs.launchpad.net/bugs/1049653

Title:
  --unaccent option does not work

Status in OpenERP Server:
  New

Bug description:
  I have OpenERP v6.1 in Ubuntu 12.04 with PostgreSQL. I updated the
  nightly builds, version: OpenERP Server 6.1-20120910-233309.

  I create a new OpenERP database called X.

  I installed postgresql-contrib for using unaccent in PostgreSQL and
  connect to the database X with psql. I execute "create extension
  unaccent;" to have access to unaccent in the database X.

  I start the OpenERP server with the '--unaccent' option.

  After all this, if I search over product name, I do not receive the
  expected result. For example, if I have products 'aeío' and 'aeio' and
  I search with string 'aeí' I receive only the first product and not
  the second.

  I check the log (using option --log-sql in the server) and I don't see
  any usage of unaccent function in the querys.

To manage notifications about this bug go to:
https://bugs.launchpad.net/openobject-server/+bug/1049653/+subscriptions


References