From 34feaf74d304e75693a897d4ac3fc3cf13eaa779 Mon Sep 17 00:00:00 2001 From: WU PEI HSUAN Date: Mon, 11 Feb 2019 14:38:20 +0800 Subject: [PATCH 1/3] Enhancement: find - case insensitive --- src/seedu/addressbook/commands/FindCommand.java | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/seedu/addressbook/commands/FindCommand.java b/src/seedu/addressbook/commands/FindCommand.java index 7fe2c52c3..9061b3fdf 100644 --- a/src/seedu/addressbook/commands/FindCommand.java +++ b/src/seedu/addressbook/commands/FindCommand.java @@ -1,23 +1,23 @@ package seedu.addressbook.commands; import java.util.ArrayList; -import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Set; +import java.lang.*; import seedu.addressbook.data.person.ReadOnlyPerson; /** * Finds and lists all persons in address book whose name contains any of the argument keywords. - * Keyword matching is case sensitive. + * Keyword matching is case insensitive. */ public class FindCommand extends Command { public static final String COMMAND_WORD = "find"; public static final String MESSAGE_USAGE = COMMAND_WORD + ": Finds all persons whose names contain any of " - + "the specified keywords (case-sensitive) and displays them as a list with index numbers.\n" + + "the specified keywords (case-insensitive) and displays them as a list with index numbers.\n" + "Parameters: KEYWORD [MORE_KEYWORDS]...\n" + "Example: " + COMMAND_WORD + " alice bob charlie"; @@ -42,6 +42,7 @@ public CommandResult execute() { /** * Retrieves all persons in the address book whose names contain some of the specified keywords. + * Will check for equality with case ignored * * @param keywords for searching * @return list of persons found @@ -50,10 +51,15 @@ private List getPersonsWithNameContainingAnyKeyword(Set final List matchedPersons = new ArrayList<>(); for (ReadOnlyPerson person : addressBook.getAllPersons()) { final Set wordsInName = new HashSet<>(person.getName().getWordsInName()); - if (!Collections.disjoint(wordsInName, keywords)) { - matchedPersons.add(person); + for (String words : wordsInName) { + for (String key : keywords ){ + if (words.equalsIgnoreCase(key)){ + matchedPersons.add(person); + } + } } } + return matchedPersons; } From a1c0c7e1e83de134dae4687ff7be48fde04d4d9f Mon Sep 17 00:00:00 2001 From: WU PEI HSUAN Date: Mon, 11 Feb 2019 14:38:52 +0800 Subject: [PATCH 2/3] Update test files for enhancement --- test/expected.txt | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/test/expected.txt b/test/expected.txt index 56fe5fcac..adfd75091 100644 --- a/test/expected.txt +++ b/test/expected.txt @@ -14,7 +14,7 @@ || Example: delete 1 || Clears address book permanently. || Example: clear -|| find: Finds all persons whose names contain any of the specified keywords (case-sensitive) and displays them as a list with index numbers. +|| find: Finds all persons whose names contain any of the specified keywords (case-insensitive) and displays them as a list with index numbers. || Parameters: KEYWORD [MORE_KEYWORDS]... || Example: find alice bob charlie || list: Displays all persons in the address book as a list with index numbers. @@ -200,7 +200,7 @@ || =================================================== || Enter command: || [Command entered: find] || Invalid command format! -|| find: Finds all persons whose names contain any of the specified keywords (case-sensitive) and displays them as a list with index numbers. +|| find: Finds all persons whose names contain any of the specified keywords (case-insensitive) and displays them as a list with index numbers. || Parameters: KEYWORD [MORE_KEYWORDS]... || Example: find alice bob charlie || =================================================== @@ -213,8 +213,9 @@ || 0 persons listed! || =================================================== || Enter command: || [Command entered: find betsy] +|| 1. Betsy Choo Tags: [secretive] || -|| 0 persons listed! +|| 1 persons listed! || =================================================== || Enter command: || [Command entered: find Betsy] || 1. Betsy Choo Tags: [secretive] From b5e21425c40059f565afb2916f0bcbf0ee325e2f Mon Sep 17 00:00:00 2001 From: WU PEI HSUAN Date: Mon, 11 Feb 2019 15:17:08 +0800 Subject: [PATCH 3/3] Update User Guide --- docs/UserGuide.adoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/UserGuide.adoc b/docs/UserGuide.adoc index 4abb17e3e..c62533072 100644 --- a/docs/UserGuide.adoc +++ b/docs/UserGuide.adoc @@ -79,7 +79,7 @@ Format: `find KEYWORD [MORE_KEYWORDS]` [NOTE] ==== -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). ====