寻找一个允许灵活搜索的简单 SQL (PostgreSQL) 正则表达式或类似解决方案(可能是 soundex)。因此在搜索过程中省略了破折号、空格等。作为搜索的一部分,只在表中搜索原始字符。:
目前正在使用:
SELECT * FROM Productions WHERE part_no ~* '%search_term%'
如果用户键入 UTR-1,它无法调出存储在数据库中的 UTR1 或 UTR 1。
但是当 part_no 有破折号并且用户省略了这个字符(反之亦然)时,匹配不会发生
EXAMPLE 搜索部分 UTR-1 应该会找到下面的所有匹配项。
UTR1
UTR --1
UTR 1
任何建议...
最佳答案
您可能会发现 postrgesql 中的官方内置(至少从 8.3 开始)全文搜索功能值得一看:
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
关于sql - PostgreSQL 字符串搜索部分模式删除无关字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2510732/