PostgreSQL String search for partial patterns, removing extra characters

Looking for a simple SQL regular expression (PostgreSQL) or a similar solution (possibly soundex) that allows you to use flexible search. So during the search hyphens, spaces, etc. Omitted. As part of the search, and only raw characters are searched in the table .:

Currently used:

SELECT * FROM Productions WHERE part_no ~* '%search_term%'

If a user creates UTR-1, he cannot call UTR1 or UTR 1 stored in the database.

But no match occurs when part_no has a dash and the user omits that character (or vice versa)

EXAMPLE a search for a part of UTR-1 should find all matches below.

UTR1 
UTR --1 
UTR  1

any suggestions...

+3
source share
2
SELECT  *
FROM    Productions
WHERE   REGEXP_REPLACE(part_no, '[^[:alnum:]]', '') 
      = REGEXP_REPLACE('UTR-1', '[^[:alnum:]]', '')

REGEXP_REPLACE(part_no, '[^[:alnum:]]', ''), .

+2

, ( 8.3 ) postrgesql, :

http://www.postgresql.org/docs/8.3/static/textsearch.html

:

It is possible for the parser to produce overlapping tokens from the 
same of text. 

As an example, a hyphenated word will be reported both as the entire word 
and as each component: 

SELECT alias, description, token FROM ts_debug('foo-bar-beta1');

      alias      |               description                |     token     
-----------------+------------------------------------------+---------------
 numhword        | Hyphenated word, letters and digits      | foo-bar-beta1
 hword_asciipart | Hyphenated word part, all ASCII          | foo
 blank           | Space symbols                            | -
 hword_asciipart | Hyphenated word part, all ASCII          | bar
 blank           | Space symbols                            | -
 hword_numpart   | Hyphenated word part, letters and digits | beta1
+2

Source: https://habr.com/ru/post/1738388/


All Articles