Skip to content

Commit

Permalink
Merge pull request nus-cs2103-AY2425S1#262 from jessica2828/func-bug-fix
Browse files Browse the repository at this point in the history
Fix FilterCommand bug
  • Loading branch information
juliantayyc authored Nov 11, 2024
2 parents 22887bd + b2c53f1 commit 70d1415
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 5 deletions.
2 changes: 1 addition & 1 deletion docs/UserGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ filter [KEYWORD_PREFIX] [MORE_KEYWORDS]

* **For filtering by Module:**
* Use prefix `m/`.
* Partial matching is supported, allowing users to input parts of module codes. e.g. `m/CS21` will match modules like "CS2103T" and "CS2101."
* Only full module codes will be matched, e.g. `m/CS2103T` will match the module "CS2103T", and not `m/CS21`.

<!-- -->

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ public ModuleContainsKeywordsPredicate(String keyword) {

@Override
public boolean test(Person person) {
String regex = "\\b" + keyword.toLowerCase() + "\\b";
return person.getModules().stream()
.anyMatch(module -> module.toString().toLowerCase().contains(keyword.toLowerCase()));
.anyMatch(module -> module.toString().toLowerCase().matches(".*" + regex + ".*"));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,6 @@ public void test_moduleContainsKeyword_returnsTrue() {

predicate = new ModuleContainsKeywordsPredicate("cs1010");
assertTrue(predicate.test(new PersonBuilder().addUngradedModule("CS1010").build()));

predicate = new ModuleContainsKeywordsPredicate("1010");
assertTrue(predicate.test(new PersonBuilder().addUngradedModule("CS1010").build()));
}

@Test
Expand Down

0 comments on commit 70d1415

Please sign in to comment.