add postgres's regex operator for more powerful searching?

Asked by Scott Meyer

This small patch adds the very powerful postgres regex operator to OpenObject searches:
___
openerp-server/osv/expression.py
-OPS = ('=', '!=', '<>', '<=', '<', '>', '>=', '=?', '=like', '=ilike', 'like', 'not like', 'ilike', 'not ilike', 'in', 'not in', 'child_of')
+OPS = ('=', '!=', '<>', '<=', '<', '>', '>=', '=?', '=like', '=ilike', 'like', 'not like', 'ilike', 'not ilike', 'in', 'not in', 'child_of', '~', '~*')
___

Adding the '~' and '~'" operators will give OpenERP access to Postgres's excellent regular expression engine for searches; much more power than 'like'. This tiny patch works for great for me, would love to see it in the trunk.
___

Optionally?...Perhaps 'not ~' and 'not ~*' should be added also?
But that may require many more lines are touched; especially all the occurrences of

                            if operator in ['not like','not ilike','not in','<>','!=']:

which by the way, would be more maintainable as one preamble copy of

not_operators=['not like','not ilike','not in','<>','!=','not ~','not ~*']

used by all the lines like this

                            if operator in not_operators:

Question information

Language:
English Edit question
Status:
Answered
For:
Odoo Server (MOVED TO GITHUB) Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
xrg (xrg) said :
#1

On Tuesday 21 December 2010, you wrote:
> New question #138636 on OpenObject Server:
> https://answers.launchpad.net/openobject-server/+question/138636
>
> This small patch adds the very powerful postgres regex operator to
> OpenObject searches:
> Adding the '~' and '~'" operators will give OpenERP access to Postgres's
> excellent regular expression engine for searches; much more power than
> 'like'. This tiny patch works for great for me, would love to see it in
> the trunk.

Interesting suggestion, but definitely for after v6.0.

One issue is that expressions are /not only/ used in Postgres. So, if we add
any new operator, we have to make sure it also works for orm_memory objects,
for the client etc.

Can you help with this problem?

Provide an answer of your own, or ask Scott Meyer for more information if necessary.

To post a message you must log in.