Print Page | Close Window

Accent insensitive search in cache

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2012
Forum Discription: For .NET 4.5
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=4614
Printed Date: 29-Apr-2025 at 12:29pm


Topic: Accent insensitive search in cache
Posted By: cefernan
Subject: Accent insensitive search in cache
Date 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.




Replies:
Posted By: kimj
Date 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 - 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.


Posted By: cefernan
Date 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.



Print Page | Close Window