Sql 喜欢使用 MaterialSearchBar 查询 Firebase 数据库参考
Sql Like query for Firebase Database Reference with MaterialSearchBar
这是我要在products.about中专门搜索的数据:
"products": {
"10001": {
"about": "Marble Chowki pair with intricate floral Painting by Handicrafts Paradise",
"category": "handicrafts",
"contact_vendor": "09171430513",
"images": {
"1001": {
"url": "https://firebasestorage.googleapis.com/v0/b/sarasmelaapp.appspot.com/o/products_images%2Fchowki.jpg?alt=media&token=a74bf78e-f5ad-410c-aa28-9cbcacf386c4"
},
"1002": {
"url": "https://firebasestorage.googleapis.com/v0/b/sarasmelaapp.appspot.com/o/products_images%2Fchowki1.jpg?alt=media&token=f91b064f-98fa-4504-91ff-ef56b43ab1fc"
}
},
"shop_location": "Stall No. 56, Saras Mela, Patna",
"vendor_address": "Rajasthan Handicraft And Textiles, Opposite Dada Bari, amer, Sagar Rd, Devisinghpura, Rajasthan 302028"
},
"10002": {
"about": "Generic ITOS365 Handmade Vintage Dummy Gramophone Only For Home Décor",
"category": "handicrafts",
"contact_vendor": "01412630837",
"images": {
"1001": {
"url": "https://firebasestorage.googleapis.com/v0/b/sarasmelaapp.appspot.com/o/products_images%2Fgramophone.jpg?alt=media&token=8a5cb8a1-4786-4d1b-b5cc-1072de9331de"
},
"1002": {
"url": "https://firebasestorage.googleapis.com/v0/b/sarasmelaapp.appspot.com/o/products_images%2Fgramophone1.jpg?alt=media&token=6992be5f-2153-4cc5-89ef-1e36850ae21f"
}
},
"shop_location": "Stall No. 56, Saras Mela, Patna",
"vendor_address": "Near Rmgarh Turn, Amber Road, Sanganeer, Amber Road, Jaipur, Rajasthan 302002"
}
}
这是我正在使用的 MaterialSearchBar 的实现:
searchBar.setOnSearchActionListener(new MaterialSearchBar.OnSearchActionListener() {
@Override
public void onSearchStateChanged(boolean enabled) {
if(enabled) {
GridAutoFitLayoutManager layoutManager = new GridAutoFitLayoutManager(view.getContext(), 300);
categories.setLayoutManager(layoutManager);
categories.setNestedScrollingEnabled(false);
searchListRecyclerAdapter = new ProductsRecyclerAdapter(searchList, view.getContext()) ;
categories.setAdapter(searchListRecyclerAdapter);
} else {
onButtonClicked(MaterialSearchBar.BUTTON_BACK) ;
}
}
@Override
public void onSearchConfirmed(CharSequence text) {
//HERE IS THE COMPLICATION
searchList = CategoryActivity.feed_data() ;
searchListRecyclerAdapter = new ProductsRecyclerAdapter(searchList, view.getContext()) ;
categories.setAdapter(searchListRecyclerAdapter);
}
@Override
public void onButtonClicked(int buttonCode) {
if(buttonCode == MaterialSearchBar.BUTTON_BACK) {
categoriesRecyclerAdapter = new CategoriesRecyclerAdapter(categoryList, view.getContext());
LinearLayoutManager verticalLayoutManager = new LinearLayoutManager
(view.getContext(), LinearLayoutManager.VERTICAL, false);
categories.setLayoutManager(verticalLayoutManager);
categories.setNestedScrollingEnabled(false);
categories.setAdapter(categoriesRecyclerAdapter);
}
}
});
}
我想以某种方式搜索 Firebase 数据库并填充 searchList 中的数据以创建布局。我不知道如何实现它。
这是我最终必须解决的问题。由于我可以在性能上做出一些妥协,但我需要我的搜索结果是准确的,所以我对所有产品一个一个地使用了 for-each 循环,并搜索了我想要的每个字符串。
无论我需要哪个对象,我都将它们添加到 ArrayList 中,最后通过 feedData() 函数传递。
我知道这不是最好的解决方案,但我不得不即兴发挥,这在 firebase 中是不可能的,这是我所能达到的最佳结果。
这是我要在products.about中专门搜索的数据:
"products": {
"10001": {
"about": "Marble Chowki pair with intricate floral Painting by Handicrafts Paradise",
"category": "handicrafts",
"contact_vendor": "09171430513",
"images": {
"1001": {
"url": "https://firebasestorage.googleapis.com/v0/b/sarasmelaapp.appspot.com/o/products_images%2Fchowki.jpg?alt=media&token=a74bf78e-f5ad-410c-aa28-9cbcacf386c4"
},
"1002": {
"url": "https://firebasestorage.googleapis.com/v0/b/sarasmelaapp.appspot.com/o/products_images%2Fchowki1.jpg?alt=media&token=f91b064f-98fa-4504-91ff-ef56b43ab1fc"
}
},
"shop_location": "Stall No. 56, Saras Mela, Patna",
"vendor_address": "Rajasthan Handicraft And Textiles, Opposite Dada Bari, amer, Sagar Rd, Devisinghpura, Rajasthan 302028"
},
"10002": {
"about": "Generic ITOS365 Handmade Vintage Dummy Gramophone Only For Home Décor",
"category": "handicrafts",
"contact_vendor": "01412630837",
"images": {
"1001": {
"url": "https://firebasestorage.googleapis.com/v0/b/sarasmelaapp.appspot.com/o/products_images%2Fgramophone.jpg?alt=media&token=8a5cb8a1-4786-4d1b-b5cc-1072de9331de"
},
"1002": {
"url": "https://firebasestorage.googleapis.com/v0/b/sarasmelaapp.appspot.com/o/products_images%2Fgramophone1.jpg?alt=media&token=6992be5f-2153-4cc5-89ef-1e36850ae21f"
}
},
"shop_location": "Stall No. 56, Saras Mela, Patna",
"vendor_address": "Near Rmgarh Turn, Amber Road, Sanganeer, Amber Road, Jaipur, Rajasthan 302002"
}
}
这是我正在使用的 MaterialSearchBar 的实现:
searchBar.setOnSearchActionListener(new MaterialSearchBar.OnSearchActionListener() {
@Override
public void onSearchStateChanged(boolean enabled) {
if(enabled) {
GridAutoFitLayoutManager layoutManager = new GridAutoFitLayoutManager(view.getContext(), 300);
categories.setLayoutManager(layoutManager);
categories.setNestedScrollingEnabled(false);
searchListRecyclerAdapter = new ProductsRecyclerAdapter(searchList, view.getContext()) ;
categories.setAdapter(searchListRecyclerAdapter);
} else {
onButtonClicked(MaterialSearchBar.BUTTON_BACK) ;
}
}
@Override
public void onSearchConfirmed(CharSequence text) {
//HERE IS THE COMPLICATION
searchList = CategoryActivity.feed_data() ;
searchListRecyclerAdapter = new ProductsRecyclerAdapter(searchList, view.getContext()) ;
categories.setAdapter(searchListRecyclerAdapter);
}
@Override
public void onButtonClicked(int buttonCode) {
if(buttonCode == MaterialSearchBar.BUTTON_BACK) {
categoriesRecyclerAdapter = new CategoriesRecyclerAdapter(categoryList, view.getContext());
LinearLayoutManager verticalLayoutManager = new LinearLayoutManager
(view.getContext(), LinearLayoutManager.VERTICAL, false);
categories.setLayoutManager(verticalLayoutManager);
categories.setNestedScrollingEnabled(false);
categories.setAdapter(categoriesRecyclerAdapter);
}
}
});
}
我想以某种方式搜索 Firebase 数据库并填充 searchList 中的数据以创建布局。我不知道如何实现它。
这是我最终必须解决的问题。由于我可以在性能上做出一些妥协,但我需要我的搜索结果是准确的,所以我对所有产品一个一个地使用了 for-each 循环,并搜索了我想要的每个字符串。
无论我需要哪个对象,我都将它们添加到 ArrayList 中,最后通过 feedData() 函数传递。
我知道这不是最好的解决方案,但我不得不即兴发挥,这在 firebase 中是不可能的,这是我所能达到的最佳结果。