简体   繁体   中英

How to make a more flexible search query using parse.com

I've got a database full of users and their information and I use parse.com to search through them.

Now, to make searching a bit better, and make it flexible with uppercase, accents and the like, I have a column called search_helper that gets filled when the user registers or updates his info, like this:

            String fullNameNormalized = Normalizer.normalize(inputFirstName.getText() + " " + inputFirstSurname.getText() + " " + inputSecondSurname.getText(), Normalizer.Form.NFD);
            fullNameNormalized = fullNameNormalized.replaceAll("[^\\p{ASCII}]", "");
            fullNameNormalized = fullNameNormalized.toLowerCase();



            String searchHelper = fullNameNormalized + " " + email + " " + phone;

So it's basically a longer string that contains all of the user's information in lowercase, so when I make a query, it looks like this:

            String searchParams = searchText.getText().toString().toLowerCase().trim();
            ParseQuery<ParseUser> newSearch = ParseUser.getQuery();
            newSearch.whereContains("search_helper", searchParams);

And that works, for the most part. For example, if i try to search for "john sanchez smith", it'll correctly return "John Sánchez Smith" as a search result. However, if I search for "john smith", it won't find him, because the column doesn't contain it in exactly that order. Does anyone know of a workaround for this?

Thanks for your time

It is not possible to search for "john smith", because contains means that just 1 part of a string can be searched, which has to be together. I'm sorry for that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM