Exemplo n.º 1
0
// Token search iterates through a TokenChain to find sub-results
// in the already builded chain. This may be useful in case you match the outer DIV
// of the DOM and still want to get deeper smaller results that may also match your
// search-term
func (q *Query) TokenSearch(tokenChain *tokenutil.Chain) *searchutil.Result {
	var success bool

	for {
		if tokenChain.Next() == nil {
			return q.result
		}

		// we start with the next sub-chain, as the one passed to this func as arg counts already as match
		tokenChain = tokenChain.Next()

		success = q.Match(tokenChain.StartToken())

		if success == true {
			q.result.Add(tokenChain)
			// search within the new chain again this will be done recursively upon the deepest level of the chain
			// new results will have their own new chain
			// TODO: upon here this can actually be done in coroutines as we are working with totally independant data
			q.TokenSearch(tokenChain)
		}
	}
}