/*
 *  call-seq:
 *     query.terms(searcher) -> term_array
 *
 *  Returns an array of terms searched for by this query. This can be used for
 *  implementing an external query highlighter for example. You must supply a
 *  searcher so that the query can be rewritten and optimized like it would be
 *  in a real search.
 */
static VALUE
frb_q_get_terms(VALUE self, VALUE searcher)
{
    VALUE rterms = rb_ary_new();
    HashSet *terms = hs_new((hash_ft)&term_hash,
                            (eq_ft)&term_eq,
                            (free_ft)term_destroy);
    HashSetEntry *hse;
    GET_Q();
    Searcher *sea = (Searcher *)DATA_PTR(searcher);
    Query *rq = sea->rewrite(sea, q);
    rq->extract_terms(rq, terms);
    q_deref(rq);

    for (hse = terms->first; hse; hse = hse->next) {
        Term *term = (Term *)hse->elem;
        rb_ary_push(rterms, frb_get_term(term->field, term->text));
    }
    hs_destroy(terms);
    return rterms;
}