开发者

Problem while using NSPredicate

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 remov开发者_StackOverflow中文版ing 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


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


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜