From 13347bd3bcfe124fa220d00db3efe1bd96b5c701 Mon Sep 17 00:00:00 2001 From: Koji Sekiguchi Date: Sat, 30 Jul 2011 11:35:55 +0000 Subject: [PATCH] SOLR-2682: remove addException() from SimpleFacet git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1152456 13f79535-47bb-0310-9956-ffa450edef68 --- solr/CHANGES.txt | 7 +- .../org/apache/solr/request/SimpleFacets.java | 72 +++++-------------- 2 files changed, 25 insertions(+), 54 deletions(-) diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index 1dda7847d24..e6316b30910 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -52,7 +52,9 @@ Upgrading from Solr 3.3-dev If q.op is effectively "OR" then mm=0%. Users who wish to force the legacy behavior should set a default value for the 'mm' param in their solrconfig.xml file. - + +* FacetComponent no longer catches and embeds exceptions occurred during facet + processing, it throws HTTP 400 or 500 exceptions instead. Detailed Change List ---------------------- @@ -212,6 +214,9 @@ Bug Fixes * SOLR-2193, SOLR-2565, SOLR-2651: SolrCores now properly share IndexWriters across SolrCore reloads. (Mark Miller, Robert Muir) + +* SOLR-2682: Remove addException() in SimpleFacet. FacetComponent no longer catches and embeds + exceptions occurred during facet processing, it throws HTTP 400 or 500 exceptions instead. (koji) Other Changes ---------------------- diff --git a/solr/core/src/java/org/apache/solr/request/SimpleFacets.java b/solr/core/src/java/org/apache/solr/request/SimpleFacets.java index 7fa02eeb77c..d6cedaaada3 100644 --- a/solr/core/src/java/org/apache/solr/request/SimpleFacets.java +++ b/solr/core/src/java/org/apache/solr/request/SimpleFacets.java @@ -28,6 +28,7 @@ import org.apache.lucene.util.packed.Direct32; import org.apache.lucene.util.packed.Direct8; import org.apache.lucene.util.packed.PackedInts; import org.apache.solr.common.SolrException; +import org.apache.solr.common.SolrException.ErrorCode; import org.apache.solr.common.params.FacetParams; import org.apache.solr.common.params.RequiredSolrParams; import org.apache.solr.common.params.SolrParams; @@ -191,26 +192,16 @@ public class SimpleFacets { facetResponse.add("facet_dates", getFacetDateCounts()); facetResponse.add("facet_ranges", getFacetRangeCounts()); - } catch (Exception e) { + } catch (IOException e) { SolrException.logOnce(SolrCore.log, "Exception during facet counts", e); - addException("Exception during facet counts", e); + throw new SolrException(ErrorCode.SERVER_ERROR, e); + } catch (ParseException e) { + SolrException.logOnce(SolrCore.log, "Exception during facet counts", e); + throw new SolrException(ErrorCode.BAD_REQUEST, e); } return facetResponse; } - public void addException(String msg, Exception e) { - @SuppressWarnings("unchecked") - List exceptions = (List)facetResponse.get("exception"); - - if (exceptions == null) { - exceptions = new ArrayList(); - facetResponse.add("exception", exceptions); - } - - String entry = msg + '\n' + SolrException.toStr(e); - exceptions.add(entry); - } - /** * Returns a list of facet counts for each of the facet queries * specified in the params @@ -232,18 +223,11 @@ public class SimpleFacets { if (null != facetQs && 0 != facetQs.length) { for (String q : facetQs) { - try { - parseParams(FacetParams.FACET_QUERY, q); + parseParams(FacetParams.FACET_QUERY, q); - // TODO: slight optimization would prevent double-parsing of any localParams - Query qobj = QParser.getParser(q, null, req).getQuery(); - res.add(key, searcher.numDocs(qobj, base)); - } - catch (Exception e) { - String msg = "Exception during facet.query of " + q; - SolrException.logOnce(SolrCore.log, msg, e); - addException(msg , e); - } + // TODO: slight optimization would prevent double-parsing of any localParams + Query qobj = QParser.getParser(q, null, req).getQuery(); + res.add(key, searcher.numDocs(qobj, base)); } } @@ -347,18 +331,12 @@ public class SimpleFacets { String[] facetFs = params.getParams(FacetParams.FACET_FIELD); if (null != facetFs) { for (String f : facetFs) { - try { - parseParams(FacetParams.FACET_FIELD, f); - String termList = localParams == null ? null : localParams.get(CommonParams.TERMS); - if (termList != null) { - res.add(key, getListedTermCounts(facetValue, termList)); - } else { - res.add(key, getTermCounts(facetValue)); - } - } catch (Exception e) { - String msg = "Exception during facet.field of " + f; - SolrException.logOnce(SolrCore.log, msg, e); - addException(msg , e); + parseParams(FacetParams.FACET_FIELD, f); + String termList = localParams == null ? null : localParams.get(CommonParams.TERMS); + if (termList != null) { + res.add(key, getListedTermCounts(facetValue, termList)); + } else { + res.add(key, getTermCounts(facetValue)); } } } @@ -780,13 +758,7 @@ public class SimpleFacets { if (null == fields || 0 == fields.length) return resOuter; for (String f : fields) { - try { - getFacetDateCounts(f, resOuter); - } catch (Exception e) { - String msg = "Exception during facet.date of " + f; - SolrException.logOnce(SolrCore.log, msg, e); - addException(msg , e); - } + getFacetDateCounts(f, resOuter); } return resOuter; @@ -955,20 +927,14 @@ public class SimpleFacets { * @see FacetParams#FACET_RANGE */ - public NamedList getFacetRangeCounts() { + public NamedList getFacetRangeCounts() throws IOException, ParseException { final NamedList resOuter = new SimpleOrderedMap(); final String[] fields = params.getParams(FacetParams.FACET_RANGE); if (null == fields || 0 == fields.length) return resOuter; for (String f : fields) { - try { - getFacetRangeCounts(f, resOuter); - } catch (Exception e) { - String msg = "Exception during facet.range of " + f; - SolrException.logOnce(SolrCore.log, msg, e); - addException(msg , e); - } + getFacetRangeCounts(f, resOuter); } return resOuter;