RED-2175 Added test with search string containing hyphen

This commit is contained in:
Philipp Schramm 2021-10-12 14:15:05 +02:00
parent a99824067b
commit ab192f8703

View File

@ -42,6 +42,7 @@ public class IndexCreatorTest extends AbstractElasticsearchIntegrationTest {
@MockBean
private FileStatusProcessingUpdateClient fileStatusProcessingUpdateClient;
/*
* Index two documents and delete one
*/
@ -82,6 +83,7 @@ public class IndexCreatorTest extends AbstractElasticsearchIntegrationTest {
}
/*
* SearchService will not find any result
*/
@ -124,26 +126,6 @@ public class IndexCreatorTest extends AbstractElasticsearchIntegrationTest {
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
@ -167,6 +149,7 @@ public class IndexCreatorTest extends AbstractElasticsearchIntegrationTest {
assertThat(result.getMatchedDocuments().get(0).getMatchedTerms().contains("42.pdf")).isTrue();
}
/*
* Filename contains hyphen and searchString contains one word from filename
*/
@ -188,6 +171,7 @@ public class IndexCreatorTest extends AbstractElasticsearchIntegrationTest {
assertThat(result.getMatchedDocuments().get(0).getMatchedTerms().contains(searchString)).isTrue();
}
/*
* Filename contains hyphen and searchString contains filename without file ending
*/
@ -209,6 +193,7 @@ public class IndexCreatorTest extends AbstractElasticsearchIntegrationTest {
assertThat(result.getMatchedDocuments().get(0).getMatchedTerms().contains(searchString)).isTrue();
}
/*
* Filename contains hyphen and searchString contains complete filename within quotes
*/
@ -231,6 +216,7 @@ public class IndexCreatorTest extends AbstractElasticsearchIntegrationTest {
assertThat(result.getMatchedDocuments().get(0).getMatchedTerms().contains(matchedString)).isTrue();
}
/*
* Filename contains hyphen and searchString contains part of filename within quotes
*/
@ -253,6 +239,7 @@ public class IndexCreatorTest extends AbstractElasticsearchIntegrationTest {
assertThat(result.getMatchedDocuments().get(0).getMatchedTerms().contains(matchedString)).isTrue();
}
/*
* Filename contains hyphen and searchString contains filename without file ending within quotes
*/
@ -275,6 +262,7 @@ public class IndexCreatorTest extends AbstractElasticsearchIntegrationTest {
assertThat(result.getMatchedDocuments().get(0).getMatchedTerms().contains(matchedString)).isTrue();
}
/*
* Filename contains hyphen & blank and searchString contains complete filename within quotes
*/
@ -297,34 +285,35 @@ public class IndexCreatorTest extends AbstractElasticsearchIntegrationTest {
assertThat(result.getMatchedDocuments().get(0).getMatchedTerms().contains(matchedString)).isTrue();
}
/*
* XXX
* Search string with hyphen
*/
@Test
public void testXXX() throws IOException {
public void testSearchStringWithHyphen() 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 = "[14C]-SDS-46851";
String searchString = "14C]-SDS-46851";
documentIndexService.indexDocument("template1", "dossierId1", "fileId1", fileName, text);
// Act
SearchResult result = searchService.search(searchString, null, Arrays.asList("dossierId1"), null, 1, 10, true);
// XXX Remove them
System.out.println(result.getMatchedDocuments().size());
System.out.println(result.getMatchedDocuments().get(0).getMatchedTerms());
System.out.println(result.getMatchedDocuments().get(0).getHighlights().get("sections.text"));
System.out.println(result.getMatchedDocuments().get(0).getHighlights().get("sections.text").size());
System.out.println(result.getMatchedDocuments().get(0).getHighlights().get("sections.text").toArray()[0]);
System.out.println(StringUtils.contains(result.getMatchedDocuments().get(0).getHighlights().get("sections.text").toArray()[0].toString(), searchString));
// 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(); // XXX not really working OR?
assertThat(result.getMatchedDocuments()
.get(0)
.getMatchedTerms()
.contains(searchString)).isTrue();
assertThat(result.getMatchedDocuments().get(0).getHighlights().get("sections.text").size()).isGreaterThan(0);
assertThat(StringUtils.contains(result.getMatchedDocuments()
.get(0)
.getHighlights()
.get("sections.text")
.toArray()[0].toString(), searchString)).isTrue();
}
}