简体   繁体   English

如何使用parse.com进行更灵活的搜索查询

[英]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. 我有一个充满用户和他们的信息的数据库,我使用parse.com来搜索他们。

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: 现在,为了使搜索更好一点,并使其灵活使用大写字母,重音符号等,我有一个名为search_helper的列,该列在用户注册或更新其信息时被填充,如下所示:

            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. 无法搜索“ john smith”,因为contains表示只能搜索字符串的一部分,该部分必须在一起。 I'm sorry for that. 对此我感到抱歉。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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