I am trying to perform a search on names within my

2019-09-16 10:16发布

问题:

The problem that I am having is I can search based on numbers inside the name but any other text shows nothing. Basically if the name in the child is 1212 NW Drive, I can search on the 1212 part but not the text of the name.

Here is my code for building the adapter based on the EditText.

    mSearchText.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {

        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {

        }

        @Override
        public void afterTextChanged(Editable s) {
            mSearchInput = mSearchText.getText().toString().toLowerCase();

            if (mAutoCompleteSearchAdapter != null) mAutoCompleteSearchAdapter.cleanup();

            RecyclerView mHomeRecycler = (RecyclerView) findViewById(R.id.home_recycler_view);

                mAutoCompleteSearchAdapter = new AutoCompleteSearchAdapter(
                        BusinessesModel.class,
                        R.layout.business_listings,
                        BusinessViewHolder.class,
                        mSearchQuery = mDatabase.orderByChild("name").startAt(mSearchInput).endAt(mSearchInput + "~")) {
                };

                mHomeRecycler.setAdapter(mAutoCompleteSearchAdapter);
            }
    });

And here is my code for the FirebaseRecyclerAdapter.

public class AutoCompleteSearchAdapter extends FirebaseRecyclerAdapter<BusinessesModel, BusinessViewHolder> {


  public AutoCompleteSearchAdapter(Class<BusinessesModel> modelClass, int modelLayout, Class<BusinessViewHolder> viewHolderClass, Query ref) {
    super(modelClass, modelLayout, viewHolderClass, ref);


  }

  @Override
  protected void populateViewHolder(BusinessViewHolder viewHolder, final BusinessesModel model, int position) {

    viewHolder.setBusinessName(model.getName());
    viewHolder.setBusinessCategory(model.getCategory());

    if (model.getLogoURL() != null) {
        viewHolder.setBusinessLogo(getApplicationContext(), model.getLogoURL());
    } else {

    }

    viewHolder.setOnClickListener(new BusinessViewHolder.ClickListener() {
        @Override
        public void onItemClick(View view, int position) {
            Intent intent = new Intent(getApplicationContext(), DealDetailsActivity.class);
            intent.putExtra("name", model.getName());
            intent.putExtra("headerImg", model.getDailyDealLogoURL());
            intent.putExtra("logoImg", model.getLogoURL());
            intent.putExtra("freeDeal", model.getIsFreeDeal());
            intent.putExtra("dealOne", model.getDealOne());
            intent.putExtra("detailsOne", model.getDetailsOne());
            intent.putExtra("dealTwo", model.getDealTwo());
            intent.putExtra("detailsTwo", model.getDetailsTwo());
            intent.putExtra("dealThree", model.getDealThree());
            intent.putExtra("detailsThree", model.getDetailsThree());
            getApplicationContext().startActivity(intent);
        }
    });

}

Here is the snippet of the JSON out of the database.

[ {
  "blue" : 84,
  "category" : "Sporting Goods",
  "dealOne" : "10% Off",
  "dealThree" : "$1 Off",
  "dealTwo" : "$5 Off",
  "detailsOne" : "Cannot be combined with any other offer.",
  "detailsThree" : "Cannot be combined with any other offer.",
  "detailsTwo" : "Cannot be combined with any other offer. Cannot be combined with any other offer. Cannot be combined with any other offer. Cannot be combined with any other offer.",
  "featuredOrderField" : 1,
  "green" : 99,
  "isDailyDeal" : "yes",
  "isFeaturedDeal" : "yes",
  "isFreeDeal" : "yes",
  "name" : "Dick's Sporting Goods",
  "orderField" : 100,
  "red" : 43
}, {
  "blue" : 94,
  "category" : "Golf",
  "dealOne" : "$5 off",
  "detailsOne" : "$5 off a round of 18 hole with a cart. Also includes free small basket of range balls.",
  "featuredOrderField" : 100,
  "green" : 153,
  "isDailyDeal" : "yes",
  "isFeaturedDeal" : "yes",
  "name" : "Quail Heights Country Club",
  "orderField" : 100,
  "red" : 100
}, {
  "blue" : 115,
  "category" : "Fast Food",
  "dealOne" : "$2 Off",
  "detailsOne" : "Cannot be combined with any other offer. Participating locations: US HWY 90 and Main St.",
  "green" : 43,
  "isDailyDeal" : "yes",
  "isFeaturedDeal" : "yes",
  "name" : "Taco Bell",
  "orderField" : 100,
  "red" : 92
}, {
  "blue" : 0,
  "category" : "Resturants",
  "dealOne" : "10% off",
  "detailsOne" : "Cannot be combined with any other offer.",
  "green" : 53,
  "isFeaturedDeal" : "yes",
  "isFreeDeal" : "yes",
  "name" : "1000 Degrees Neapolitan Pizzeria",
  "orderField" : 1,
  "red" : 223
}, {
  "blue" : 37,
  "category" : "Resturants",
  "dealOne" : "$1 off",
  "detailsOne" : "Order must be at least $5 and cannot be combined with any other offer.",
  "green" : 30,
  "isFeaturedDeal" : "no",
  "isFreeDeal" : "yes",
  "name" : "Moe's Southwestern Grill",
  "orderField" : 3,
  "red" : 203
}, {
  "blue" : 0,
  "category" : "Resturants",
  "dealOne" : "$5 off a $25 order",
  "dealTwo" : "10% off",
  "detailsOne" : "Order must be $25 before the $5 coupon can be applied.",
  "detailsTwo" : "Cannot be combined with any other offer.",
  "green" : 210,
  "isFeaturedDeal" : "yes",
  "name" : "Buffalo Wild Wings",
  "orderField" : 2,
  "red" : 255
} ]