Welcome to the CSC Q&A, on our server named in honor of Ada Lovelace. Write great code! Get help and give help!
It is our choices... that show what we truly are, far more than our abilities.

Categories

+20 votes

I have been working on the super search for a couple of hours now and cannot get anything to show up. I am attempting to allow the user to only have to type in part of the intended result (e.g. "bar" shows results for "low bar" and "high bar"), but I fear it might be messing up how everything is being searched. Does anyone have any tips on how they did the super search, especially if they had a similar idea to mine?

asked in CSC305 Fall 2023 by (1 point)

3 Answers

+6 votes

My group had a separate class that handles the filtering from the search bar where we searched if the data from the csv file contained what we were searching for from the search bar.

answered by (1 point)
+3 votes

Yes, you can perform a case-insensitive partial match. Specifically, you can use toLowerCase() on both the property (prop) and the filter string (filterLowerCase), and then checking if the property contains the filter string using contains().

propertiesToSearch.stream().anyMatch(prop -> prop.toLowerCase().contains(filterLowerCase))
|| listPropertiesToSearch.stream()
    .flatMap(List::stream)
    .anyMatch(item -> item.toLowerCase().contains(filterLowerCase));

So this will return true if there is any property in propertiesToSearch (that's the card properties) or any item in the flattened listPropertiesToSearch that contains the specified filterLowerCase as a substring in a case-insensitive manner.

So, if the user inputs "bar," it should match properties like "low bar" and "high bar" in both propertiesToSearch and listPropertiesToSearch.

answered by (1 point)
+2 votes

i took inspiration from stonedahls movie tracker project. it's really easy to understand

answered by (1 point)
...