/*
 *  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
frt_q_get_terms(VALUE self, VALUE searcher)
{
    int i;
    VALUE rterms = rb_ary_new();
    HashSet *terms = term_set_new();
    GET_Q();
    Searcher *sea = (Searcher *)DATA_PTR(searcher);
    Query *rq = sea->rewrite(sea, q);
    rq->extract_terms(rq, terms);
    q_deref(rq);
    for (i = 0; i < terms->size; i++) {
        Term *term = (Term *)terms->elems[i];
        rb_ary_push(rterms, frt_get_term(term->field, term->text));
    }
    hs_destroy(terms);
    return rterms;
}