no.sesat.search.query.parser.alt
Class RotationAlternation

java.lang.Object
  extended by no.sesat.search.query.parser.alt.AbstractAlternation
      extended by no.sesat.search.query.parser.alt.RotationAlternation
All Implemented Interfaces:
Alternation

public final class RotationAlternation
extends AbstractAlternation

SKER-439 - Rotation Alternation

Rotates like-joined DoubleOperatorClauses (forests). Tree rotation on the Query clause heirarchy is expensive, and as clauses are immutable and are reused through a weak-referenced cache map, performing and remembering the rotations directly after tree construction is a performance benefit over repeated on-the-fly rotations.
The memory increase, taking into account the weak-reference maps is (N-1)^2 +2N -2, where N is the number leaf clauses in the forest. From this it can also be shown that the asymptotic complexity is just shy of O(n^2).
XorClauses with Hint.ROTATION_ALTERNATION are used to store these alternations within the query tree.

Typical usecases of these Rotation-variant XorClauses are visitors that are interested in possible combinations, or joins, between leaf clauses, for example the query evaluation and analysis, and the synonym query transformer.

Here's an example of the sequencial rotations on a query clause heirarchy of eight leaf clauses, all eight leaf clauses are joined by DefaultOperatorClause, so there is only one forest to perform rotations on.
The numbers one through to eight represent the eight terms in the query string and hence the eight leaf clauses. In every rotation these leaf clauses refer to the same reused immutable instances.
The letters A through to G represent the DoubleOperatorClauses. In every rotation these are always different instances as their layout of grandchildren differ.
The number of rotations in any forest is always one less than the number of DoubleOperatorClauses in the forest.
The leaf clauses from left to right always remain in order so visitors can be assured that the query string at large remains the same.

To perform each rotation, the iterate, top, bottom, and orphan clause must be all determined. This is indicated in the diagram on the forest before the rotation occurs.

The process of rotation is then split into three steps, pre-rotation, post-rotation, and centre-of-rotation. This is indicated in the diagram on the forest after it has been rotated.



Example usecases of the resulting rotations within the query
The questions begs when is this rotation actually used and to what benefit?



References:
Binary Tree Rotation
Institute of Standards and Technology - Rotation
Sequence tagging

Version:
$Id: RotationAlternation.java 7225 2009-04-09 00:32:20Z ssmiweve $

Nested Class Summary
 
Nested classes/interfaces inherited from interface no.sesat.search.query.parser.alt.Alternation
Alternation.Context
 
Field Summary
 
Fields inherited from class no.sesat.search.query.parser.alt.AbstractAlternation
context
 
Constructor Summary
RotationAlternation(Alternation.Context cxt)
          Creates a new instance of RotationAlternation.
 
Method Summary
 Clause alternate(Clause originalRoot)
          Returns a alternated clause where all child forests contain XorClauses.
protected
<T extends UnaryClause>
T
createOperatorClause(Clause left, Clause right, T replacementFor)
          
protected  XorClause.Hint getAlternationHint()
          
 
Methods inherited from class no.sesat.search.query.parser.alt.AbstractAlternation
createXorClause, leftChild, leftOpChild, parent, parents, replaceDescendant, replaceOperatorClause, rightChild, rightOpChild
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RotationAlternation

public RotationAlternation(Alternation.Context cxt)
Creates a new instance of RotationAlternation.

Parameters:
cxt -
Method Detail

alternate

public Clause alternate(Clause originalRoot)
Returns a alternated clause where all child forests contain XorClauses. These XorClauses hold all possible rotations for the corresponding forest. Each XorClause always puts the left-leaning rotation as the left child, and the right-leaning rotation (or the next XorClause) as the right child.

Parameters:
originalRoot -
Returns:

createOperatorClause

protected <T extends UnaryClause> T createOperatorClause(Clause left,
                                                         Clause right,
                                                         T replacementFor)

Overrides:
createOperatorClause in class AbstractAlternation
Returns:

getAlternationHint

protected XorClause.Hint getAlternationHint()

Specified by:
getAlternationHint in class AbstractAlternation
Returns:
the XorClause.Hint used during this alternation process.


Copyright © 2005-2009 Schibsted ASA. All Rights Reserved.