Friday, June 1, 2012

Re: How to perform a simple search ignoring characters with accents (á, é, í, ó, ú)

Maybe you could just build a simple index? It'd basically be a set of keywords, each with a set of matching books.
So in your example, you'd have two keywords:

hola (with accent) -> book1, book2, etc..
hola (without accent) -> (same as previous)

And then just write some sort of functionality to run through your data and index it to a table. I can't vouch that this is the best approach - but I think it'd at least solve the problem.

On Fri, Jun 1, 2012 at 1:03 PM, Joni Bekenstein <jonibekenstein@gmail.com> wrote:
I need to do a simple search ignoring some characters with accents. The idea would be that "hola" matches the search term "holá".

What I'm currently doing is adding a CharField to my model to store the searchable term. For example:

class Book(models.Model):
  title = models.CharField(max_length=100)
  searchable_title = models.CharField(max_length=100)

When I save a Book I'll replace the accented characters in title with their non-accented counterparts and store the result in searchable_title. The, I'll also do the same thing with the search term before actually doing the query.

I don't like this approach because if I need to add more searchable fields things start getting noisy in my models.

Any ideas?

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/tdIUkptWpZgJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment