diff --git a/README.md b/README.md index f1ca56ee..acba4f46 100644 --- a/README.md +++ b/README.md @@ -84,12 +84,12 @@ Format: `list` > Finds persons that match given keywords Format: `find KEYWORD [MORE_KEYWORDS]` -> The search is case sensitive, the order of the keywords does not matter, only the name is searched, +> The search is case insensitive, the order of the keywords does not matter, only the name is searched, and persons matching at least one keyword will be returned (i.e. `OR` search). Examples: -* `find John` - > Returns `John Doe` but not `john` +* `find John` or `find john` + > Returns `John Doe` * `find Betsy Tim John` > Returns Any person having names `Betsy`, `Tim`, or `John` @@ -468,4 +468,4 @@ The full list of contributors for se-edu can be found [here](https://se-edu.gith * If you would like to contact us, refer to [our website](https://se-edu.github.io/#contact). [coding-standard]: https://github.com/oss-generic/process/blob/master/codingStandards/CodingStandard-Java.md "Java Coding Standard" -[code-quality]: https://se-edu.github.io/se-book/codeQuality/ "Code Quality Best Practices" \ No newline at end of file +[code-quality]: https://se-edu.github.io/se-book/codeQuality/ "Code Quality Best Practices" diff --git a/src/seedu/addressbook/AddressBook.java b/src/seedu/addressbook/AddressBook.java index 5a158b67..e6d66247 100644 --- a/src/seedu/addressbook/AddressBook.java +++ b/src/seedu/addressbook/AddressBook.java @@ -107,7 +107,7 @@ public class AddressBook { private static final String COMMAND_FIND_WORD = "find"; private static final String COMMAND_FIND_DESC = "Finds all persons whose names contain any of the specified " - + "keywords (case-sensitive) and displays them as a list with index numbers."; + + "keywords (case-insensitive) and displays them as a list with index numbers."; private static final String COMMAND_FIND_PARAMETERS = "KEYWORD [MORE_KEYWORDS]"; private static final String COMMAND_FIND_EXAMPLE = COMMAND_FIND_WORD + " alice bob charlie"; @@ -485,14 +485,22 @@ private static Set extractKeywordsFromFindPersonArgs(String findPersonCo private static ArrayList getPersonsWithNameContainingAnyKeyword(Collection keywords) { final ArrayList matchedPersons = new ArrayList<>(); for (String[] person : getAllPersonsInAddressBook()) { - final Set wordsInName = new HashSet<>(splitByWhitespace(getNameFromPerson(person))); - if (!Collections.disjoint(wordsInName, keywords)) { + final Set wordsInName = new HashSet<>(splitByWhitespace(getNameFromPerson(person).toLowerCase())); + if (!Collections.disjoint(wordsInName, toLowerCaseKeywords(keywords))) { matchedPersons.add(person); } } return matchedPersons; } + private static Collection toLowerCaseKeywords(Collection keywords) { + ArrayList lowerCaseKeywords = new ArrayList(); + for (String keyword : keywords) { + lowerCaseKeywords.add(keyword.toLowerCase()); + } + return lowerCaseKeywords; + } + /** * Deletes person identified using last displayed index. * diff --git a/test/expected.txt b/test/expected.txt index f18922ac..60bda0b2 100644 --- a/test/expected.txt +++ b/test/expected.txt @@ -184,8 +184,9 @@ || 0 persons found! || =================================================== || Enter command: || [Command entered: find betsy] +|| 1. Betsy Choo Phone Number: 222222 Email: benchoo@nus.edu.sg || -|| 0 persons found! +|| 1 persons found! || =================================================== || Enter command: || [Command entered: find Betsy] || 1. Betsy Choo Phone Number: 222222 Email: benchoo@nus.edu.sg diff --git a/test/input.txt b/test/input.txt index 0b99df54..30b53246 100644 --- a/test/input.txt +++ b/test/input.txt @@ -51,7 +51,7 @@ find bet # does not match if none have keyword find 23912039120 - # matching should be case-sensitive + # matching should no longer be case-sensitive find betsy # find unique keyword @@ -105,4 +105,4 @@ # exits properly exit - list \ No newline at end of file + list