如何在Quickblox阵列中搜索

时间:2015-07-27 14:47:22

标签: quickblox

我正在使用http://quickblox.com/developers/SimpleSample-customObjects-android#Search_operators在“数组”数据类型中查找关键字。

但它只搜索数组中的第一个字符串。如何在数组中的所有字符串中搜索?

public static void getNews(final Context context, final Handler handler, final int page) {
    ArrayList<String> catSearch = new ArrayList<>();
    ArrayList<NewsCategory> categories = Cache.getNewsCategories(context);
    for(NewsCategory category : categories) {
        if(Cache.isCategoryChecked(context, category.getId())) {
            catSearch.add(category.getId());
        }
    }

    ArrayList<String> tagSearch = new ArrayList<>();
    ArrayList<NewsTag> tags = Cache.getNewsTags(context, Cache.SELECTED_TAGS);
    for(NewsTag tag : tags) {
        tagSearch.add(tag.getTitle());
    }

    QBRequestGetBuilder builder = new QBRequestGetBuilder();
    if(tagSearch.size() == 0) {
        builder.ctn("LangId", Cache.getNewsLanguage(context)).
                in("CategoryId", catSearch.toArray());
    } else {
        builder.ctn("LangId", Cache.getNewsLanguage(context)).in("Tags", tagSearch.toArray()).
                in("CategoryId", catSearch.toArray());
    }

    QBCustomObjects.getObjects("News", builder,
            new QBEntityCallbackImpl<ArrayList<QBCustomObject>>() {
                @Override
                public void onSuccess(ArrayList<QBCustomObject> customObjects, Bundle params) {
                    ArrayList<String> images = new ArrayList<>();
                    ArrayList<News> newsArray = new ArrayList<>();
                    for (QBCustomObject object : customObjects) {
                        try {
                            HashMap<String, Object> pairs = object.getFields();
                            String id = object.getCustomObjectId();
                            long created = object.getCreatedAt().getTime();
                            News news = new News(pairs, id, created);
                            newsArray.add(news);
                            Log.e("", "Tags: " + pairs.get("Tags"));

                            if (!news.getPhoto().equals("")) {
                                images.add(news.getPhoto());
                            }
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }

                    Cache.saveNews(context, newsArray);

                    if (handler != null) {
                        handler.sendEmptyMessage(6);
                    }
                }

                @Override
                public void onError(List<String> errors) {
                    Helper.showErrorToast(context, errors);
                    if (handler != null) {
                        handler.sendEmptyMessage(1);
                    }
                }
            });
}

UPD:

我们进行了一些研究,结果如下:

1。当我们搜索“Русский”标签时:

QBRequestGetBuilder builder = new QBRequestGetBuilder();
builder.in("Tags", "Русский");

https://api.quickblox.com/data/News.json?Tags[in]=%D0%A0%D1%83%D1%81%D1%81%D0%BA%D0%B8%D0%B9

结果:

news id:55b4a74f535c12b641004f3e;标签:[Русский,советы]

news id:55b91b78535c129a1d0039f2;标签:[Русский,Россия]

news id:55ba9482535c1238ce003522;标签:[Русский,Россия]

news id:55ba96c4535c1298​​ec0003fc;标签:[Русский,советы]

news id:55ba973f535c1298​​ec0004d7;标签:[Русский]

news id:55ba9967535c12e2c00017f9;标签:[Русский,Россия]

news id:55ba99e3535c1298​​ec00099f;标签:[Русский,Россия]

news id:55bd592c535c12a8d6000327;标签:[Русский]

news id:55bb32ae535c12e543006e15;标签:[Русский,религия,пятница,Коран]

因此,当它不是数组中的第一个标记时,没有搜索标记“Русский”。我们检查了数据库 - 我们有一些标签[“Россия”,“Русский”]的新闻

2。当我们搜索标签“Русский”,“Томск”:

QBRequestGetBuilder builder = new QBRequestGetBuilder();
        builder.in("Tags", "Русский", "Томск");

https://api.quickblox.com/data/News.json?Tags[in]=%D0%A0%D1%83%D1%81%D1%81%D0%BA%D0%B8%D0%B9%2C%D0%A2%D0%BE%D0%BC%D1%81%D0%BA

第3。当我们搜索标签“Томск”,“Русский”时:

QBRequestGetBuilder builder = new QBRequestGetBuilder();
        builder.in("Tags", "Томск", "Русский");

https://api.quickblox.com/data/News.json?Tags[in]=%D0%A2%D0%BE%D0%BC%D1%81%D0%BA%2C%D0%A0%D1%83%D1%81%D1%81%D0%BA%D0%B8%D0%B9

现在结果为2和3:

news id:555c46736390d8a0ca03ab61;标签:[Томск,Алмере]

news id:555c46b26390d8a7ce01439e;标签:[Томск,Алмере,Нидерланды,Россия]

news id:555c50bf6390d8b66300dadf;标签:[Россия,Томскаяобласть,Томск]

news id:555d7f5c6390d8eb8504df15;标签:[Россия,Томскаяобласть,Томск,Russia,Moscow,Москва]

news id:556454536390d894de005c22;标签:[Томск,Россия]

news id:55a905ba535c1207e600251d;标签:[Томск,Россия]

news id:55b4a74f535c12b641004f3e;标签:[Русский,советы]

news id:55b91b78535c129a1d0039f2;标签:[Русский,Россия]

news id:55ba9482535c1238ce003522;标签:[Русский,Россия]

news id:55ba96c4535c1298​​ec0003fc;标签:[Русский,советы]

news id:55ba973f535c1298​​ec0004d7;标签:[Русский]

news id:55ba9967535c12e2c00017f9;标签:[Русский,Россия]

news id:55ba99e3535c1298​​ec00099f;标签:[Русский,Россия]

news id:55bd592c535c12a8d6000327;标签:[Русский]

news id:55bb32ae535c12e543006e15;标签:[Русский,религия,пятница,Коран]

news id:55666ac66390d8ce7900044f;标签:[Томск,Россия]

1 个答案:

答案 0 :(得分:0)

根据该文件http://quickblox.com/developers/SimpleSample-customObjects-android#Search_operators

使用数组只能 nin 所有运算符

<强> UPD 例如,我有一个发布类,其字段为标记。并且记录标签= [&#34; man&#34;,&#34; golf&#34;,&#34; car&#34;]

这是我的要求:

http://api.quickblox.com/data/Post.json?tags[in]=car&token=70f997fecf68b25f8992271b5f943503884f3f52

http://api.quickblox.com/data/Post.json?tags[in]=man&token=70f997fecf68b25f8992271b5f943503884f3f52

http://api.quickblox.com/data/Post.json?tags[in]=golf&token=70f997fecf68b25f8992271b5f943503884f3f52 

他们都返回相同的记录:

{"class_name":"Post","skip":0,"limit":0,
  "items":[{"_id":"55ba0597535c12a4120011e8","_parent_id":"",
   "body":"How are you?",
   "created_at":1438254487,"tags":["man","golf","car"],
   "title":"best post","updated_at":1438254487,"user_id":291}]}