/* * call-seq: * top_doc.to_s -> string * * Returns a string represention of the top_doc in readable format. */ static VALUE frt_td_to_s(VALUE self) { int i; VALUE rhits = rb_funcall(self, id_hits, 0); const int len = RARRAY(rhits)->len; char *str = ALLOC_N(char, len * 64 + 100); char *s = str; VALUE rstr; sprintf(s, "TopDocs: total_hits = %d, max_score = %f [\n", FIX2INT(rb_funcall(self, id_total_hits, 0)), NUM2DBL(rb_funcall(self, id_max_score, 0))); s += strlen(s); for (i = 0; i < len; i++) { VALUE rhit = RARRAY(rhits)->ptr[i]; sprintf(s, "\t%d: %f\n", FIX2INT(rb_funcall(rhit, id_doc, 0)), NUM2DBL(rb_funcall(rhit, id_score, 0))); s += strlen(s); } sprintf(s, "]\n"); rstr = rb_str_new2(str); free(str); return rstr; }