-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Persistent search #130
Persistent search #130
Conversation
Persistent search
Persistent search
Persistent search, resolve merge conflicts
Add test case coverage for PersistentSearch
if (argMultimap.getValue(PREFIX_NAME).isPresent()) { | ||
String name = argMultimap.getValue(PREFIX_NAME).get().trim(); | ||
|
||
String[] nameKeywords = name.split("\\s+"); | ||
|
||
Predicate<Person> namePred = new NameContainsKeywordsPredicate( | ||
Arrays.stream(nameKeywords).toList()); | ||
predicates.add(namePred); | ||
} | ||
if (argMultimap.getValue(PREFIX_PHONE).isPresent()) { | ||
String phone = argMultimap.getValue(PREFIX_PHONE).get().trim(); | ||
String[] phoneKeywords = phone.split("\\s+"); | ||
|
||
Predicate<Person> phonePred = new PhoneNumberContainsKeywordPredicate( | ||
Arrays.stream(phoneKeywords).toList()); | ||
predicates.add(phonePred); | ||
} | ||
if (argMultimap.getValue(PREFIX_EMAIL).isPresent()) { | ||
String email = argMultimap.getValue(PREFIX_EMAIL).get().trim(); | ||
String[] emailKeywords = email.split("\\s+"); | ||
|
||
Predicate<Person> emailPred = new EmailContainsKeywordsPredicate( | ||
Arrays.stream(emailKeywords).toList()); | ||
predicates.add(emailPred); | ||
} | ||
if (argMultimap.getValue(PREFIX_ADDRESS).isPresent()) { | ||
String address = argMultimap.getValue(PREFIX_ADDRESS).get().trim(); | ||
String[] addressKeywords = address.split("\\s+"); | ||
Predicate<Person> addressPred = new AddressContainsKeywordsPredicate( | ||
Arrays.stream(addressKeywords).toList()); | ||
|
||
predicates.add(addressPred); | ||
} | ||
if (argMultimap.getValue(PREFIX_TELEGRAM).isPresent()) { | ||
String telegram = argMultimap.getValue(PREFIX_TELEGRAM).get().trim(); | ||
String[] telegramKeywords = telegram.split("\\s+"); | ||
Predicate<Person> telegramPred = new TelegramContainsKeywordsPredicate( | ||
Arrays.stream(telegramKeywords).toList()); | ||
predicates.add(telegramPred); | ||
} | ||
//role have to use separate predicate | ||
if (argMultimap.getValue(PREFIX_ROLE).isPresent()) { | ||
String roles = argMultimap.getValue(PREFIX_ROLE).get().trim(); | ||
// map each word in String roles to a Role object |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very long method, perhaps can refactor the code by abstracting each if block into a separate method for better readability
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Just some areas that may need some refactoring
Trial Implementation of a persistent search function to group multiple selections
Issues
UI
Have NOT implemented UI for the full list of Persons
Currently no way to see who you are trying to add
## TestingUnsure how to check equality for SearchModeSearchCommands due to difficulty in checking Predicate Equality
Commands generated by SearchModeSearchCommandParser are based on Strings, making it difficult to check equality of different SearchModeSearchCommands generated.
No idea how to check equality of different Predicates
Testing of equality of functions used for FieldContainsKeywordPredicateFieldContainsKeyWordPredicate currently uses a lambda function to parse out the target field from a person object. May be difficult to test equality
Alternative: Separate each field Predicate into its own separate method.
searchmode implementation
searchmode is tracked by a boolean value searchMode in the ModelManager class. When searchMode is true, the commands accepted by the app changes.
ModelManager also tracks the last used Predicate used to filter its list lastPredicate
The displayed list will be modified by chaining lastPredicate with Predicates generated based on user parameter input using FieldContainsKeywordPredicate class
Enter search mode using searchmode
Searchmode commands
exitsearchmode
Exits searchmode, returning to view of all contacts
search n/{String} e/{String p/ ...
Searches for contacts that matches ALL search parameter criteria
The search parsing currently implemented to check if a person field contains or contains a word equal to the string
This is done in the using the FieldContainsKeywordsPredicate class
This is currently implemented using a SearchModeSearchCommand class that tracks a Set
Upon .execute, the Set is reduced using the .and method to create a final predicate used to filter the list
The predicates are currently stored in a set rather than immediately chaining them using .and due to equality checking
Chaining Searches
Searches with multiple criteria can be chained using separate search commands
search n/Alex
would first add to the displayed list all Persons with name containing Alex
search n/Roy
Adds again to the current displayed list all Persons with name containing Roy
This is done using .or method to combine the new SearchModeSearchCommand predicate with lastPredicate in model manager