|
| 1 | +package org.mycore.mir.it.tests; |
| 2 | + |
| 3 | +import java.io.IOException; |
| 4 | +import java.util.Arrays; |
| 5 | +import java.util.Collection; |
| 6 | +import java.util.List; |
| 7 | +import java.util.Optional; |
| 8 | +import java.util.stream.Collectors; |
| 9 | + |
| 10 | +import org.junit.Assert; |
| 11 | +import org.junit.Before; |
| 12 | +import org.junit.Test; |
| 13 | +import org.junit.runner.RunWith; |
| 14 | +import org.junit.runners.Parameterized; |
| 15 | +import org.mycore.mir.it.controller.MIRSearchController; |
| 16 | +import org.mycore.mir.it.model.MIRComplexSearchQuery; |
| 17 | +import org.mycore.mir.it.model.MIRSearchField; |
| 18 | +import org.mycore.mir.it.model.MIRSearchFieldCondition; |
| 19 | +import org.mycore.mir.it.model.MIRSearchTestDataLoader; |
| 20 | +import org.openqa.selenium.By; |
| 21 | + |
| 22 | +/** |
| 23 | + * Integration tests for language-specific Solr fields. |
| 24 | + * <p> |
| 25 | + * Each test document contains a title and abstract in a specific language using a <b>plural or inflected</b> |
| 26 | + * word form. The test searches with the <b>singular or base</b> form. A match proves that the language-specific |
| 27 | + * stemmer is working correctly, since {@code text_general} (without stemming) would not match. |
| 28 | + * </p> |
| 29 | + * <p> |
| 30 | + * Stemming proof per language: |
| 31 | + * </p> |
| 32 | + * <ul> |
| 33 | + * <li><b>de:</b> "Bibliotheken" (plural) vs. search "Bibliothek" (singular) — GermanLightStemFilterFactory</li> |
| 34 | + * <li><b>en:</b> "Libraries" (plural) vs. search "Library" (singular) — PorterStemFilterFactory</li> |
| 35 | + * <li><b>es:</b> "bibliotecas" (plural) vs. search "biblioteca" (singular) — SpanishLightStemFilterFactory</li> |
| 36 | + * <li><b>fr:</b> "bibliothèques" (plural) vs. search "bibliothèque" (singular) — FrenchLightStemFilterFactory</li> |
| 37 | + * <li><b>it:</b> "biblioteche" (plural) vs. search "biblioteca" (singular) — ItalianLightStemFilterFactory</li> |
| 38 | + * <li><b>ru:</b> "библиотек" (genitive plural) vs. search "библиотека" (nominative) — RussianLightStemFilterFactory</li> |
| 39 | + * <li><b>tr:</b> "araştırmalar" (plural) vs. search "araştırma" (singular) — SnowballPorterFilterFactory (Turkish)</li> |
| 40 | + * </ul> |
| 41 | + * |
| 42 | + * <p>These tests require both the MCR and MIR tickets to be implemented:</p> |
| 43 | + * <ul> |
| 44 | + * <li>MCR: Language-specific Solr field types and MODS indexing XSLT</li> |
| 45 | + * <li>MIR: Search forms updated to query language-specific fields</li> |
| 46 | + * </ul> |
| 47 | + */ |
| 48 | +@RunWith(Parameterized.class) |
| 49 | +public class MIRLanguageSearchITCase extends MIRITBase { |
| 50 | + |
| 51 | + private final String language; |
| 52 | + |
| 53 | + private final String expectedDocId; |
| 54 | + |
| 55 | + private final String titleSearchTerm; |
| 56 | + |
| 57 | + private final String abstractSearchTerm; |
| 58 | + |
| 59 | + public MIRLanguageSearchITCase(String language, String expectedDocId, |
| 60 | + String titleSearchTerm, String abstractSearchTerm) { |
| 61 | + this.language = language; |
| 62 | + this.expectedDocId = expectedDocId; |
| 63 | + this.titleSearchTerm = titleSearchTerm; |
| 64 | + this.abstractSearchTerm = abstractSearchTerm; |
| 65 | + } |
| 66 | + |
| 67 | + /** |
| 68 | + * Test parameters: language, document ID, stemmed title search term, stemmed abstract search term. |
| 69 | + * The search term is always a different word form than what is stored in the document. |
| 70 | + */ |
| 71 | + @Parameterized.Parameters(name = "{0}") |
| 72 | + public static Collection<Object[]> data() { |
| 73 | + return Arrays.asList(new Object[][] { |
| 74 | + // { language, docId, title search (singular/base), abstract search (singular/base) } |
| 75 | + { "de", "mir_mods_00010001", "Bibliothek", "Publikation" }, |
| 76 | + { "en", "mir_mods_00010002", "Library", "publication" }, |
| 77 | + { "es", "mir_mods_00010003", "biblioteca", "publicación" }, |
| 78 | + { "fr", "mir_mods_00010004", "bibliothèque", "publication" }, |
| 79 | + { "it", "mir_mods_00010005", "biblioteca", "pubblicazione" }, |
| 80 | + { "ru", "mir_mods_00010006", "\u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430", |
| 81 | + "\u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u044f" }, |
| 82 | + { "tr", "mir_mods_00010007", "araştırma", "araç" }, |
| 83 | + }); |
| 84 | + } |
| 85 | + |
| 86 | + @Before |
| 87 | + public final void init() throws IOException, InterruptedException { |
| 88 | + MIRSearchTestDataLoader searchTestDataLoader = new MIRSearchTestDataLoader(); |
| 89 | + searchTestDataLoader.lazyLoadData(getDriver()); |
| 90 | + // navigate to start page so the "Suche" nav link is available |
| 91 | + getDriver().get(getAPPUrlString()); |
| 92 | + } |
| 93 | + |
| 94 | + /** |
| 95 | + * Tests that language-specific title stemming works via the simple search form. |
| 96 | + * Searches with the base/singular form of a word that appears in plural/inflected form in the title. |
| 97 | + */ |
| 98 | + @Test |
| 99 | + public void testTitleStemming() { |
| 100 | + MIRSearchController searchController = new MIRSearchController(getDriver(), getAPPUrlString()); |
| 101 | + searchController.setTitle(titleSearchTerm); |
| 102 | + |
| 103 | + List<String> foundIds = collectResultIds(); |
| 104 | + |
| 105 | + Assert.assertTrue( |
| 106 | + "Language [" + language + "]: title search for '" + titleSearchTerm |
| 107 | + + "' should find " + expectedDocId + " (found: " + String.join(",", foundIds) + ")", |
| 108 | + foundIds.contains(expectedDocId)); |
| 109 | + } |
| 110 | + |
| 111 | + /** |
| 112 | + * Tests that language-specific abstract stemming works via the complex search form. |
| 113 | + * Uses the "Metadaten" (allMeta) field since there is no dedicated abstract field in the current form. |
| 114 | + * Searches with the base/singular form of a word that appears in plural/inflected form in the abstract. |
| 115 | + */ |
| 116 | + @Test |
| 117 | + public void testAbstractStemming() { |
| 118 | + MIRSearchController searchController = new MIRSearchController(getDriver(), getAPPUrlString()); |
| 119 | + |
| 120 | + List<MIRComplexSearchQuery> queries = List.of( |
| 121 | + new MIRComplexSearchQuery(MIRSearchFieldCondition.enthält, abstractSearchTerm, |
| 122 | + MIRSearchField.Metadaten)); |
| 123 | + |
| 124 | + searchController.complexSearchBy(queries, null, null, null, |
| 125 | + null, null, null, null, null); |
| 126 | + |
| 127 | + List<String> foundIds = collectResultIds(); |
| 128 | + |
| 129 | + Assert.assertTrue( |
| 130 | + "Language [" + language + "]: abstract search for '" + abstractSearchTerm |
| 131 | + + "' should find " + expectedDocId + " (found: " + String.join(",", foundIds) + ")", |
| 132 | + foundIds.contains(expectedDocId)); |
| 133 | + } |
| 134 | + |
| 135 | + private List<String> collectResultIds() { |
| 136 | + return getDriver().waitAndFindElements(By.xpath(".//input[@name='id']")) |
| 137 | + .stream() |
| 138 | + .map(v -> Optional.ofNullable(v.getDomProperty("value")) |
| 139 | + .orElseGet(() -> v.getDomAttribute("value"))) |
| 140 | + .collect(Collectors.toList()); |
| 141 | + } |
| 142 | +} |
0 commit comments