From d9f47b3538d8f7a9f8fce1099391cb881388657d Mon Sep 17 00:00:00 2001 From: Jon Bratseth Date: Tue, 23 Oct 2018 11:32:49 +0200 Subject: Allow conflicting aliases across document types --- .../main/java/com/yahoo/prelude/IndexModel.java | 14 ++++++-- .../com/yahoo/prelude/test/IndexFactsTestCase.java | 40 +++++++++------------- 2 files changed, 28 insertions(+), 26 deletions(-) diff --git a/container-search/src/main/java/com/yahoo/prelude/IndexModel.java b/container-search/src/main/java/com/yahoo/prelude/IndexModel.java index 45214d4d3df..d2950078868 100644 --- a/container-search/src/main/java/com/yahoo/prelude/IndexModel.java +++ b/container-search/src/main/java/com/yahoo/prelude/IndexModel.java @@ -7,6 +7,7 @@ import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.logging.Logger; import java.util.stream.Collectors; import com.yahoo.search.config.IndexInfoConfig; @@ -20,6 +21,8 @@ import com.yahoo.container.QrSearchersConfig; */ public final class IndexModel { + private static final Logger log = Logger.getLogger(IndexModel.class.getName()); + // Copied from MasterClustersInfoUpdater. It's a temporary workaround for IndexFacts private Map> masterClusters; private Map searchDefinitions; @@ -112,8 +115,15 @@ public final class IndexModel { union.getOrCreateIndex(index.getName()); for (String command : index.allCommands()) union.addCommand(index.getName(), command); - for (String alias : index.aliases()) - union.addAlias(alias, index.getName()); + for (String alias : index.aliases()) { + try { + union.addAlias(alias, index.getName()); + } + catch (IllegalArgumentException e) { + log.fine("Conflicting alias '" + alias + " of " + index + " in " + sd + + " will not take effect for queries which does not specify that search definition"); + } + } } } diff --git a/container-search/src/test/java/com/yahoo/prelude/test/IndexFactsTestCase.java b/container-search/src/test/java/com/yahoo/prelude/test/IndexFactsTestCase.java index 88c06635520..e3a5ce76ffb 100644 --- a/container-search/src/test/java/com/yahoo/prelude/test/IndexFactsTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/test/IndexFactsTestCase.java @@ -244,30 +244,6 @@ public class IndexFactsTestCase { assertTrue(session.getIndex("e").isExact()); } - @Test - public void testOverlappingAliases() { - IndexInfoConfig cfg = new IndexInfoConfig(new IndexInfoConfig.Builder() - .indexinfo( - new Indexinfo.Builder() - .name("music2") - .command( - new Command.Builder().indexname( - "btitle").command("index")) - .alias(new Alias.Builder().alias("title") - .indexname("btitle"))).indexinfo( - new Indexinfo.Builder().name("music").command( - new Command.Builder().indexname("title") - .command("index")))); - try { - new IndexModel(cfg, (QrSearchersConfig) null); - fail("Excepted exception"); // (This is validated at deploy time) - } - catch (IllegalArgumentException e) { - assertEquals("Tried adding the alias 'title' for the index name 'btitle' when the name 'title' already maps to 'title'", - e.getMessage()); - } - } - private Query newQuery(String queryString, IndexFacts indexFacts) { Query query = new Query(queryString); query.getModel().setExecution(new Execution(new Execution.Context(null, indexFacts, null, null, null))); @@ -329,5 +305,21 @@ public class IndexFactsTestCase { assertEquals("url:\"https foo bar\"", query1.getModel().getQueryTree().toString()); assertEquals("url:\"https foo bar\"", query2.getModel().getQueryTree().toString()); } + + @Test + public void testConflictingAliases() { + SearchDefinition first = new SearchDefinition("first"); + Index field1 = new Index("field1"); + first.addIndex(field1); + + SearchDefinition second = new SearchDefinition("second"); + Index field2 = new Index("field2"); + field2.addAlias("field1"); + second.addIndex(field2); + + // Alias to field1 conflics with field1 in the "union" search definition. + // Should not produce an exception (but a log message): + new IndexFacts(new IndexModel(Collections.emptyMap(), ImmutableList.of(first, second))); + } } -- cgit v1.2.3