forked from nus-cs2103-AY2324S2/tp
-
Notifications
You must be signed in to change notification settings - Fork 4
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 #23 from maze508/flexible-search
Flexible search
- Loading branch information
Showing
14 changed files
with
483 additions
and
63 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
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 |
---|---|---|
|
@@ -113,23 +113,67 @@ Examples: | |
* `edit 1 p/91234567 e/[email protected]` Edits the phone number and email address of the 1st person to be `91234567` and `[email protected]` respectively. | ||
* `edit 2 n/Betsy Crower t/` Edits the name of the 2nd person to be `Betsy Crower` and clears all existing tags. | ||
|
||
### Locating persons by name: `find` | ||
### Search Contact `find` | ||
|
||
Finds persons whose names contain any of the given keywords. | ||
- Search feature supports search by name and/or tags **ONLY**. | ||
- Finds all contacts whose names or tags matches the substring keyword provided. | ||
|
||
Format: `find KEYWORD [MORE_KEYWORDS]` | ||
General Format: `find FIELD/ KEYWORD FIELD/ KEYWORD ...` | ||
- Where `FIELD` is either `n/` for name or `t/` for tag. | ||
- `KEYWORD` is the keyword (**alphabets only**) to search for. | ||
|
||
#### Search Guidelines | ||
|
||
* 'KEYWORD' can **ONLY** be alphabets and **CANNOT** contain spaces or be empty. | ||
* e.g. `find n/John Doe` will **NOT** work. Try `find n/John n/Doe` instead to represent finding John and Doe | ||
* e.g. `find n/` will **NOT** work as 'KEYWORD' cannot be empty. | ||
* e.g. `find n/John123` will **NOT** work as 'KEYWORD' cannot contain non-alphabetic characters. | ||
|
||
|
||
* 'KEYWORD' and next 'FIELD' should be separated by a space. | ||
* e.g. `find n/John t/friends` will find all instances of John that have the tag friends | ||
* but `find n/Johnt/tfriends` will instead return an error since it assumes you are searching for 'Johnt/tfriends' | ||
* and there should not be non-alphabetic characters in the 'KEYWORD' field. | ||
|
||
|
||
* Multiple of the same 'FIELDs' will be treated as a **Logical AND (&&)**. | ||
* e.g. `find n/John n/Doe` will return all instances of John and Doe. | ||
* e.g. `find n/Ale n/le` will still return the following example instances ["Alex Liew", "Alexis Lebrun", "Alec"] | ||
|
||
|
||
* 'KEYWORD' should **NOT** be empty and there should be at least one 'FIELD' and 'KEYWORD' pair. | ||
* e.g. `find n/ t/` and `find ` will **NOT** work. | ||
|
||
|
||
* There should not be prefixes before the first 'FIELD' and 'KEYWORD' pair. | ||
* e.g. `find testing123 n/John` will **NOT** work. | ||
|
||
|
||
* The search is case-insensitive. | ||
* e.g. `find n/hans` will match `Hans Niemann` and `Hans Zimmer` | ||
|
||
* The order of the keywords does not matter. | ||
* e.g. Results of `find n/Hans n/Bo` will match the results of`find n/Bo n/Hans` | ||
|
||
* You can have multiple of the same 'FIELD's. | ||
* e.g. `find n/J n/Do` will match names with `J` AND `Do`, like `John Doe` | ||
|
||
* 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` | ||
|
||
Examples: | ||
* `find John` returns `john` and `John Doe` | ||
* `find alex david` returns `Alex Yeoh`, `David Li`<br> | ||
![result for 'find alex david'](images/findAlexDavidResult.png) | ||
* `find n/Joh` returns `john`, `John Doe` and `Johnann Sebastian Bach` | ||
|
||
* `find n/alex n/david` returns `Alex Davidson` and `David Alexis` | ||
|
||
* `find n/Alex t/friends` returns `Alex Yeoh` who is tagged as a `friend` | ||
|
||
* `find n////` returns an error message as the 'KEYWORD' field must consist of alphabets only | ||
|
||
* `find n/` or `find t/` or `find n/ t/` returns an error message as the 'KEYWORD' field cannot be empty | ||
|
||
* `find` returns an error message as there should be at least one 'FIELD' and 'KEYWORD' pair | ||
|
||
* `find testing123 n/John` returns an error message as there should not be | ||
prefixes before the first 'FIELD' and 'KEYWORD' pair | ||
|
||
### Deleting a person : `delete` | ||
|
||
|
@@ -199,6 +243,6 @@ Action | Format, Examples | |
**Clear** | `clear` | ||
**Delete** | `delete INDEX`<br> e.g., `delete 3` | ||
**Edit** | `edit INDEX [n/NAME] [p/PHONE_NUMBER] [e/EMAIL] [a/ADDRESS] [t/TAG]…`<br> e.g.,`edit 2 n/James Lee e/[email protected]` | ||
**Find** | `find KEYWORD [MORE_KEYWORDS]`<br> e.g., `find James Jake` | ||
**Find** | `find KEYWORD/ [KEYWORD]`<br> e.g., `find n/ James n/ T t/ friend t/ rich` | ||
**List** | `list` | ||
**Help** | `help` |
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
60 changes: 60 additions & 0 deletions
60
src/main/java/seedu/address/model/person/NameAndTagContainsKeywordsPredicate.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,60 @@ | ||
package seedu.address.model.person; | ||
|
||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.function.Predicate; | ||
|
||
import seedu.address.commons.util.StringUtil; | ||
|
||
|
||
/** | ||
* Tests that a {@code Person}'s {@code Name} and {@code Tag} matches any of the keywords given. | ||
*/ | ||
public class NameAndTagContainsKeywordsPredicate implements Predicate<Person> { | ||
private final List<String> nameKeywords; | ||
private final List<String> tagKeywords; | ||
|
||
/** | ||
* Constructor for NameAndTagContainsKeywordsPredicate. | ||
* @param nameKeywords List of name keywords to search for. | ||
* @param tagKeywords List of tag keywords to search for. | ||
*/ | ||
public NameAndTagContainsKeywordsPredicate(List<String> nameKeywords, List<String> tagKeywords) { | ||
this.nameKeywords = nameKeywords; | ||
this.tagKeywords = tagKeywords; | ||
} | ||
|
||
@Override | ||
public boolean test(Person person) { | ||
boolean matchesName = nameKeywords.stream() | ||
.allMatch(keyword -> StringUtil.containsSubstringIgnoreCase(person.getName().fullName, keyword)); | ||
boolean matchesTags = tagKeywords.stream() | ||
.allMatch(keyword -> person.getTags().stream() | ||
.anyMatch(tag -> StringUtil.containsSubstringIgnoreCase(tag.tagName, keyword))); | ||
return matchesName && matchesTags; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
if (other == this) { | ||
return true; | ||
} | ||
|
||
// instanceof handles nulls | ||
if (!(other instanceof NameAndTagContainsKeywordsPredicate)) { | ||
return false; | ||
} | ||
|
||
NameAndTagContainsKeywordsPredicate that = (NameAndTagContainsKeywordsPredicate) other; | ||
return Objects.equals(nameKeywords, that.nameKeywords) | ||
&& Objects.equals(tagKeywords, that.tagKeywords); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "NameAndTagContainsKeywordsPredicate{" | ||
+ "nameKeywords=" + nameKeywords | ||
+ ", tagKeywords=" + tagKeywords | ||
+ '}'; | ||
} | ||
} |
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
Oops, something went wrong.