New Posts New Posts RSS Feed: Accent insensitive search in cache
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Accent insensitive search in cache

 Post Reply Post Reply
Author
cefernan View Drop Down
Groupie
Groupie


Joined: 13-Jul-2012
Posts: 70
Post Options Post Options   Quote cefernan Quote  Post ReplyReply Direct Link To This Post Topic: Accent insensitive search in cache
    Posted: 27-Nov-2013 at 11:47am
Hi,

I'm trying to created a accent insensitive search in my app. 

For instance, I have this rows:

Name
-------
Ricardo Ribeiro
Luis Aragão
André Silva
João Souza
Paolo Guerreiro

If I do this:
  var query = UnitOfWork.EntityManager.People
          .Where(person => person.Name.Contains("ao"));
 
  var result = query.Execute();

I expect this result:
Luis Aragão
João Souza
Paolo Guerreiro

But, my collection result is just "Paolo Guerreiro", because just this ocurrence contains "ao" without accent. 

My database is configured to do accent insensitive searches and I can check that executing the generated query direct in database. Also, if I check my entity manager cache, I can see only these three rows loaded in my entity. Just my collection doesn't receive the expected result.

Back to Top
kimj View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 1391
Post Options Post Options   Quote kimj Quote  Post ReplyReply Direct Link To This Post Posted: 27-Nov-2013 at 3:02pm
DevForce does support some customization of cache queries using the CacheQueryOptions on the QueryStrategy, but unfortunately this won't help here. 
 
One option is to break this into two separate queries, one to execute against the database only, and another to execute against cache only.  The cache only query can then call a local function to remove the accent prior to the string compare.  See the RemoveDiacritics method in this StackOverflow post - http://stackoverflow.com/questions/359827/ignoring-accented-letters-in-string-comparison - for more information.  The local query might then look like:
 
  EntityManager.People.Where(person => RemoveDiacritics(person.Name).Contains("ao"))
 
Not ideal, but maybe other DevForce developers have encountered this problem and have some suggestions.
Back to Top
cefernan View Drop Down
Groupie
Groupie


Joined: 13-Jul-2012
Posts: 70
Post Options Post Options   Quote cefernan Quote  Post ReplyReply Direct Link To This Post Posted: 28-Nov-2013 at 4:09am
Actually, I demonstrated a simple example, but my real scenario is little different.

I use a PagedCollectionViewAdapter for IPager<T> - Cocktail. So, I don't control the query execution itself. I just pass my IPagerRepository, a predicate and then call GoToPageAsync to load data.

Maybe, I can execute first a query against database and after put my strategy to cache only in IPagerRepository.


Edited by cefernan - 28-Nov-2013 at 4:37am
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down