/* *Internalstateforplaintreeandplainnode
*/ typedefstruct
{
QueryItem *ptr; int len; /* allocated size of ptr */ int cur; /* number of elements in ptr */
} PLAINTREE;
staticvoid
plainnode(PLAINTREE *state, NODE *node)
{ /* since this function recurses, it could be driven to stack overflow. */
check_stack_depth();
staticvoid
freetree(NODE *node)
{ /* since this function recurses, it could be driven to stack overflow. */
check_stack_depth();
if (!node) return; if (node->left)
freetree(node->left); if (node->right)
freetree(node->right);
pfree(node);
}
/* *cleantreefor!operator. *It'susefulfordebug,butin *othercase,suchviewisusedwithsearchinindex. *Operator!alwaysreturnTRUE
*/ static NODE *
clean_NOT_intree(NODE *node)
{ /* since this function recurses, it could be driven to stack overflow. */
check_stack_depth();
if (node->valnode->type == QI_VAL) return node;
if (node->valnode->qoperator.oper == OP_NOT)
{
freetree(node); return NULL;
}
/* Check if current node is OP_PHRASE, get its distance */
isphrase = (node->valnode->qoperator.oper == OP_PHRASE);
ndistance = isphrase ? node->valnode->qoperator.distance : 0;
if (node->left == NULL && node->right == NULL)
{ /* *Whenwecollapseoutaphrasenodeentirely,propagateitsown *distanceintoboth*laddand*radd;itistheresponsibilityof *theparentnodetocountitonlyonce.Also,foraphrase *node,distancescomingfromchildrenaresummedandpropagated *uptoparent(weassumelladd==lraddandrladd==rradd,else *rulewasbrokenatalowerlevel).Butifthisisn'taphrase *node,takethelargerofthetwochilddistances;that *correspondstowhatTS_executewilldoinnon-stopwordcases.
*/ if (isphrase)
*ladd = *radd = lladd + ndistance + rladd; else
*ladd = *radd = Max(lladd, rladd);
freetree(node); return NULL;
} elseif (node->left == NULL)
{ /* Removing this operator and left subnode */ /* lladd and lradd are equal/redundant, don't count both */ if (isphrase)
{ /* operator's own distance must propagate to left */
*ladd = lladd + ndistance + rladd;
*radd = rradd;
} else
{ /* at non-phrase op, just forget the left subnode entirely */
*ladd = rladd;
*radd = rradd;
}
res = node->right;
pfree(node);
} elseif (node->right == NULL)
{ /* Removing this operator and right subnode */ /* rladd and rradd are equal/redundant, don't count both */ if (isphrase)
{ /* operator's own distance must propagate to right */
*ladd = lladd;
*radd = lradd + ndistance + rradd;
} else
{ /* at non-phrase op, just forget the right subnode entirely */
*ladd = lladd;
*radd = lradd;
}
res = node->left;
pfree(node);
} elseif (isphrase)
{ /* Absorb appropriate corrections at this level */
node->valnode->qoperator.distance += lradd + rladd; /* Propagate up any unaccounted-for corrections */
*ladd = lladd;
*radd = rradd;
} else
{ /* We're keeping a non-phrase operator, so ladd/radd remain 0 */
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.