RED-2175 Bugfix for should query (use matchQuery() instead of termQuery()) and extended unit tests for index creation tests
This commit is contained in:
parent
645411a72a
commit
0ebe18cdfe
@ -86,9 +86,9 @@ public class SearchService {
|
||||
sectionsQueries.should(textPhraseQuery);
|
||||
}
|
||||
for (String should : query.getShoulds()) {
|
||||
QueryBuilder textTermQuery = QueryBuilders.termQuery("sections.text", should.toLowerCase(Locale.ROOT))
|
||||
QueryBuilder textTermQuery = QueryBuilders.matchQuery("sections.text", should.toLowerCase(Locale.ROOT))
|
||||
.queryName(should);
|
||||
QueryBuilder filenameTermQuery = QueryBuilders.termQuery("filename", should.toLowerCase(Locale.ROOT))
|
||||
QueryBuilder filenameTermQuery = QueryBuilders.matchQuery("filename", should.toLowerCase(Locale.ROOT))
|
||||
.queryName("filename." + should);
|
||||
entireQuery.should(textTermQuery);
|
||||
entireQuery.should(filenameTermQuery);
|
||||
|
||||
@ -42,37 +42,259 @@ public class IndexCreatorTest extends AbstractElasticsearchIntegrationTest {
|
||||
@MockBean
|
||||
private FileStatusProcessingUpdateClient fileStatusProcessingUpdateClient;
|
||||
|
||||
|
||||
/*
|
||||
* Index two documents and delete one
|
||||
*/
|
||||
@Test
|
||||
public void test() throws IOException {
|
||||
|
||||
public void testTwoDocumentsAndDeleteOne() throws IOException {
|
||||
// Arrange
|
||||
ClassPathResource textResource = new ClassPathResource("files/Text.json");
|
||||
Text text = objectMapper.readValue(textResource.getInputStream(), Text.class);
|
||||
|
||||
ClassPathResource textResource2 = new ClassPathResource("files/Text2.json");
|
||||
Text text2 = objectMapper.readValue(textResource2.getInputStream(), Text.class);
|
||||
|
||||
documentIndexService.indexDocument("template1", "dossierId", "fileId", "Single Study - Oral (Gavage) Mouse.pdf", text);
|
||||
documentIndexService.indexDocument("template1", "dossierId1", "fileId1", "Single Study - Oral (Gavage) Mouse.pdf", text);
|
||||
documentIndexService.indexDocument("template2", "dossierId2", "fileId2", "S-Metolachlor_RAR_01_Volume_1_2018-09-06.pdf", text2);
|
||||
|
||||
// Act & Assert 1
|
||||
SearchResult result = searchService.search("hans klaus single", null, null, null, 1, 10, true);
|
||||
|
||||
assertThat(result.getMatchedDocuments().size()).isEqualTo(2);
|
||||
|
||||
documentDeleteService.deleteDocument("fileId");
|
||||
// Act
|
||||
documentDeleteService.deleteDocument("fileId1");
|
||||
|
||||
result = searchService.search("hans klaus single", null, Arrays.asList("dossierId", "dossierId2"), null, 1, 10, true);
|
||||
// Act & Assert 2
|
||||
result = searchService.search("hans klaus single", null, Arrays.asList("dossierId1", "dossierId2"), null, 1, 10, true);
|
||||
|
||||
assertThat(result.getMatchedDocuments().size()).isEqualTo(1);
|
||||
|
||||
// Act & Assert 3
|
||||
result = searchService.search("hans klaus single", null, Arrays.asList("dossierId3", "dossierId4"), null, 1, 10, true);
|
||||
|
||||
assertThat(result.getMatchedDocuments().size()).isEqualTo(0);
|
||||
|
||||
// Act & Assert 4
|
||||
result = searchService.search("hans klaus single", Arrays.asList("template1", "template2"), null, null, 1, 10, true);
|
||||
|
||||
assertThat(result.getMatchedDocuments().size()).isEqualTo(1);
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* SearchService will not find any result
|
||||
*/
|
||||
@Test
|
||||
public void testWithoutResult() throws IOException {
|
||||
// Arrange
|
||||
ClassPathResource textResource = new ClassPathResource("files/Text.json");
|
||||
Text text = objectMapper.readValue(textResource.getInputStream(), Text.class);
|
||||
String fileName = "luke-skywalker-42.pdf";
|
||||
String searchString = "szedhsegkekhglghserlkghrsdvkerxyfdbvkrdjgh";
|
||||
documentIndexService.indexDocument("template1", "dossierId1", "fileId1", fileName, text);
|
||||
|
||||
// Act
|
||||
SearchResult result = searchService.search(searchString, null, Arrays.asList("dossierId1"), null, 1, 10, true);
|
||||
|
||||
// Assert
|
||||
assertThat(result.getMatchedDocuments().size()).isEqualTo(1);
|
||||
assertThat(result.getMatchedDocuments().get(0).getMatchedTerms().size()).isEqualTo(0);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Filename contains hyphen and searchString contains complete filename
|
||||
*/
|
||||
@Test
|
||||
public void testFilenameWithHyphenWholeFilenameSearch() throws IOException {
|
||||
// Arrange
|
||||
ClassPathResource textResource = new ClassPathResource("files/Text.json");
|
||||
Text text = objectMapper.readValue(textResource.getInputStream(), Text.class);
|
||||
String fileName = "luke-skywalker-42.pdf";
|
||||
String searchString = fileName;
|
||||
documentIndexService.indexDocument("template1", "dossierId1", "fileId1", fileName, text);
|
||||
|
||||
// Act
|
||||
SearchResult result = searchService.search(searchString, null, Arrays.asList("dossierId1"), null, 1, 10, true);
|
||||
|
||||
// Assert
|
||||
assertThat(result.getMatchedDocuments().size()).isEqualTo(1);
|
||||
assertThat(result.getMatchedDocuments().get(0).getMatchedTerms().size()).isGreaterThan(0);
|
||||
assertThat(result.getMatchedDocuments().get(0).getMatchedTerms().contains(searchString)).isTrue();
|
||||
}
|
||||
|
||||
/*
|
||||
* Filename contains hyphen and searchString is like complete filename
|
||||
*/
|
||||
@Test
|
||||
public void testFilenameWithHyphenLikeFilenameSearch() throws IOException {
|
||||
// Arrange
|
||||
ClassPathResource textResource = new ClassPathResource("files/Text.json");
|
||||
Text text = objectMapper.readValue(textResource.getInputStream(), Text.class);
|
||||
String fileName = "luke-skywalker-42.pdf";
|
||||
String searchString = "luke-skiwalker-42.pdf";
|
||||
documentIndexService.indexDocument("template1", "dossierId1", "fileId1", fileName, text);
|
||||
|
||||
// Act
|
||||
SearchResult result = searchService.search(searchString, null, Arrays.asList("dossierId1"), null, 1, 10, true);
|
||||
|
||||
// Assert
|
||||
assertThat(result.getMatchedDocuments().size()).isEqualTo(1);
|
||||
assertThat(result.getMatchedDocuments().get(0).getMatchedTerms().size()).isGreaterThan(0);
|
||||
assertThat(result.getMatchedDocuments().get(0).getMatchedTerms().contains(searchString)).isTrue();
|
||||
}
|
||||
|
||||
/*
|
||||
* Filename contains hyphen & blank and searchString contains complete filename
|
||||
*/
|
||||
@Test
|
||||
public void testFilenameWithHyphenAndBlankContainsFilenameSearch() throws IOException {
|
||||
// Arrange
|
||||
ClassPathResource textResource = new ClassPathResource("files/Text.json");
|
||||
Text text = objectMapper.readValue(textResource.getInputStream(), Text.class);
|
||||
String fileName = "luke-blankwalker 42.pdf";
|
||||
String searchString = fileName;
|
||||
documentIndexService.indexDocument("template1", "dossierId1", "fileId1", fileName, text);
|
||||
|
||||
// Act
|
||||
SearchResult result = searchService.search(searchString, null, Arrays.asList("dossierId1"), null, 1, 10, true);
|
||||
|
||||
// Assert
|
||||
assertThat(result.getMatchedDocuments().size()).isEqualTo(1);
|
||||
assertThat(result.getMatchedDocuments().get(0).getMatchedTerms().size()).isGreaterThan(0);
|
||||
assertThat(result.getMatchedDocuments().get(0).getMatchedTerms().contains("luke-blankwalker")).isTrue();
|
||||
assertThat(result.getMatchedDocuments().get(0).getMatchedTerms().contains("42.pdf")).isTrue();
|
||||
}
|
||||
|
||||
/*
|
||||
* Filename contains hyphen and searchString contains one word from filename
|
||||
*/
|
||||
@Test
|
||||
public void testFilenameWithHyphenOneWordSearch() throws IOException {
|
||||
// Arrange
|
||||
ClassPathResource textResource = new ClassPathResource("files/Text.json");
|
||||
Text text = objectMapper.readValue(textResource.getInputStream(), Text.class);
|
||||
String fileName = "luke-skywalker-42.pdf";
|
||||
String searchString = "luke";
|
||||
documentIndexService.indexDocument("template1", "dossierId1", "fileId1", fileName, text);
|
||||
|
||||
// Act
|
||||
SearchResult result = searchService.search(searchString, null, Arrays.asList("dossierId1"), null, 1, 10, true);
|
||||
|
||||
// Assert
|
||||
assertThat(result.getMatchedDocuments().size()).isEqualTo(1);
|
||||
assertThat(result.getMatchedDocuments().get(0).getMatchedTerms().size()).isGreaterThan(0);
|
||||
assertThat(result.getMatchedDocuments().get(0).getMatchedTerms().contains(searchString)).isTrue();
|
||||
}
|
||||
|
||||
/*
|
||||
* Filename contains hyphen and searchString contains filename without file ending
|
||||
*/
|
||||
@Test
|
||||
public void testFilenameWithHyphenWithoutFileEnding() throws IOException {
|
||||
// Arrange
|
||||
ClassPathResource textResource = new ClassPathResource("files/Text.json");
|
||||
Text text = objectMapper.readValue(textResource.getInputStream(), Text.class);
|
||||
String fileName = "luke-skywalker-42.pdf";
|
||||
String searchString = "luke-skywalker-42";
|
||||
documentIndexService.indexDocument("template1", "dossierId1", "fileId1", fileName, text);
|
||||
|
||||
// Act
|
||||
SearchResult result = searchService.search(searchString, null, Arrays.asList("dossierId1"), null, 1, 10, true);
|
||||
|
||||
// Assert
|
||||
assertThat(result.getMatchedDocuments().size()).isEqualTo(1);
|
||||
assertThat(result.getMatchedDocuments().get(0).getMatchedTerms().size()).isGreaterThan(0);
|
||||
assertThat(result.getMatchedDocuments().get(0).getMatchedTerms().contains(searchString)).isTrue();
|
||||
}
|
||||
|
||||
/*
|
||||
* Filename contains hyphen and searchString contains complete filename within quotes
|
||||
*/
|
||||
@Test
|
||||
public void testFilenameWithHyphenWholeFilenameSearchWithQuotes() throws IOException {
|
||||
// Arrange
|
||||
ClassPathResource textResource = new ClassPathResource("files/Text.json");
|
||||
Text text = objectMapper.readValue(textResource.getInputStream(), Text.class);
|
||||
String fileName = "luke-skywalker-42.pdf";
|
||||
String matchedString = fileName;
|
||||
String searchString = "\"" + matchedString + "\"";
|
||||
documentIndexService.indexDocument("template1", "dossierId1", "fileId1", fileName, text);
|
||||
|
||||
// Act
|
||||
SearchResult result = searchService.search(searchString, null, Arrays.asList("dossierId1"), null, 1, 10, true);
|
||||
|
||||
// Assert
|
||||
assertThat(result.getMatchedDocuments().size()).isEqualTo(1);
|
||||
assertThat(result.getMatchedDocuments().get(0).getMatchedTerms().size()).isGreaterThan(0);
|
||||
assertThat(result.getMatchedDocuments().get(0).getMatchedTerms().contains(matchedString)).isTrue();
|
||||
}
|
||||
|
||||
/*
|
||||
* Filename contains hyphen and searchString contains part of filename within quotes
|
||||
*/
|
||||
@Test
|
||||
public void testFilenameWithHyphenOneWordSearchWithQuotes() throws IOException {
|
||||
// Arrange
|
||||
ClassPathResource textResource = new ClassPathResource("files/Text.json");
|
||||
Text text = objectMapper.readValue(textResource.getInputStream(), Text.class);
|
||||
String fileName = "luke-skywalker-42.pdf";
|
||||
String matchedString = "luke";
|
||||
String searchString = "\"" + matchedString + "\"";
|
||||
documentIndexService.indexDocument("template1", "dossierId1", "fileId1", fileName, text);
|
||||
|
||||
// Act
|
||||
SearchResult result = searchService.search(searchString, null, Arrays.asList("dossierId1"), null, 1, 10, true);
|
||||
|
||||
// Assert
|
||||
assertThat(result.getMatchedDocuments().size()).isEqualTo(1);
|
||||
assertThat(result.getMatchedDocuments().get(0).getMatchedTerms().size()).isGreaterThan(0);
|
||||
assertThat(result.getMatchedDocuments().get(0).getMatchedTerms().contains(matchedString)).isTrue();
|
||||
}
|
||||
|
||||
/*
|
||||
* Filename contains hyphen and searchString contains filename without file ending within quotes
|
||||
*/
|
||||
@Test
|
||||
public void testFilenameWithHyphenWithoutFileEndingWithQuotes() throws IOException {
|
||||
// Arrange
|
||||
ClassPathResource textResource = new ClassPathResource("files/Text.json");
|
||||
Text text = objectMapper.readValue(textResource.getInputStream(), Text.class);
|
||||
String fileName = "luke-skywalker-42.pdf";
|
||||
String matchedString = "luke-skywalker-42";
|
||||
String searchString = "\"luke-skywalker-42\"";
|
||||
documentIndexService.indexDocument("template1", "dossierId1", "fileId1", fileName, text);
|
||||
|
||||
// Act
|
||||
SearchResult result = searchService.search(searchString, null, Arrays.asList("dossierId1"), null, 1, 10, true);
|
||||
|
||||
// Assert
|
||||
assertThat(result.getMatchedDocuments().size()).isEqualTo(1);
|
||||
assertThat(result.getMatchedDocuments().get(0).getMatchedTerms().size()).isGreaterThan(0);
|
||||
assertThat(result.getMatchedDocuments().get(0).getMatchedTerms().contains(matchedString)).isTrue();
|
||||
}
|
||||
|
||||
/*
|
||||
* Filename contains hyphen & blank and searchString contains complete filename within quotes
|
||||
*/
|
||||
@Test
|
||||
public void testFilenameWithHyphenAndBlankWholeFilenameSearchWithQuotes() throws IOException {
|
||||
// Arrange
|
||||
ClassPathResource textResource = new ClassPathResource("files/Text.json");
|
||||
Text text = objectMapper.readValue(textResource.getInputStream(), Text.class);
|
||||
String fileName = "luke-blankwalker 42.pdf";
|
||||
String matchedString = fileName;
|
||||
String searchString = "\"" + matchedString + "\"";
|
||||
documentIndexService.indexDocument("template1", "dossierId1", "fileId1", fileName, text);
|
||||
|
||||
// Act
|
||||
SearchResult result = searchService.search(searchString, null, Arrays.asList("dossierId1"), null, 1, 10, true);
|
||||
|
||||
// Assert
|
||||
assertThat(result.getMatchedDocuments().size()).isEqualTo(1);
|
||||
assertThat(result.getMatchedDocuments().get(0).getMatchedTerms().size()).isGreaterThan(0);
|
||||
assertThat(result.getMatchedDocuments().get(0).getMatchedTerms().contains(matchedString)).isTrue();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user