Problem while using NSPredicate

情到浓时终转凉″ 提交于 2019-12-12 01:24:26

问题


Sql query:

select * from test_mart where replace(replace(replace(replace(replace(replace(lower(name),'+'),'_'),'the '),' the'),'a '),' a')='tariq'

I can fire following query very easy, if I have to use simply Sqlite... but In current project I am using Core Data so not familiar about NSPredicate much.

The functionality talks about removing all BUT alphanumeric characters, which means removing special characters.

The characters that should be valid in the comparison would be

ABCDEFGHIJKLMNOPQRESTUVWXYZ1234567890

But we should not fail the comparison for the following characters

:;,~`!@#$%^&*()_-+="'/?.>,<|\

Or for the following words

'the' 'an' 'a'

Some examples:

  1. 'Walmart' would be seen as the same payee as 'Wal-Mart'

  2. 'The Shoe Store' would be seen as the same payee as 'Shoe Store'

  3. 'Domino's Pizza' would be seen as the same payee as 'Dominos Pizza'

  4. 'Test Payee;' would be seen as the same payee as 'Test Payee'

Can any one suggest appropriate Predicates/Regular Expression ?

Thanks


回答1:


I would have an extra field in the data base which would be a processed version of the original with all the irrelevant characters stripped out. Then use that for comparisons.

You might want to look at the soundex algorithm which may suite your purposes better... Soundex




回答2:


It seems to me that you would want to normalize your data before it every gets set into the core data store. So if you're given "Wal-Mart", normalize it to "walmart" once, and then save it. Then you won't be doing all of this expensive on-the-fly comparison many many times.

The normalization would be fairly simple, given your rules:

  • Strip the words "a", "an", and "the"
  • Remove punctuation


来源:https://stackoverflow.com/questions/4781379/problem-while-using-nspredicate

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!