Author: ssmiweve Date: 2008-11-25 15:08:33 +0100 (Tue, 25 Nov 2008) New Revision: 6981
Modified: trunk/query-api/src/main/java/no/sesat/search/query/finder/ChildFinder.java trunk/query-api/src/main/java/no/sesat/search/query/parser/alt/AbstractAlternation.java Log: Merged revisions 6980 via svnmerge from http://sesat.no/svn/sesat-kernel/branches/2.17 ........ r6980 | ssmiweve | 2008-11-25 14:49:33 +0100 (Tue, 25 Nov 2008) | 1 line Issue SKER5016: (Strange infinite loop in VeryFastTokenEvaluator.java on a few number of newscase person pages) ........ Modified: trunk/query-api/src/main/java/no/sesat/search/query/finder/ChildFinder.java =================================================================== --- trunk/query-api/src/main/java/no/sesat/search/query/finder/ChildFinder.java 2008-11-25 13:49:33 UTC (rev 6980) +++ trunk/query-api/src/main/java/no/sesat/search/query/finder/ChildFinder.java 2008-11-25 14:08:33 UTC (rev 6981) @@ -1,4 +1,4 @@ -/* Copyright (2007) Schibsted Søk AS +/* Copyright (2007-2008) Schibsted Søk AS * This file is part of SESAT. * * SESAT is free software: you can redistribute it and/or modify @@ -23,11 +23,21 @@ import no.sesat.search.query.parser.*; -final class ChildFinder extends AbstractReflectionVisitor { +/** Used to find if a particular clause exists underneath another. + * + * @version $Id$ + */ +public final class ChildFinder extends AbstractReflectionVisitor { private boolean found; private Clause child = null; + /** Does the child clause exist any depth underneath the parent. + * + * @param parent the parent clause + * @param child the child clause. + * @return Does the child clause exist any depth underneath the parent. + */ public synchronized boolean childExists(final OperationClause parent, final Clause child) { found = false; Modified: trunk/query-api/src/main/java/no/sesat/search/query/parser/alt/AbstractAlternation.java =================================================================== --- trunk/query-api/src/main/java/no/sesat/search/query/parser/alt/AbstractAlternation.java 2008-11-25 13:49:33 UTC (rev 6980) +++ trunk/query-api/src/main/java/no/sesat/search/query/parser/alt/AbstractAlternation.java 2008-11-25 14:08:33 UTC (rev 6981) @@ -1,4 +1,4 @@ -/* Copyright (2007) Schibsted Søk AS +/* Copyright (2007-2008) Schibsted Søk AS * This file is part of SESAT. * * SESAT is free software: you can redistribute it and/or modify @@ -31,6 +31,7 @@ import no.sesat.search.query.OperationClause; import no.sesat.search.query.OrClause; import no.sesat.search.query.XorClause; +import no.sesat.search.query.finder.ChildFinder; import org.apache.log4j.Logger; /** Base abstraction class for any Alternation implementation. @@ -150,13 +151,14 @@ } /** Build new DoubleOperatorClauses from newChild all the way back up to the root. - * XXX Only handles single splits, or one layer of variations, denoted by the childsParentBeforeRotation argument. - * This could be solved by using an array, specifying ancestry line, for the argument instead. - ** @param root - * @param newChild - * @param originalChild - * @param originalParent - * @return + * XXX Only handles single splits, or one layer of variations, denoted by the originalParent argument. + * This could be solved by using an array, specifying ancestry line, for the argument instead. <br/><br/> + * If, under root, originalParent cannot be found then root is returned unaltered. + * @param root the root clause. an altered version of this will be returned. + * @param newChild the new child. + * @param originalChild the original child. + * @param originalParent the original parent of the original child. expected to be found under root. + * @return the root clause where the originalChild has been replaced with the newChild. */ protected OperationClause replaceDescendant( final DoubleOperatorClause root, @@ -164,24 +166,33 @@ final DoubleOperatorClause originalChild, final DoubleOperatorClause originalParent){ - OperationClause nC = newChild; - OperationClause rC = originalChild; - OperationClause rCParent = originalParent; + // pre-condition check: originalParent must be found under root somewhere + if(new ChildFinder().childExists(root, originalParent)){ - do{ - nC = replaceOperatorClause(nC, rC, rCParent); - for(OperationClause parent : context.getParentFinder().getParents(root, rC)){ - if(rCParent == parent){ - rC = parent; - rCParent = root == rCParent - ? rCParent - : context.getParentFinder().getParent(root, rCParent); - break; + OperationClause nC = newChild; + OperationClause rC = originalChild; + OperationClause rCParent = originalParent; + + do{ + nC = replaceOperatorClause(nC, rC, rCParent); + for(OperationClause parent : context.getParentFinder().getParents(root, rC)){ + if(rCParent == parent){ + rC = parent; + rCParent = root == rCParent + ? rCParent + : context.getParentFinder().getParent(root, rCParent); + break; + } } - } - }while(root != rC); + }while(root != rC); - return nC; + return nC; + + }else{ + LOG.error("originalParent does not live inside root\n" + originalParent + '\n' + root); + // return the unaltered root + return root; + } } /** Replace the originalChild that exists under the originalParent will the newChild. _______________________________________________ Kernel-commits mailing list [email protected] http://sesat.no/mailman/listinfo/kernel-commits
