0

Hi I'm trying to make a movie app where I'm trying to make a search functionality work. However I'm running into a problem trying to figure out a way to make the search case insensitive as well as ignore the punctuations. I believe another post showed how to get the case insensitive to work by using regular expression

query.whereMatches("name", "("+searchData+")", "i"); 

However is there something I can do to ignore the punctuations?

For example in the database I have "Mission: Impossible". If a user searches for "Mission impossible" it still won't be able to find it.

Reinhard Männer
  • 14,022
  • 5
  • 54
  • 116
Zack
  • 881
  • 1
  • 9
  • 13
  • 1
    I believe it is not possible to ignore certain characters during a Parse search. You had to store the text without punctuations in Parse. – Reinhard Männer Jan 09 '16 at 19:44

1 Answers1

0

A good way to search on an attribute slightly transformed is to do the transformation upon save, then use the simpler (faster) match on query against the transformed attribute. For this question, the transformation is to a case-insensitive, punctuation-free version of an attribute.

Parse.Cloud.beforeSave("MyClass", function(request, response) {
    var name = request.object.get("name");
    var searchName = name.replace(/['";:,.\/?\\-]/g, '').toLowerCase();
    request.object.set("searchName", searchName);
    response.success();
});

Now, a case-insensitive, punctuation-free search can be done with maximum simplicity and speed (since it's indexed) on the "searchName" attribute.

danh
  • 62,181
  • 10
  • 95
  • 136