Fix search with best guess query containing hyphen (#1753)

Split searched best guess query into single wildcard query terms.
This commit is contained in:
Sebastian Sdorra
2021-08-02 13:43:48 +02:00
committed by GitHub
parent 124e7f1b18
commit 6a5d56244c
3 changed files with 67 additions and 10 deletions

View File

@@ -63,6 +63,7 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Mockito.lenient;
import static org.mockito.Mockito.when;
@SuppressWarnings("java:S5976")
@SubjectAware(value = "trillian", permissions = "abc")
@ExtendWith({MockitoExtension.class, ShiroExtension.class})
class LuceneQueryBuilderTest {
@@ -107,6 +108,37 @@ class LuceneQueryBuilderTest {
assertThat(result.getTotalHits()).isOne();
}
@Test
void shouldMatchWithHyphen() throws IOException {
try (IndexWriter writer = writer()) {
writer.addDocument(personDoc("Trillian-McMillan"));
}
QueryResult result = query(Person.class, "Trillian-McMi");
assertThat(result.getTotalHits()).isOne();
}
@Test
void shouldMatchQueryWithMultipleFieldsAndHyphen() throws IOException {
try (IndexWriter writer = writer()) {
writer.addDocument(inetOrgPersonDoc("Trillian", "McMillan", "Trillian McMillan", "abc"));
}
QueryResult result = query(InetOrgPerson.class, "Trillian-McMi");
assertThat(result.getTotalHits()).isOne();
}
@Test
void shouldMatchExpertQueryWithHyphen() throws IOException {
try (IndexWriter writer = writer()) {
writer.addDocument(personDoc("Trillian-McMillan"));
}
QueryResult result = query(Person.class, "lastName:Trillian-McMi");
assertThat(result.getTotalHits()).isOne();
}
@Test
@SuppressWarnings("java:S5976")
void shouldNotAppendWildcardIfStarIsUsed() throws IOException {