Firestore CollectionGroup查询未显示任何结果

时间:2020-09-21 06:09:20

标签: android firebase google-cloud-firestore

我正在尝试使用Firestore进行搜索活动。这是我的消防站结构。

 /Collection/Document/Collection/Document(ID generated by firesotre)
 /Recipes/Food_Recipe/Rice_Recipe/5LlP3SZO27tL9IIlMhD2

这是我的Java代码,

Query query = FirebaseFirestore.getInstance()
            .collectionGroup("Recipes").orderBy("Recipe_name").startAt(InputSearchText).endAt(InputSearchText+"\uf8ff");
 PagedList.Config config = new PagedList.Config.Builder()
            .setEnablePlaceholders(false)
            .setPrefetchDistance(2)
            .setInitialLoadSizeHint(2)
            .setPageSize(3)
            .build();
 FirestorePagingOptions<FoodItems> options = new FirestorePagingOptions.Builder<FoodItems>()
            .setQuery(query, config, FoodItems.class)
            .build();
food_items_recycle_adapter = new Food_Items_Recycle_Adapter(options, progressIndicator,this);
    recyclerView.setHasFixedSize(true);
    recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
    recyclerView.setAdapter(food_items_recycle_adapter);
    food_items_recycle_adapter.notifyDataSetChanged();
    food_items_recycle_adapter.startListening();

这是我的单个字段索引, enter image description here

这是我尝试获得结果的方式,但是没有显示任何结果。

修改 我想获取以Recipe_name以InputSearchText开头的文档


修改

 2020-09-21 11:59:24.560 26802-26802/com.example.thechef I/AssistStructure: Flattened final assist data: 5944 bytes, containing 1 windows, 26 views
2020-09-21 11:59:24.665 26802-26802/com.example.thechef W/StaticLayout: maxLineHeight should not be -1.  maxLines:1 lineCount:1
 2020-09-21 11:59:24.689 26802-26802/com.example.thechef E/RecyclerView: No adapter attached; skipping layout
 2020-09-21 11:59:27.029 26802-26802/com.example.thechef D/Search_Fragment: onClick: InputSearchText is   badu
 2020-09-21 11:59:27.071 26802-26802/com.example.thechef D/Food_Items_Recycle_Adap: onLoadingStateChanged: loading initial pages
 2020-09-21 11:59:27.284 26802-26802/com.example.thechef D/Food_Items_Recycle_Adap: onLoadingStateChanged: Wholedata loaded
 2020-09-21 11:59:29.937 26802-26807/com.example.thechef I/zygote: Do partial code cache collection, code=111KB, data=98KB
 2020-09-21 11:59:29.937 26802-26807/com.example.thechef I/zygote: After code cache collection, code=111KB, data=98KB
 2020-09-21 11:59:29.937 26802-26807/com.example.thechef I/zygote: Increasing code cache capacity to 512KB

当我在inputEditText中键入文本并按下搜索按钮时,这就是我在android studio logcat中看到的全部内容。

1 个答案:

答案 0 :(得分:0)

最后,我发现此问题的答案对Firebase专家有帮助。是否可以对不同的子集合使用集合组查询。如果要使用组查询,则子集合名称应相同。 Java代码没有问题。问题是对收集组查询有误解。 Firebase expert answer / Firebase guide

简单来说,无法从根集合进行查询。如果我错了,请编辑此答案:)