aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@oath.com>2018-10-23 11:43:58 +0200
committerGitHub <noreply@github.com>2018-10-23 11:43:58 +0200
commit123c5a40b52018090a9a7d36ab2699b85bd12328 (patch)
treed729506edc3fbff972d5ffec19ac1346bf0b6baf
parent46546965f885ef1b9b2597d665329b9e36e31d69 (diff)
parentd9f47b3538d8f7a9f8fce1099391cb881388657d (diff)
Merge pull request #7415 from vespa-engine/bratseth/allow-conflicting-aliases
Allow conflicting aliases across document types
-rw-r--r--container-search/src/main/java/com/yahoo/prelude/IndexModel.java14
-rw-r--r--container-search/src/test/java/com/yahoo/prelude/test/IndexFactsTestCase.java40
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<String, List<String>> masterClusters;
private Map<String, SearchDefinition> 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)));
+ }
}