forked from AY2324S1-CS2103T-F12-4/tp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request AY2324S1-CS2103T-F12-4#93 from qz1004/update-findc
Modify findc to search for more fields
- Loading branch information
Showing
37 changed files
with
1,102 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -81,7 +81,7 @@ Adds a contact to OutBook. | |
|
||
Format: `addc n/NAME p/PHONE_NUMBER e/EMAIL l/LAST_CONTACTED_TIME s/STATUS [t/TAG]…` | ||
|
||
* NAME, PHONE_NUMBER, EMAIL and LAST_CONTACTED_TIME are compulsory fields. STATUS and TAG are optional. | ||
* NAME, PHONE_NUMBER, and EMAIL are compulsory fields. STATUS, TAG and LAST_CONTACTED_TIME are optional. | ||
* PHONE_NUMBER must contain only numbers, and be at least 3 digits long. | ||
* EMAIL must be of the format local-part@domain and adhere to the following constraints: | ||
1. The local-part should only contain alphanumeric characters and these special characters, excluding the parentheses, (+_.-). | ||
|
@@ -174,23 +174,28 @@ Examples: | |
* `viewc 2` Displays detailed information related to the 2nd contact on the list. | ||
|
||
|
||
### Locating persons by name: `findc` | ||
### Search for persons using contact fields: `findc` | ||
Find persons whose contact details match the keywords specified for at least 1 of these fields: name, phone, email, status, tag | ||
|
||
Find contacts whose names contain any of the given keywords. | ||
Format: `findc [n/KEYWORDS] [p/KEYWORDS] [e/KEYWORDS] [l/DATETIME] [s/KEYWORDS] [t/KEYWORDS]` | ||
|
||
Format: `findc KEYWORD [MORE_KEYWORDS]` | ||
|
||
* The search is case-insensitive. e.g `hans` will match `Hans` | ||
* The order of the keywords does not matter. e.g. `Hans Bo` will match `Bo Hans` | ||
* Only the name is searched. | ||
* Only full words will be matched e.g. `Han` will not match `Hans` | ||
* Persons matching at least one keyword will be returned (i.e. `OR` search). | ||
e.g. `Hans Bo` will return `Hans Gruber`, `Bo Yang` | ||
* The search is case-insensitive. e.g `shop` will match `SHOP` | ||
* The order of the keywords does not matter. e.g. `Shop Meet` will match `Meet Shop` | ||
* For name, status and tags, only full words will be matched e.g. `Meet` will not match `Meeting` | ||
* For email, any characters (alphanumeric, special characters) will be matched e.g. `_` will match `[email protected]` | ||
* For phone, the entire length of the input digits will be matched e.g. `913` will match `90091300` but not `90103000` | ||
* For last contacted time, the input must adhere to the dd.MM.yyyy HHmm format e.g. 9th October 2023 10.30am will be `09.10.2023 1030` | ||
* For a single field, a Person must match at least one keyword to be returned as a result (i.e. `OR` search). | ||
e.g. `John Doe` will return `John Lee`, `James Doe` | ||
* If there are multiple fields specified, the Person must match at least one keyword in each field to be returned as a result (i.e. `AND` search). | ||
e.g. `m/Shop Meet a/Mall` will return `Meeting: Shop at mall, Location:Mall` | ||
|
||
Examples: | ||
* `findc John` returns `john` and `John Doe` | ||
* `findc alex david` returns `Alex Yeoh`, `David Li`<br> | ||
![result for 'find alex david'](images/findAlexDavidResult.png) | ||
* `findc n/alice` returns `Alice` and `alice tan` | ||
* `findc p/51` returns `95163890` and `40351` | ||
* `findc e/_@GMAIL` returns `[email protected]` | ||
* `findc p/9 s/inactive claimant t/friend` returns persons with a `9` in their phone number, whose status is either `inactive` or `claimant`, and has a `friend` tag | ||
![result for 'findContact'](images/findContactResult.png) | ||
|
||
|
||
## Meeting commands | ||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 47 additions & 8 deletions
55
src/main/java/seedu/address/logic/parser/FindCommandParser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,72 @@ | ||
package seedu.address.logic.parser; | ||
|
||
import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_LASTTIME; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_STATUS; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG; | ||
|
||
import java.util.Arrays; | ||
import java.time.LocalDateTime; | ||
import java.util.logging.Logger; | ||
|
||
import seedu.address.Main; | ||
import seedu.address.commons.core.LogsCenter; | ||
import seedu.address.logic.commands.FindCommand; | ||
import seedu.address.logic.parser.exceptions.ParseException; | ||
import seedu.address.model.person.NameContainsKeywordsPredicate; | ||
import seedu.address.model.person.GeneralPersonPredicate; | ||
import seedu.address.model.person.LastContactedTime; | ||
|
||
/** | ||
* Parses input arguments and creates a new FindCommand object | ||
*/ | ||
public class FindCommandParser implements Parser<FindCommand> { | ||
private static Logger logger = LogsCenter.getLogger(Main.class); | ||
|
||
/** | ||
* Parses the given {@code String} of arguments in the context of the FindCommand | ||
* and returns a FindCommand object for execution. | ||
* @throws ParseException if the user input does not conform the expected format | ||
*/ | ||
public FindCommand parse(String args) throws ParseException { | ||
String trimmedArgs = args.trim(); | ||
if (trimmedArgs.isEmpty()) { | ||
throw new ParseException( | ||
String.format(MESSAGE_INVALID_COMMAND_FORMAT, FindCommand.MESSAGE_USAGE)); | ||
logger.info("Begin FindCommand parse"); | ||
assert args != null; | ||
|
||
ArgumentMultimap argMultimap = ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, | ||
PREFIX_LASTTIME, PREFIX_STATUS, PREFIX_TAG); | ||
if (!argMultimap.getPreamble().isEmpty()) { | ||
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, FindCommand.MESSAGE_USAGE)); | ||
} | ||
argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, | ||
PREFIX_LASTTIME, PREFIX_STATUS, PREFIX_TAG); | ||
|
||
logger.info("Begin creation of Meeting predicates"); | ||
String[] nameKeyWords = argMultimap.getValue(PREFIX_NAME).orElse("").split("\\s+"); | ||
String[] phoneValues = argMultimap.getValue(PREFIX_PHONE).orElse("").split("\\s+"); | ||
String[] emailKeyWords = argMultimap.getValue(PREFIX_EMAIL).orElse("").split("\\s+"); | ||
String[] statusKeyWords = argMultimap.getValue(PREFIX_STATUS).orElse("").split("\\s+"); | ||
String[] tagKeyWords = argMultimap.getValue(PREFIX_TAG).orElse("").split("\\s+"); | ||
|
||
LocalDateTime lastContacted = LocalDateTime.MIN; | ||
if (argMultimap.getValue(PREFIX_LASTTIME).isPresent()) { | ||
lastContacted = ParserUtil.parseContactTime(argMultimap.getValue(PREFIX_LASTTIME).get()); | ||
if (!LastContactedTime.isValidLastContactedTime(lastContacted)) { | ||
throw new ParseException(LastContactedTime.MESSAGE_CONSTRAINTS); | ||
} | ||
} | ||
|
||
GeneralPersonPredicate generalPersonPredicate = new GeneralPersonPredicate( | ||
nameKeyWords, | ||
phoneValues, | ||
emailKeyWords, | ||
lastContacted, | ||
statusKeyWords, | ||
tagKeyWords); | ||
|
||
String[] nameKeywords = trimmedArgs.split("\\s+"); | ||
logger.info("All Person predicates created"); | ||
|
||
return new FindCommand(new NameContainsKeywordsPredicate(Arrays.asList(nameKeywords))); | ||
return new FindCommand(generalPersonPredicate); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
src/main/java/seedu/address/model/person/EmailContainsKeywordsPredicate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package seedu.address.model.person; | ||
|
||
import java.util.List; | ||
import java.util.function.Predicate; | ||
|
||
import seedu.address.commons.util.ToStringBuilder; | ||
|
||
/** | ||
* Tests that a {@code Person}'s {@code Email} matches any of the keywords given. | ||
*/ | ||
public class EmailContainsKeywordsPredicate implements Predicate<Person> { | ||
private final List<String> keywords; | ||
|
||
public EmailContainsKeywordsPredicate(List<String> keywords) { | ||
this.keywords = keywords; | ||
} | ||
|
||
@Override | ||
public boolean test(Person person) { | ||
String email = person.getEmail().toString(); | ||
Boolean result = false; | ||
for (String keyword : keywords) { | ||
result |= email.contains(keyword.toLowerCase()); | ||
} | ||
return result; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
if (other == this) { | ||
return true; | ||
} | ||
|
||
// instanceof handles nulls | ||
if (!(other instanceof EmailContainsKeywordsPredicate)) { | ||
return false; | ||
} | ||
|
||
EmailContainsKeywordsPredicate otherEmailContainsKeywordsPredicate = (EmailContainsKeywordsPredicate) other; | ||
return keywords.equals(otherEmailContainsKeywordsPredicate.keywords); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return new ToStringBuilder(this).add("keywords", keywords).toString(); | ||
} | ||
} |
Oops, something went wrong.