From f56bf5b9d06c9d582e58f6861e37777d5bc213e9 Mon Sep 17 00:00:00 2001 From: Shalin Shekhar Mangar Date: Sun, 1 Dec 2013 15:06:42 +0000 Subject: [PATCH] SOLR-5204: StatsComponent and SpellCheckComponent do not support the shards.tolerant=true parameter git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1546819 13f79535-47bb-0310-9956-ffa450edef68 --- solr/CHANGES.txt | 3 +++ .../component/SpellCheckComponent.java | 11 +++++++- .../handler/component/StatsComponent.java | 11 +++++++- .../apache/solr/TestDistributedSearch.java | 25 +++++++++++++++++-- 4 files changed, 46 insertions(+), 4 deletions(-) diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index d215aebecad..29b43f45b8a 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -169,6 +169,9 @@ Bug Fixes * SOLR-5515: NPE when getting stats on date field with empty result on SolrCloud. (Alexander Sagen, shalin) +* SOLR-5204: StatsComponent and SpellCheckComponent do not support the + shards.tolerant=true parameter. (Anca Kopetz, shalin) + Optimizations ---------------------- diff --git a/solr/core/src/java/org/apache/solr/handler/component/SpellCheckComponent.java b/solr/core/src/java/org/apache/solr/handler/component/SpellCheckComponent.java index 35a6c66592f..a2c609e3a9f 100644 --- a/solr/core/src/java/org/apache/solr/handler/component/SpellCheckComponent.java +++ b/solr/core/src/java/org/apache/solr/handler/component/SpellCheckComponent.java @@ -320,7 +320,16 @@ public class SpellCheckComponent extends SearchComponent implements SolrCoreAwar if (maxResultsForSuggest==null || !isCorrectlySpelled) { for (ShardRequest sreq : rb.finished) { for (ShardResponse srsp : sreq.responses) { - NamedList nl = (NamedList) srsp.getSolrResponse().getResponse().get("spellcheck"); + NamedList nl = null; + try { + nl = (NamedList) srsp.getSolrResponse().getResponse().get("spellcheck"); + } catch (Exception e) { + if (rb.req.getParams().getBool(ShardParams.SHARDS_TOLERANT, false)) { + continue; // looks like a shard did not return anything + } + throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, + "Unable to read spelling info for shard: " + srsp.getShard(), e); + } LOG.info(srsp.getShard() + " " + nl); if (nl != null) { mergeData.totalNumberShardResponses++; diff --git a/solr/core/src/java/org/apache/solr/handler/component/StatsComponent.java b/solr/core/src/java/org/apache/solr/handler/component/StatsComponent.java index 3af0f62e5b8..34601804370 100644 --- a/solr/core/src/java/org/apache/solr/handler/component/StatsComponent.java +++ b/solr/core/src/java/org/apache/solr/handler/component/StatsComponent.java @@ -102,7 +102,16 @@ public class StatsComponent extends SearchComponent { StatsInfo si = rb._statsInfo; for (ShardResponse srsp : sreq.responses) { - NamedList stats = (NamedList) srsp.getSolrResponse().getResponse().get("stats"); + NamedList stats = null; + try { + stats = (NamedList) srsp.getSolrResponse().getResponse().get("stats"); + } catch (Exception e) { + if (rb.req.getParams().getBool(ShardParams.SHARDS_TOLERANT, false)) { + continue; // looks like a shard did not return anything + } + throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, + "Unable to read stats info for shard: " + srsp.getShard(), e); + } NamedList stats_fields = (NamedList) stats.get("stats_fields"); if (stats_fields != null) { diff --git a/solr/core/src/test/org/apache/solr/TestDistributedSearch.java b/solr/core/src/test/org/apache/solr/TestDistributedSearch.java index 2c6f0232f46..d0887f4f7c8 100644 --- a/solr/core/src/test/org/apache/solr/TestDistributedSearch.java +++ b/solr/core/src/test/org/apache/solr/TestDistributedSearch.java @@ -105,6 +105,8 @@ public class TestDistributedSearch extends BaseDistributedSearchTestCase { t1,"no eggs on wall, lesson learned", oddField, "odd man out"); + indexr(id, "1001", "lowerfilt", "toyota"); // for spellcheck + indexr(id, 14, "SubjectTerms_mfacet", new String[] {"mathematical models", "mathematical analysis"}); indexr(id, 15, "SubjectTerms_mfacet", new String[] {"test 1", "test 2", "test3"}); indexr(id, 16, "SubjectTerms_mfacet", new String[] {"test 1", "test 2", "test3"}); @@ -227,6 +229,9 @@ public class TestDistributedSearch extends BaseDistributedSearchTestCase { query("q","*:*", "fl", "id", "fl",nint, "fl",tint,"sort",i1 + " desc"); query("q","*:*", "fl",nint, "fl", "id", "fl",tint,"sort",i1 + " desc"); + // basic spellcheck testing + query("q", "toyata", "fl", "id,lowerfilt", "spellcheck", true, "spellcheck.q", "toyata", "qt", "spellCheckCompRH_Direct", "shards.qt", "spellCheckCompRH_Direct"); + stress=0; // turn off stress... we want to tex max combos in min time for (int i=0; i<25*RANDOM_MULTIPLIER; i++) { String f = fieldNames[random().nextInt(fieldNames.length)]; @@ -336,7 +341,7 @@ public class TestDistributedSearch extends BaseDistributedSearchTestCase { assertNotNull("missing shard info", sinfo); assertEquals("should have an entry for each shard ["+sinfo+"] "+shards, cnt, sinfo.size()); - + // test shards.tolerant=true for(int numDownServers = 0; numDownServers < jettys.size()-1; numDownServers++) { @@ -383,6 +388,22 @@ public class TestDistributedSearch extends BaseDistributedSearchTestCase { ShardParams.SHARDS_INFO, "true", ShardParams.SHARDS_TOLERANT, "true"); + queryPartialResults(upShards, upClients, + "q", "*:*", + "stats", "true", + "stats.field", i1, + ShardParams.SHARDS_INFO, "true", + ShardParams.SHARDS_TOLERANT, "true"); + + queryPartialResults(upShards, upClients, + "q", "toyata", + "spellcheck", "true", + "spellcheck.q", "toyata", + "qt", "spellCheckCompRH_Direct", + "shards.qt", "spellCheckCompRH_Direct", + ShardParams.SHARDS_INFO, "true", + ShardParams.SHARDS_TOLERANT, "true"); + // restart the jettys for (JettySolrRunner downJetty : downJettys) { downJetty.start(); @@ -409,7 +430,7 @@ public class TestDistributedSearch extends BaseDistributedSearchTestCase { } } - protected void queryPartialResults(final List upShards, + protected void queryPartialResults(final List upShards, final List upClients, Object... q) throws Exception {