diff options
Diffstat (limited to 'container-search')
43 files changed, 265 insertions, 158 deletions
diff --git a/container-search/src/main/java/com/yahoo/prelude/cluster/ClusterSearcher.java b/container-search/src/main/java/com/yahoo/prelude/cluster/ClusterSearcher.java index 5111c601c6d..ca1afbd4171 100644 --- a/container-search/src/main/java/com/yahoo/prelude/cluster/ClusterSearcher.java +++ b/container-search/src/main/java/com/yahoo/prelude/cluster/ClusterSearcher.java @@ -364,12 +364,12 @@ public class ClusterSearcher extends Searcher { doFill(searcher, result, summaryClass, execution); } else { if (result.hits().getErrorHit() == null) { - result.hits().setError(ErrorMessage.createTimeout("No time left to get summaries")); + result.hits().addError(ErrorMessage.createTimeout("No time left to get summaries")); } } } else { if (result.hits().getErrorHit() == null) { - result.hits().setError(ErrorMessage.createNoBackendsInService("Could not fill result")); + result.hits().addError(ErrorMessage.createNoBackendsInService("Could not fill result")); } } // no error: good result, let's return diff --git a/container-search/src/main/java/com/yahoo/prelude/fastsearch/VespaBackEndSearcher.java b/container-search/src/main/java/com/yahoo/prelude/fastsearch/VespaBackEndSearcher.java index 1a7e693caa7..05e306a7dec 100644 --- a/container-search/src/main/java/com/yahoo/prelude/fastsearch/VespaBackEndSearcher.java +++ b/container-search/src/main/java/com/yahoo/prelude/fastsearch/VespaBackEndSearcher.java @@ -300,7 +300,7 @@ public abstract class VespaBackEndSearcher extends PingableSearcher { Result result = new Result(query); if (result.hits().getErrorHit() == null) { - result.hits().setError(ErrorMessage.createBackendCommunicationError( + result.hits().addError(ErrorMessage.createBackendCommunicationError( "Fast Search (" + getName() + ") failed: " + e.getMessage())); } if (query.getTraceLevel() >= 1) { diff --git a/container-search/src/main/java/com/yahoo/prelude/searcher/MultipleResultsSearcher.java b/container-search/src/main/java/com/yahoo/prelude/searcher/MultipleResultsSearcher.java index adcae24d9e6..c47af9e32da 100644 --- a/container-search/src/main/java/com/yahoo/prelude/searcher/MultipleResultsSearcher.java +++ b/container-search/src/main/java/com/yahoo/prelude/searcher/MultipleResultsSearcher.java @@ -43,7 +43,7 @@ public class MultipleResultsSearcher extends Searcher { return hitsRetriever.createMultipleResultSets(); } catch(ParameterException exception) { Result result = new Result(query); - result.hits().setError(ErrorMessage.createInvalidQueryParameter(exception.msg)); + result.hits().addError(ErrorMessage.createInvalidQueryParameter(exception.msg)); return result; } } diff --git a/container-search/src/main/java/com/yahoo/search/Result.java b/container-search/src/main/java/com/yahoo/search/Result.java index cb53246c7ad..ded8992fa65 100644 --- a/container-search/src/main/java/com/yahoo/search/Result.java +++ b/container-search/src/main/java/com/yahoo/search/Result.java @@ -81,7 +81,7 @@ public final class Result extends com.yahoo.processing.Response implements Clone /** Create a result containing an error */ public Result(Query query, ErrorMessage errorMessage) { this(query); - hits.setError(errorMessage); + hits.addError(errorMessage); } /** diff --git a/container-search/src/main/java/com/yahoo/search/federation/CommonFields.java b/container-search/src/main/java/com/yahoo/search/federation/CommonFields.java index 01e359cdcf9..119c4eb9e0a 100644 --- a/container-search/src/main/java/com/yahoo/search/federation/CommonFields.java +++ b/container-search/src/main/java/com/yahoo/search/federation/CommonFields.java @@ -2,9 +2,10 @@ package com.yahoo.search.federation; /** * A set of string constants for common hit field names. - * @author laboisse * + * @author laboisse */ +// TODO: Deprecate and remove public class CommonFields { public static final String TITLE = "title"; @@ -19,4 +20,5 @@ public class CommonFields { public static final String THUMBNAIL_URL = "thumbnailUrl"; public static final String THUMBNAIL_WIDTH = "thumbnailWidth"; public static final String THUMBNAIL_HEIGHT = "thumbnailHeight"; + } diff --git a/container-search/src/main/java/com/yahoo/search/federation/FederationSearcher.java b/container-search/src/main/java/com/yahoo/search/federation/FederationSearcher.java index 2d84a536da6..9034484b022 100644 --- a/container-search/src/main/java/com/yahoo/search/federation/FederationSearcher.java +++ b/container-search/src/main/java/com/yahoo/search/federation/FederationSearcher.java @@ -65,7 +65,7 @@ import static com.yahoo.search.federation.StrictContractsConfig.PropagateSourceP * This searcher takes a set of sources, looks them up in config and fire off the correct searchchains. * * @author Arne Bergene Fossaa - * @author tonytv + * @author Tony Vaagenes * @author bratseth */ @Provides(FederationSearcher.FEDERATION) diff --git a/container-search/src/main/java/com/yahoo/search/federation/vespa/QueryMarshaller.java b/container-search/src/main/java/com/yahoo/search/federation/vespa/QueryMarshaller.java index b0168315d28..2bfec008761 100644 --- a/container-search/src/main/java/com/yahoo/search/federation/vespa/QueryMarshaller.java +++ b/container-search/src/main/java/com/yahoo/search/federation/vespa/QueryMarshaller.java @@ -9,10 +9,11 @@ import com.yahoo.prelude.query.*; * Marshal a query stack into an advanced query string suitable for * passing to another QRS. * - * @author <a href="mailto:steinar@yahoo-inc.com">Steinar Knutsen</a> - * @author <a href="mailto:rafan@yahoo-inc.com">Rong-En Fan</a> + * @author Steinar Knutsen + * @author Rong-En Fan */ public class QueryMarshaller { + private boolean atRoot = true; public String marshal(Item root) { @@ -168,4 +169,5 @@ public class QueryMarshaller { s.append(" )"); } } + } diff --git a/container-search/src/main/java/com/yahoo/search/federation/vespa/ResultBuilder.java b/container-search/src/main/java/com/yahoo/search/federation/vespa/ResultBuilder.java index 4c7192f774b..71971b56ef1 100644 --- a/container-search/src/main/java/com/yahoo/search/federation/vespa/ResultBuilder.java +++ b/container-search/src/main/java/com/yahoo/search/federation/vespa/ResultBuilder.java @@ -29,10 +29,9 @@ import static com.yahoo.text.Lowercase.toLowerCase; /** * Parse Vespa XML results and create Result instances. * - * <p> TODO: Ripe for a rewrite or major refactoring. - * - * @author <a href="mailto:steinar@yahoo-inc.com">Steinar Knutsen</a> + * @author Steinar Knutsen */ +// Ripe for a rewrite or major refactoring. @SuppressWarnings("deprecation") public class ResultBuilder extends DefaultHandler { private static final String ERROR = "error"; @@ -509,7 +508,7 @@ public class ResultBuilder extends DefaultHandler { if (ERROR.equals(qName)) { ErrorMessage error = new ErrorMessage(Integer.valueOf(currentErrorCode), fieldContent.toString()); - hitGroups.peekFirst().setError(error); + hitGroups.peekFirst().addError(error); currentErrorCode = null; fieldContent = null; } diff --git a/container-search/src/main/java/com/yahoo/search/grouping/Continuation.java b/container-search/src/main/java/com/yahoo/search/grouping/Continuation.java index b9cf81786a4..e7f40b8b447 100644 --- a/container-search/src/main/java/com/yahoo/search/grouping/Continuation.java +++ b/container-search/src/main/java/com/yahoo/search/grouping/Continuation.java @@ -10,7 +10,7 @@ import com.yahoo.search.grouping.vespa.ContinuationDecoder; * * <p>To render a Cookie within a result set, you simply need to call {@link #toString()}.</p> * - * @author <a href="mailto:simon@yahoo-inc.com">Simon Thoresen</a> + * @author Simon Thoresen */ public abstract class Continuation { diff --git a/container-search/src/main/java/com/yahoo/search/grouping/GroupingQueryParser.java b/container-search/src/main/java/com/yahoo/search/grouping/GroupingQueryParser.java index 4a255462cbc..f3af9cf1fc7 100644 --- a/container-search/src/main/java/com/yahoo/search/grouping/GroupingQueryParser.java +++ b/container-search/src/main/java/com/yahoo/search/grouping/GroupingQueryParser.java @@ -19,7 +19,7 @@ import java.util.*; * also parse any "timezone" parameter as the timezone for time expressions such as {@link * com.yahoo.search.grouping.request.DayOfMonthFunction} and {@link com.yahoo.search.grouping.request.HourOfDayFunction}. * - * @author <a href="mailto:simon@yahoo-inc.com">Simon Thoresen</a> + * @author Simon Thoresen */ @After(PhaseNames.RAW_QUERY) @Before(PhaseNames.TRANSFORMED_QUERY) diff --git a/container-search/src/main/java/com/yahoo/search/grouping/GroupingValidator.java b/container-search/src/main/java/com/yahoo/search/grouping/GroupingValidator.java index cfe18595b74..b321915359f 100644 --- a/container-search/src/main/java/com/yahoo/search/grouping/GroupingValidator.java +++ b/container-search/src/main/java/com/yahoo/search/grouping/GroupingValidator.java @@ -28,7 +28,7 @@ import static com.yahoo.search.grouping.GroupingQueryParser.SELECT_PARAMETER_PAR * cluster for which this searcher has been deployed. This searcher uses exceptions to signal invalid grouping * requests. * - * @author <a href="mailto:simon@yahoo-inc.com">Simon Thoresen</a> + * @author Simon Thoresen */ @Before(PhaseNames.BACKEND) @After(SELECT_PARAMETER_PARSING) diff --git a/container-search/src/main/java/com/yahoo/search/grouping/UnavailableAttributeException.java b/container-search/src/main/java/com/yahoo/search/grouping/UnavailableAttributeException.java index 6fb6a7f772d..0669bcb3d60 100644 --- a/container-search/src/main/java/com/yahoo/search/grouping/UnavailableAttributeException.java +++ b/container-search/src/main/java/com/yahoo/search/grouping/UnavailableAttributeException.java @@ -5,7 +5,7 @@ package com.yahoo.search.grouping; * This exception is thrown by the {@link GroupingValidator} if it a {@link GroupingRequest} contains a reference to an * unavailable attribute. * - * @author <a href="mailto:simon@yahoo-inc.com">Simon Thoresen</a> + * @author Simon Thoresen */ @SuppressWarnings("serial") public class UnavailableAttributeException extends RuntimeException { diff --git a/container-search/src/main/java/com/yahoo/search/grouping/result/AbstractList.java b/container-search/src/main/java/com/yahoo/search/grouping/result/AbstractList.java index 2760b2b80e6..030a3c08cd6 100644 --- a/container-search/src/main/java/com/yahoo/search/grouping/result/AbstractList.java +++ b/container-search/src/main/java/com/yahoo/search/grouping/result/AbstractList.java @@ -9,7 +9,7 @@ import java.util.HashMap; import java.util.Map; /** - * @author <a href="mailto:simon@yahoo-inc.com">Simon Thoresen</a> + * @author Simon Thoresen */ public abstract class AbstractList extends HitGroup { @@ -44,4 +44,5 @@ public abstract class AbstractList extends HitGroup { public Map<String, Continuation> continuations() { return continuations; } + } diff --git a/container-search/src/main/java/com/yahoo/search/grouping/result/BucketGroupId.java b/container-search/src/main/java/com/yahoo/search/grouping/result/BucketGroupId.java index 32f10a5ed65..7ee55e85479 100644 --- a/container-search/src/main/java/com/yahoo/search/grouping/result/BucketGroupId.java +++ b/container-search/src/main/java/com/yahoo/search/grouping/result/BucketGroupId.java @@ -7,7 +7,7 @@ import static com.yahoo.text.Lowercase.toLowerCase; * This abstract class is used in {@link Group} instances where the identifying expression evaluated to a {@link * com.yahoo.search.grouping.request.BucketValue}. The range is inclusive-from and exclusive-to. * - * @author <a href="mailto:simon@yahoo-inc.com">Simon Thoresen</a> + * @author Simon Thoresen */ public abstract class BucketGroupId<T> extends GroupId { @@ -57,4 +57,5 @@ public abstract class BucketGroupId<T> extends GroupId { public T getTo() { return to; } + } diff --git a/container-search/src/main/java/com/yahoo/search/handler/HttpSearchResponse.java b/container-search/src/main/java/com/yahoo/search/handler/HttpSearchResponse.java index 8265dad782f..845b4d7249d 100644 --- a/container-search/src/main/java/com/yahoo/search/handler/HttpSearchResponse.java +++ b/container-search/src/main/java/com/yahoo/search/handler/HttpSearchResponse.java @@ -29,7 +29,7 @@ import com.yahoo.search.query.context.QueryContext; /** * Wrap the result of a query as an HTTP response. * - * @author <a href="mailto:steinar@yahoo-inc.com">Steinar Knutsen</a> + * @author Steinar Knutsen */ public class HttpSearchResponse extends ExtendedResponse { diff --git a/container-search/src/main/java/com/yahoo/search/handler/SearchHandler.java b/container-search/src/main/java/com/yahoo/search/handler/SearchHandler.java index 6d3b0351190..4161f814866 100644 --- a/container-search/src/main/java/com/yahoo/search/handler/SearchHandler.java +++ b/container-search/src/main/java/com/yahoo/search/handler/SearchHandler.java @@ -375,8 +375,7 @@ public class SearchHandler extends LoggingRequestHandler { Renderer<Result> renderer = rendererRegistry.getRenderer(query.getPresentation().getRenderer()); // docsumClass null means "unset", so we set it (it might be null - // here too in which case it will still be "unset" after we - // set it :-) + // here too in which case it will still be "unset" after we set it :-) if (query.getPresentation().getSummary() == null && renderer instanceof com.yahoo.search.rendering.Renderer) query.getPresentation().setSummary(((com.yahoo.search.rendering.Renderer) renderer).getDefaultSummaryClass()); @@ -472,7 +471,7 @@ public class SearchHandler extends LoggingRequestHandler { } catch (Exception e) { Result result = new Result(query); log(request, query, e); - result.hits().setError( + result.hits().addError( ErrorMessage.createUnspecifiedError("Failed searching: " + Exceptions.toMessageString(e), e)); return result; } diff --git a/container-search/src/main/java/com/yahoo/search/handler/SearchResponse.java b/container-search/src/main/java/com/yahoo/search/handler/SearchResponse.java index 8d94b9c2985..6945340892b 100644 --- a/container-search/src/main/java/com/yahoo/search/handler/SearchResponse.java +++ b/container-search/src/main/java/com/yahoo/search/handler/SearchResponse.java @@ -15,7 +15,7 @@ import java.util.Iterator; /** * Some leftover static methods. * - * @author <a href="mailto:steinar@yahoo-inc.com">Steinar Knutsen</a> + * @author Steinar Knutsen */ public class SearchResponse { diff --git a/container-search/src/main/java/com/yahoo/search/match/DocumentDb.java b/container-search/src/main/java/com/yahoo/search/match/DocumentDb.java index 838cbc7ca3d..18801f69103 100644 --- a/container-search/src/main/java/com/yahoo/search/match/DocumentDb.java +++ b/container-search/src/main/java/com/yahoo/search/match/DocumentDb.java @@ -11,7 +11,7 @@ import com.yahoo.search.searchchain.Execution; /** * A searchable database of documents * - * @author bratseth + * @author bratseth */ public class DocumentDb extends Searcher { diff --git a/container-search/src/main/java/com/yahoo/search/query/ParameterParser.java b/container-search/src/main/java/com/yahoo/search/query/ParameterParser.java index 23a4445179e..30a0d90c309 100644 --- a/container-search/src/main/java/com/yahoo/search/query/ParameterParser.java +++ b/container-search/src/main/java/com/yahoo/search/query/ParameterParser.java @@ -6,7 +6,7 @@ import static com.yahoo.container.util.Util.quote; /** * Wrapper class to avoid code duplication of common parsing requirements. * - * @author <a href="steinar@yahoo-inc.com">Steinar Knutsen</a> + * @author Steinar Knutsen */ public class ParameterParser { diff --git a/container-search/src/main/java/com/yahoo/search/query/QueryHelper.java b/container-search/src/main/java/com/yahoo/search/query/QueryHelper.java index 8d77d5edf9f..d17baf663dd 100644 --- a/container-search/src/main/java/com/yahoo/search/query/QueryHelper.java +++ b/container-search/src/main/java/com/yahoo/search/query/QueryHelper.java @@ -2,7 +2,7 @@ package com.yahoo.search.query; /** - * @author <a href="mailto:arnebef@yahoo-inc.com">Arne Bergene Fossaa</a> + * @author Arne Bergene Fossaa */ class QueryHelper { diff --git a/container-search/src/main/java/com/yahoo/search/query/Ranking.java b/container-search/src/main/java/com/yahoo/search/query/Ranking.java index 18e38a8c7e5..44c26f55040 100644 --- a/container-search/src/main/java/com/yahoo/search/query/Ranking.java +++ b/container-search/src/main/java/com/yahoo/search/query/Ranking.java @@ -17,7 +17,7 @@ import com.yahoo.search.result.ErrorMessage; /** * The ranking (hit ordering) settings of a query * - * @author <a href="mailto:arnebef@yahoo-inc.com">Arne Bergene Fossaa</a> + * @author Arne Bergene Fossaa * @author bratseth */ public class Ranking implements Cloneable { diff --git a/container-search/src/main/java/com/yahoo/search/query/parser/Parser.java b/container-search/src/main/java/com/yahoo/search/query/parser/Parser.java index edc36d82c22..2d050426b00 100644 --- a/container-search/src/main/java/com/yahoo/search/query/parser/Parser.java +++ b/container-search/src/main/java/com/yahoo/search/query/parser/Parser.java @@ -6,7 +6,7 @@ import com.yahoo.search.query.QueryTree; /** * Defines the interface of a query parser. To construct an instance of this class, use the {@link ParserFactory}. * - * @author <a href="mailto:simon@yahoo-inc.com">Simon Thoresen</a> + * @author Simon Thoresen */ public interface Parser { diff --git a/container-search/src/main/java/com/yahoo/search/query/parser/ParserEnvironment.java b/container-search/src/main/java/com/yahoo/search/query/parser/ParserEnvironment.java index 1aedc4e8b27..ba782cd17c6 100644 --- a/container-search/src/main/java/com/yahoo/search/query/parser/ParserEnvironment.java +++ b/container-search/src/main/java/com/yahoo/search/query/parser/ParserEnvironment.java @@ -13,8 +13,7 @@ import com.yahoo.search.searchchain.Execution; * This class encapsulates the environment of a {@link Parser}. In case you are creating a parser from within a * {@link Searcher}, you can use the {@link #fromExecutionContext(Execution.Context)} factory for convenience. * - * @author <a href="mailto:simon@yahoo-inc.com">Simon Thoresen</a> - * @since 5.1.4 + * @author Simon Thoresen */ public final class ParserEnvironment { diff --git a/container-search/src/main/java/com/yahoo/search/query/parser/ParserFactory.java b/container-search/src/main/java/com/yahoo/search/query/parser/ParserFactory.java index 55a6b73967a..d102bc39a88 100644 --- a/container-search/src/main/java/com/yahoo/search/query/parser/ParserFactory.java +++ b/container-search/src/main/java/com/yahoo/search/query/parser/ParserFactory.java @@ -6,10 +6,9 @@ import com.yahoo.search.Query; import com.yahoo.search.yql.YqlParser; /** - * <p>Implements a factory for {@link Parser}.</p> + * Implements a factory for {@link Parser}. * * @author Simon Thoresen - * @since 5.1.4 */ public final class ParserFactory { @@ -45,4 +44,5 @@ public final class ParserFactory { throw new UnsupportedOperationException(type.toString()); } } + } diff --git a/container-search/src/main/java/com/yahoo/search/query/properties/DefaultProperties.java b/container-search/src/main/java/com/yahoo/search/query/properties/DefaultProperties.java index 3c81d62df5a..4611d375597 100644 --- a/container-search/src/main/java/com/yahoo/search/query/properties/DefaultProperties.java +++ b/container-search/src/main/java/com/yahoo/search/query/properties/DefaultProperties.java @@ -10,14 +10,17 @@ import java.util.Map; /** * Default values for properties that are meant to be customized in query profiles. - * @author tonytv + * + * @author Tony Vaagenes */ public final class DefaultProperties extends Properties { + public static final CompoundName MAX_OFFSET = new CompoundName("maxOffset"); public static final CompoundName MAX_HITS = new CompoundName("maxHits"); public static final QueryProfileType argumentType = new QueryProfileType("DefaultProperties"); + static { argumentType.setBuiltin(true); @@ -37,4 +40,5 @@ public final class DefaultProperties extends Properties { return super.get(name, context, substitution); } } + } diff --git a/container-search/src/main/java/com/yahoo/search/query/properties/SubProperties.java b/container-search/src/main/java/com/yahoo/search/query/properties/SubProperties.java index 72405d2a728..9b40cff290f 100644 --- a/container-search/src/main/java/com/yahoo/search/query/properties/SubProperties.java +++ b/container-search/src/main/java/com/yahoo/search/query/properties/SubProperties.java @@ -9,7 +9,7 @@ import java.util.Map; /** * A wrapper around a chain of property objects that prefixes all gets/sets with a given path * - * @author <a href="mailto:arnebef@yahoo-inc.com">Arne Bergene Fossaa</a> + * @author Arne Bergene Fossaa */ public class SubProperties extends com.yahoo.search.query.Properties { diff --git a/container-search/src/main/java/com/yahoo/search/query/ranking/Matching.java b/container-search/src/main/java/com/yahoo/search/query/ranking/Matching.java index 64de357c683..bc07ad7bdbd 100644 --- a/container-search/src/main/java/com/yahoo/search/query/ranking/Matching.java +++ b/container-search/src/main/java/com/yahoo/search/query/ranking/Matching.java @@ -10,7 +10,7 @@ import java.util.Objects; /** * Holds the settings for the matching feature. * - * @author balder + * @author baldersheim */ public class Matching implements Cloneable { /** The type representing the property arguments consumed by this */ diff --git a/container-search/src/main/java/com/yahoo/search/query/ranking/SoftTimeout.java b/container-search/src/main/java/com/yahoo/search/query/ranking/SoftTimeout.java index 8f5e98c03a9..75fa9f957d7 100644 --- a/container-search/src/main/java/com/yahoo/search/query/ranking/SoftTimeout.java +++ b/container-search/src/main/java/com/yahoo/search/query/ranking/SoftTimeout.java @@ -10,7 +10,7 @@ import java.util.Objects; /** * Holds the settings for the soft-timeout feature. * - * @author balder + * @author baldersheim */ public class SoftTimeout implements Cloneable { /** The type representing the property arguments consumed by this */ diff --git a/container-search/src/main/java/com/yahoo/search/querytransform/QueryCombinator.java b/container-search/src/main/java/com/yahoo/search/querytransform/QueryCombinator.java index 274492d7414..bdeae21bfa1 100644 --- a/container-search/src/main/java/com/yahoo/search/querytransform/QueryCombinator.java +++ b/container-search/src/main/java/com/yahoo/search/querytransform/QueryCombinator.java @@ -35,7 +35,7 @@ import com.yahoo.search.searchchain.Execution; * <p>If the given default index does not exist in the search definition, the query part will be parsed with the * settings of the default index set to the "".</p> * - * @author <a href="mailto:steinar@yahoo-inc.com">Steinar Knutsen</a> + * @author Steinar Knutsen */ public class QueryCombinator extends Searcher { private static final String QUERYPREFIX = "query."; diff --git a/container-search/src/main/java/com/yahoo/search/querytransform/SortingDegrader.java b/container-search/src/main/java/com/yahoo/search/querytransform/SortingDegrader.java index 3bd88ba9c10..12a775e0a62 100644 --- a/container-search/src/main/java/com/yahoo/search/querytransform/SortingDegrader.java +++ b/container-search/src/main/java/com/yahoo/search/querytransform/SortingDegrader.java @@ -28,7 +28,6 @@ import java.util.Set; * * @author bratseth */ - // This writes fields to query.getRanking which are moved to rank.properties during query.prepare() // Query.prepare is done at the same time as canonicalization (by GroupingExecutor), so use that constraint. // (we're not adding another constraint at this point because all this preparation and encoding business diff --git a/container-search/src/main/java/com/yahoo/search/querytransform/VespaLowercasingSearcher.java b/container-search/src/main/java/com/yahoo/search/querytransform/VespaLowercasingSearcher.java index 2c679cd3ffc..74dcbb27817 100644 --- a/container-search/src/main/java/com/yahoo/search/querytransform/VespaLowercasingSearcher.java +++ b/container-search/src/main/java/com/yahoo/search/querytransform/VespaLowercasingSearcher.java @@ -15,8 +15,7 @@ import com.yahoo.prelude.query.WordItem; /** * Transform terms in query tree to lower case based on Vespa index settings. * - * @since 5.1.3 - * @author <a href="mailto:steinar@yahoo-inc.com">Steinar Knutsen</a> + * @author Steinar Knutsen */ @After({ STEMMING, ACCENT_REMOVAL }) @Provides(VespaLowercasingSearcher.LOWERCASING) diff --git a/container-search/src/main/java/com/yahoo/search/querytransform/WandSearcher.java b/container-search/src/main/java/com/yahoo/search/querytransform/WandSearcher.java index a4618cb99dd..cda41f5f62e 100644 --- a/container-search/src/main/java/com/yahoo/search/querytransform/WandSearcher.java +++ b/container-search/src/main/java/com/yahoo/search/querytransform/WandSearcher.java @@ -22,7 +22,6 @@ import com.yahoo.yolean.Exceptions; * Searcher that will create a Vespa WAND item from a list of tokens with weights. * IndexFacts is used to determine which WAND to create. * - * @since 5.1.11 * @author geirst * @author bratseth */ diff --git a/container-search/src/main/java/com/yahoo/search/result/DefaultErrorHit.java b/container-search/src/main/java/com/yahoo/search/result/DefaultErrorHit.java index 93574002d4f..16b07a86131 100644 --- a/container-search/src/main/java/com/yahoo/search/result/DefaultErrorHit.java +++ b/container-search/src/main/java/com/yahoo/search/result/DefaultErrorHit.java @@ -8,14 +8,15 @@ import java.util.List; import java.util.Set; /** - * A hit which holds information on error conditions in a result. - * En error hit maintains a main error - the main error of the result. + * A hit which holds a list of error conditions in a result. * * @author bratseth * @author Steinar Knutsen */ public class DefaultErrorHit extends Hit implements ErrorHit, Cloneable { + // TODO: Check that nobody implements ErrorHit, rename this to ErrorHit, and make an empty, deprecated subclass DefaultErrorHit + /** * A list of unique error messages, where the first is considered the "main" * error. It should always contain at least one error. @@ -23,16 +24,28 @@ public class DefaultErrorHit extends Hit implements ErrorHit, Cloneable { private List<ErrorMessage> errors = new ArrayList<>(); /** - * Creates an error hit with a main error + * Creates an error hit with one error * * @param source the name of the source or backend of this hit - * @param error an initial main error to add to this hit, cannot be null + * @param error an initial error to add to this hit, cannot be null */ public DefaultErrorHit(String source, ErrorMessage error) { super("error:" + source, new Relevance(Double.POSITIVE_INFINITY), source); addError(error); } + /** + * Creates an error hit with a list of errors + * + * @param source the name of the source or backend of this hit + * @param errors a list of errors for this to hold. The list will not be modified or retained. + */ + public DefaultErrorHit(String source, List<ErrorMessage> errors) { + super("error:" + source, new Relevance(Double.POSITIVE_INFINITY), source); + for (ErrorMessage error : errors) + addError(error); + } + public void setSource(String source) { super.setSource(source); for (Iterator<ErrorMessage> i = errorIterator(); i.hasNext();) { @@ -47,10 +60,11 @@ public class DefaultErrorHit extends Hit implements ErrorHit, Cloneable { /** * Returns the main error of this result, never null. * - * @deprecated since 5.18, use {@link #errors()} + * @deprecated use {@link #errors()} */ @Override @Deprecated + // TODO: Remove on Vespa 7 public ErrorMessage getMainError() { return errors.get(0); } @@ -63,14 +77,10 @@ public class DefaultErrorHit extends Hit implements ErrorHit, Cloneable { errors.add(error); } - /** - * Adds an error to this. This may change the main error - * and/or the list of detailed errors - */ + /** Adds an error to this */ public void addError(ErrorMessage error) { - if (error.getSource() == null) { + if (error.getSource() == null) error.setSource(getSource()); - } removeAndAdd(error); } @@ -97,6 +107,7 @@ public class DefaultErrorHit extends Hit implements ErrorHit, Cloneable { return s; } + @Override public String toString() { return "Error: " + errors.get(0).toString(); } diff --git a/container-search/src/main/java/com/yahoo/search/result/ErrorHit.java b/container-search/src/main/java/com/yahoo/search/result/ErrorHit.java index 31a788bd78a..802af478fa2 100644 --- a/container-search/src/main/java/com/yahoo/search/result/ErrorHit.java +++ b/container-search/src/main/java/com/yahoo/search/result/ErrorHit.java @@ -14,8 +14,13 @@ public interface ErrorHit extends Cloneable { void setSource(String source); - /** Returns the main error of this result, never null */ - @Deprecated // use: errors().iterator().next() + /** + * Returns the main error of this result, never null + * + * @deprecated use errors().iterator().next() + */ + // TODO: Remove on Vespa 7 + @Deprecated ErrorMessage getMainError(); /** @@ -38,8 +43,7 @@ public interface ErrorHit extends Cloneable { /** Returns true - this is a meta hit containing information on other hits */ boolean isMeta(); - /** Returns true if main error is the given error code or if main error - is general error 8 and all suberrors are the given error code */ + /** Returns true if all errors in this has the given error code */ boolean hasOnlyErrorCode(int code); Object clone(); diff --git a/container-search/src/main/java/com/yahoo/search/result/HitGroup.java b/container-search/src/main/java/com/yahoo/search/result/HitGroup.java index 2e51f59ba5d..4f4dff6f395 100644 --- a/container-search/src/main/java/com/yahoo/search/result/HitGroup.java +++ b/container-search/src/main/java/com/yahoo/search/result/HitGroup.java @@ -11,23 +11,26 @@ import com.yahoo.processing.response.DataList; import com.yahoo.processing.response.DefaultIncomingData; import com.yahoo.processing.response.IncomingData; +import java.util.ArrayList; import java.util.Collections; import java.util.HashSet; import java.util.Iterator; import java.util.List; +import java.util.ListIterator; import java.util.Set; +import java.util.stream.Collectors; import static com.yahoo.collections.CollectionUtil.first; /** * <p>A group of ordered hits. Since hitGroup is itself a kind of Hit, - * this can compose hierarchies of grouped hits.</p> + * this can compose hierarchies of grouped hits. * * <p>Group hits has a relevancy just as other hits - they can be ordered * between each other and in comparison to other hits. * * <p>Note that a group is by default a meta hit, but it can also contain its own content - * in addition to subgroup content, in which case it should be set to non-meta.</p> + * in addition to subgroup content, in which case it should be set to non-meta. * * @author bratseth */ @@ -77,7 +80,7 @@ public class HitGroup extends Hit implements DataList<Hit>, Cloneable, Iterable< * A direct reference to the errors of this result, or null if there are no errors. * The error hit will also be listed in the set of this of this result */ - private ErrorHit errorHit = null; + private DefaultErrorHit errorHit = null; private final ListenableFuture<DataList<Hit>> completedFuture; @@ -106,7 +109,7 @@ public class HitGroup extends Hit implements DataList<Hit>, Cloneable, Iterable< * @param id the id of this hit - any string, it is convenient to make this unique in the result containing this * @param relevance the relevance of this group of hits, preferably a number between 0 and 1 */ - public HitGroup(String id,double relevance) { + public HitGroup(String id, double relevance) { this(id,new Relevance(relevance)); } @@ -223,9 +226,15 @@ public class HitGroup extends Hit implements DataList<Hit>, Cloneable, Iterable< */ @Override public Hit add(Hit hit) { - if (hit.isMeta() && hit instanceof ErrorHit) { - boolean add = mergeErrors((ErrorHit) hit); - if (!add) return (Hit)errorHit; + if (hit.isMeta() && hit instanceof DefaultErrorHit) { + if (errorHit != null) { + errorHit.addErrors((DefaultErrorHit)hit); + return errorHit; // don't add another error hit + } + else { + errorHit = merge(consumeAnyQueryErrors(), (DefaultErrorHit) hit); + hit = errorHit; // Add this hit below + } } handleNewHit(hit); hits.add(hit); @@ -340,8 +349,8 @@ public class HitGroup extends Hit implements DataList<Hit>, Cloneable, Iterable< /** * Removes a hit from this group or any subgroup. * - * @param uri The uri of the hit to remove. - * @return The hit removed, or null if not found. + * @param uri the uri of the hit to remove. + * @return the hit removed, or null if not found. */ public Hit remove(URI uri) { for (Iterator<Hit> it = hits.iterator(); it.hasNext(); ) { @@ -351,7 +360,7 @@ public class HitGroup extends Hit implements DataList<Hit>, Cloneable, Iterable< handleRemovedHit(hit); return hit; } - if (hit instanceof HitGroup) { + else if (hit instanceof HitGroup) { Hit removed = ((HitGroup)hit).remove(uri); if (removed != null) { return removed; @@ -376,93 +385,107 @@ public class HitGroup extends Hit implements DataList<Hit>, Cloneable, Iterable< return hit; } - /** Sets the main error of this result. Prefer addError to add some error information. */ + /** + * Sets the main error of this result + * + * @deprecated prefer addError to add some error information. + */ + // TODO: Remove on Vespa 7 + @Deprecated public void setError(ErrorMessage error) { - if (errorHit == null) - add((Hit)createErrorHit(error)); - else - errorHit.addError(error); + addError(error); } /** Adds an error to this result */ public void addError(ErrorMessage error) { + getError(); // update the list of errors if (errorHit == null) - add((Hit)createErrorHit(error)); + add(new DefaultErrorHit(getSource(), error)); else errorHit.addError(error); } - /** - * Returns the error hit containing all error information, - * or null if no error has occurred - */ + /** Returns the error hit containing all error information, or null if no error has occurred */ public ErrorHit getErrorHit() { getError(); // Make sure the error hit is updated return errorHit; } + /** + * Removes the error hit of this. + * This removes all error messages of this and the query producing it. + * + * @return the error hit which was removed, or null if there were no errors + */ + public DefaultErrorHit removeErrorHit() { + updateHits(); // Consume and remove from the query producing this as well + DefaultErrorHit removed = errorHit; + if (removed != null) + remove(removed.getId()); + errorHit = null; + return removed; + } + /** * Returns the first error in this result, * or null if no searcher has produced an error AND the query doesn't contain an error */ public ErrorMessage getError() { - // See updateHits if this method is changed - if (errorHit != null) { - return errorHit.errors().iterator().next(); - } - - if (getQuery() != null && getQuery().errors().size() != 0) { - updateHits(); - } // Pull them over - - if (errorHit == null) { + updateHits(); + if (errorHit == null) return null; - } - - return errorHit.errors().iterator().next(); + else + return errorHit.errors().iterator().next(); } /** - * Handles the addition of a new error hit, whether or not we already have one + * Combines two error hits to one. Any one argument may be null, in which case the other is returned. * - * @return true if this shouls also be added to the list of hits of this reslt + * @return true if this should also be added to the list of hits of this result */ - private boolean mergeErrors(ErrorHit newHit) { - if (errorHit == null) { - errorHit = newHit; - return true; - } else { - errorHit.addErrors(newHit); - return false; - } + private DefaultErrorHit merge(DefaultErrorHit first, DefaultErrorHit second) { + if (first == null) return second; + if (second == null) return first; + + String mergedSource = first.getSource()!=null ? first.getSource() : second.getSource(); + List<ErrorMessage> mergedErrors = new ArrayList<>(); + mergedErrors.addAll(first.errors()); + mergedErrors.addAll(second.errors()); + return new DefaultErrorHit(mergedSource, mergedErrors); } /** * Must be called before the list of hits, or anything dependent on the list of hits, is removed. - * Merges errors from the query if there is one set for this group + * Consumes errors from the query if there is one set for this group */ private void updateHits() { - if (getQuery()==null) return; - - if (getQuery().errors().size() == 0) return; - - if (errorHit == null) // Creates an error hit where the first error is "main" - add((Hit)createErrorHit(toSearchError(getQuery().errors().get(0)))); - - // Add the rest of the errors - for (int i=1; i<getQuery().errors().size(); i++) - errorHit.addError(toSearchError(getQuery().errors().get(i))); - getQuery().errors().clear(); // TODO: Really clear them from here? + DefaultErrorHit queryErrors = consumeAnyQueryErrors(); + if (queryErrors != null) + add(queryErrors); } - protected ErrorHit createErrorHit(ErrorMessage errorMessage) { - return new DefaultErrorHit(getSource(), errorMessage); + /** + * Consumes errors from the query and returns them in a new error hit + * + * @return the error hit containing all query errors, or null if no query errors should be consumed + */ + private DefaultErrorHit consumeAnyQueryErrors() { + if (errorHit != null) return null; + if (getQuery() == null) return null; + if (getQuery().errors().isEmpty()) return null; + + // Move errors from the query into this + List<ErrorMessage> queryErrors = getQuery().errors().stream().map(this::toSearchError).collect(Collectors.toList()); + getQuery().errors().clear(); // TODO: Remove this line (not promised, can be done at any time) + return new DefaultErrorHit(getSource(), queryErrors); } /** Compatibility */ private ErrorMessage toSearchError(com.yahoo.processing.request.ErrorMessage error) { - if (error instanceof ErrorMessage) return (ErrorMessage)error; - else return new ErrorMessage(error.getCode(),error.getMessage(),error.getDetailedMessage(),error.getCause()); + if (error instanceof ErrorMessage) + return (ErrorMessage)error; + else + return new ErrorMessage(error.getCode(), error.getMessage(), error.getDetailedMessage(), error.getCause()); } /** @@ -704,14 +727,17 @@ public class HitGroup extends Hit implements DataList<Hit>, Cloneable, Iterable< // Filled is not kept in sync at removal private void handleRemovedHit(Hit hit) { - if (!hit.isAuxiliary()) { + if ( ! hit.isAuxiliary()) { concreteHitCount--; - if (!hit.isCached()) + if ( ! hit.isCached()) notCachedCount--; } else if (hit instanceof HitGroup) { subgroupCount--; } + else if (hit instanceof DefaultErrorHit) { + errorHit = null; + } if (deletionBreaksOrdering) { hitsSorted = false; @@ -796,8 +822,8 @@ public class HitGroup extends Hit implements DataList<Hit>, Cloneable, Iterable< } if (this.errorHit!=null) { // Find the cloned error and assign it for (Hit hit : hitGroupClone.asList()) { - if (hit instanceof ErrorHit) - hitGroupClone.errorHit=(ErrorHit)hit; + if (hit instanceof DefaultErrorHit) + hitGroupClone.errorHit=(DefaultErrorHit)hit; } } diff --git a/container-search/src/main/java/com/yahoo/search/result/HitGroupsLastComparator.java b/container-search/src/main/java/com/yahoo/search/result/HitGroupsLastComparator.java index eca72bef167..1fd2c52d1bd 100644 --- a/container-search/src/main/java/com/yahoo/search/result/HitGroupsLastComparator.java +++ b/container-search/src/main/java/com/yahoo/search/result/HitGroupsLastComparator.java @@ -6,7 +6,7 @@ import java.util.Comparator; /** * Ensures that HitGroups are placed last in the result. * - * @author tonytv + * @author Tony Vaagenes */ public class HitGroupsLastComparator extends ChainableComparator { diff --git a/container-search/src/main/java/com/yahoo/search/result/HitIterator.java b/container-search/src/main/java/com/yahoo/search/result/HitIterator.java index 7436d57a135..3a7793cd6d5 100644 --- a/container-search/src/main/java/com/yahoo/search/result/HitIterator.java +++ b/container-search/src/main/java/com/yahoo/search/result/HitIterator.java @@ -11,7 +11,7 @@ import com.yahoo.search.Result; /** * An iterator for the list of hits in a result. This iterator supports the remove operation. * - * @author <a href="mailto:steinar@yahoo-inc.com">Steinar Knutsen</a> + * @author Steinar Knutsen */ public class HitIterator implements Iterator<Hit> { diff --git a/container-search/src/main/java/com/yahoo/search/yql/FieldFiller.java b/container-search/src/main/java/com/yahoo/search/yql/FieldFiller.java index e218726d58b..45d74da53eb 100644 --- a/container-search/src/main/java/com/yahoo/search/yql/FieldFiller.java +++ b/container-search/src/main/java/com/yahoo/search/yql/FieldFiller.java @@ -97,7 +97,7 @@ public class FieldFiller extends Searcher { for (Documentdb db : config.documentdb()) { for (Summaryclass summary : db.summaryclass()) { - Set<String> attributes = null; + Set<String> attributes; if (Execution.ATTRIBUTEPREFETCH.equals(summary.name())) { attributes = new HashSet<>(summary.fields().size()); for (Fields f : summary.fields()) { @@ -131,20 +131,19 @@ public class FieldFiller extends Searcher { Set<String> summaryFields = result.getQuery().getPresentation().getSummaryFields(); - if (summaryFields.isEmpty() - || summaryClass == null - || result.getQuery().properties() - .getBoolean(FIELD_FILLER_DISABLE)) { + if (summaryFields.isEmpty() || + summaryClass == null || + result.getQuery().properties().getBoolean(FIELD_FILLER_DISABLE)) { return; } if (intersectionOfAttributes.containsAll(summaryFields)) { - if (!Execution.ATTRIBUTEPREFETCH.equals(summaryClass)) { + if ( ! Execution.ATTRIBUTEPREFETCH.equals(summaryClass)) { execution.fill(result, Execution.ATTRIBUTEPREFETCH); } } else { // Yes, summaryClass may be Execution.ATTRIBUTEPREFETCH here - if (!summaryDb.hasAll(summaryFields, summaryClass, result.getQuery().getModel().getRestrict())) { + if ( ! summaryDb.hasAll(summaryFields, summaryClass, result.getQuery().getModel().getRestrict())) { execution.fill(result, null); } } diff --git a/container-search/src/main/java/com/yahoo/search/yql/FieldFilter.java b/container-search/src/main/java/com/yahoo/search/yql/FieldFilter.java index 80c3c633b0a..75c2865d0a5 100644 --- a/container-search/src/main/java/com/yahoo/search/yql/FieldFilter.java +++ b/container-search/src/main/java/com/yahoo/search/yql/FieldFilter.java @@ -20,7 +20,7 @@ import com.yahoo.search.searchchain.Execution; * Remove fields which are not explicitly requested, if any field is explicitly * requested. Disable using FieldFilter.disable=true in request. * - * @author <a href="mailto:steinar@yahoo-inc.com">Steinar Knutsen</a> + * @author Steinar Knutsen */ @Beta @After(MinimalQueryInserter.EXTERNAL_YQL) diff --git a/container-search/src/test/java/com/yahoo/prelude/fastsearch/test/PartialFillTestCase.java b/container-search/src/test/java/com/yahoo/prelude/fastsearch/test/PartialFillTestCase.java index 7fda1d82fcc..867a8d7df83 100644 --- a/container-search/src/test/java/com/yahoo/prelude/fastsearch/test/PartialFillTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/fastsearch/test/PartialFillTestCase.java @@ -44,7 +44,7 @@ public class PartialFillTestCase extends junit.framework.TestCase { } protected void doPartialFill(Result result, String summaryClass) { if (result.hits().getErrorHit() == null) { - result.hits().setError(ErrorMessage.createUnspecifiedError("error")); + result.hits().addError(ErrorMessage.createUnspecifiedError("error")); } } } diff --git a/container-search/src/test/java/com/yahoo/search/grouping/vespa/GroupingExecutorTestCase.java b/container-search/src/test/java/com/yahoo/search/grouping/vespa/GroupingExecutorTestCase.java index b741159ab9d..f8a9b06888d 100644 --- a/container-search/src/test/java/com/yahoo/search/grouping/vespa/GroupingExecutorTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/grouping/vespa/GroupingExecutorTestCase.java @@ -650,7 +650,7 @@ public class GroupingExecutorTestCase { return ret; } if (passnum == failOnPassN) { - ret.hits().setError(ErrorMessage.createTimeout("timeout")); + ret.hits().addError(ErrorMessage.createTimeout("timeout")); } passnum++; return ret; diff --git a/container-search/src/test/java/com/yahoo/search/result/DefaultErrorHitTestCase.java b/container-search/src/test/java/com/yahoo/search/result/DefaultErrorHitTestCase.java index 840f5cbdf04..75b9a5264dc 100644 --- a/container-search/src/test/java/com/yahoo/search/result/DefaultErrorHitTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/result/DefaultErrorHitTestCase.java @@ -10,8 +10,7 @@ import org.junit.Before; import org.junit.Test; /** - * @author steinar - * @author bratseth + * @author Steinar Knutsen */ public class DefaultErrorHitTestCase { @@ -23,12 +22,8 @@ public class DefaultErrorHitTestCase { de = new DefaultErrorHit(SOURCE, ErrorMessage.createUnspecifiedError("DefaultErrorHitTestCase")); } - @After - public void tearDown() throws Exception { - } - @Test - public final void testSetSourceTakeTwo() { + public void testSetSourceTakeTwo() { assertEquals(SOURCE, de.getSource()); de.setSource(null); assertNull(de.getSource()); @@ -41,19 +36,19 @@ public class DefaultErrorHitTestCase { } @Test - public final void testToString() { + public void testToString() { assertEquals("Error: Source 'nalle': 5: Unspecified error: DefaultErrorHitTestCase", de.toString()); } @Test - public final void testSetMainError() { + public void testSetMainError() { ErrorMessage e = ErrorMessage.createBackendCommunicationError("abc"); assertNull(e.getSource()); de.addError(e); assertEquals(SOURCE, e.getSource()); boolean caught = false; try { - new DefaultErrorHit(SOURCE, null); + new DefaultErrorHit(SOURCE, (ErrorMessage)null); } catch (NullPointerException ex) { caught = true; } @@ -69,47 +64,41 @@ public class DefaultErrorHitTestCase { } @Test - public final void testAddError() { - ErrorMessage e = ErrorMessage - .createBackendCommunicationError("ljkhlkjh"); + public void testAddError() { + ErrorMessage e = ErrorMessage.createBackendCommunicationError("ljkhlkjh"); assertNull(e.getSource()); de.addError(e); assertEquals(SOURCE, e.getSource()); e = ErrorMessage.createBadRequest("kdjfhsdkfhj"); de.addError(e); int i = 0; - for (Iterator<ErrorMessage> errors = de.errorIterator(); errors - .hasNext(); errors.next()) { + for (Iterator<ErrorMessage> errors = de.errorIterator(); errors.hasNext(); errors.next()) { ++i; } assertEquals(3, i); } @Test - public final void testAddErrors() { - DefaultErrorHit other = new DefaultErrorHit("abc", - ErrorMessage.createBadRequest("sdasd")); + public void testAddErrors() { + DefaultErrorHit other = new DefaultErrorHit("abc", ErrorMessage.createBadRequest("sdasd")); de.addErrors(other); int i = 0; - for (Iterator<ErrorMessage> errors = de.errorIterator(); errors - .hasNext(); errors.next()) { + for (Iterator<ErrorMessage> errors = de.errorIterator(); errors.hasNext(); errors.next()) { ++i; } assertEquals(2, i); - other = new DefaultErrorHit("abd", - ErrorMessage.createEmptyDocsums("uiyoiuy")); + other = new DefaultErrorHit("abd", ErrorMessage.createEmptyDocsums("uiyoiuy")); other.addError(ErrorMessage.createNoAnswerWhenPingingNode("xzvczx")); de.addErrors(other); i = 0; - for (Iterator<ErrorMessage> errors = de.errorIterator(); errors - .hasNext(); errors.next()) { + for (Iterator<ErrorMessage> errors = de.errorIterator(); errors.hasNext(); errors.next()) { ++i; } assertEquals(4, i); } @Test - public final void testHasOnlyErrorCode() { + public void testHasOnlyErrorCode() { assertTrue(de.hasOnlyErrorCode(com.yahoo.container.protect.Error.UNSPECIFIED.code)); assertFalse(de.hasOnlyErrorCode(com.yahoo.container.protect.Error.BACKEND_COMMUNICATION_ERROR.code)); diff --git a/container-search/src/test/java/com/yahoo/search/result/test/HitGroupTestCase.java b/container-search/src/test/java/com/yahoo/search/result/test/HitGroupTestCase.java index 9ded5f7b768..b8f033444c8 100644 --- a/container-search/src/test/java/com/yahoo/search/result/test/HitGroupTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/result/test/HitGroupTestCase.java @@ -1,16 +1,30 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.search.result.test; +import com.yahoo.search.Query; +import com.yahoo.search.result.DefaultErrorHit; +import com.yahoo.search.result.ErrorHit; +import com.yahoo.search.result.ErrorMessage; import com.yahoo.search.result.Hit; import com.yahoo.search.result.HitGroup; +import org.junit.Test; import java.util.Arrays; +import java.util.List; +import java.util.Optional; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; /** * @author bratseth */ -public class HitGroupTestCase extends junit.framework.TestCase { +public class HitGroupTestCase { + @Test public void testStringStripping() { assertEquals("avabarne", Hit.stripCharacter('j', "javabjarne")); assertEquals("", Hit.stripCharacter('j', "")); @@ -19,7 +33,59 @@ public class HitGroupTestCase extends junit.framework.TestCase { assertEquals("foo", Hit.stripCharacter('j', "fooj")); assertEquals("", Hit.stripCharacter('j', "jjjjj")); } + + @Test + public void testErrorsConsistencyUsingErrorOperations() { + HitGroup hits = new HitGroup(); + + Query query = new Query(); + query.errors().add(ErrorMessage.createIllegalQuery("test1")); + query.errors().add(ErrorMessage.createTimeout("test2")); + hits.setQuery(query); + + hits.addError(ErrorMessage.createForbidden("test3")); + hits.addError(ErrorMessage.createUnspecifiedError("test4")); + + assertEquals(4, hits.getErrorHit().errors().size()); + assertEquals(0, query.errors().size()); + assertEquals(Optional.of(hits.getErrorHit()), errorHitIn(hits.asList())); + + DefaultErrorHit removedErrors = hits.removeErrorHit(); + assertNotNull(removedErrors); + assertEquals(4, removedErrors.errors().size()); + assertNull(hits.get(removedErrors.getId().toString())); + assertFalse(errorHitIn(hits.asList()).isPresent()); + + assertNull(hits.removeErrorHit()); + } + + @Test + public void testErrorsConsistencyUsingHitOperations() { + HitGroup hits = new HitGroup(); + + Query query = new Query(); + query.errors().add(ErrorMessage.createIllegalQuery("test1")); + query.errors().add(ErrorMessage.createTimeout("test2")); + hits.setQuery(query); + + DefaultErrorHit errors = new DefaultErrorHit("source", ErrorMessage.createForbidden("test3")); + errors.addError(ErrorMessage.createUnspecifiedError("test4")); + hits.add(errors); + + assertEquals(4, hits.getErrorHit().errors().size()); + assertEquals(0, query.errors().size()); + assertEquals(Optional.of(hits.getErrorHit()), errorHitIn(hits.asList())); + + DefaultErrorHit removedErrors = (DefaultErrorHit)hits.remove(errors.getId()); + assertNotNull(removedErrors); + assertEquals(4, removedErrors.errors().size()); + assertNull(hits.get(removedErrors.getId().toString())); + assertFalse(errorHitIn(hits.asList()).isPresent()); + + assertNull(hits.remove(errors.getId())); + } + @Test public void testRecursiveGet() { // Level 1 HitGroup g1=new HitGroup(); @@ -106,6 +172,7 @@ public class HitGroupTestCase extends junit.framework.TestCase { assertNull(g1.get("3",2)); } + @Test public void testThatHitGroupIsUnFillable() { HitGroup hg = new HitGroup("test"); { @@ -127,6 +194,7 @@ public class HitGroupTestCase extends junit.framework.TestCase { assertNull(hg.getFilled()); } + @Test public void testThatHitGroupIsFillable() { HitGroup hg = new HitGroup("test"); { @@ -150,6 +218,7 @@ public class HitGroupTestCase extends junit.framework.TestCase { assertTrue(hg.getFilled().isEmpty()); } + @Test public void testThatHitGroupIsFillableAfterFillableChangeunderTheHood() { HitGroup hg = new HitGroup("test"); { @@ -185,5 +254,10 @@ public class HitGroupTestCase extends junit.framework.TestCase { assertFalse(hg.isFilled("anyclass")); assertTrue(hg.getFilled().isEmpty()); } + + /** Returns the (first) error hit in the given list, or empty if none */ + private Optional<ErrorHit> errorHitIn(List<Hit> hits) { + return hits.stream().filter(h -> h instanceof ErrorHit).map(ErrorHit.class::cast).findFirst(); + } } |