test.rb 658 B

123456789101112131415161718192021222324252627
  1. #
  2. # $Id$
  3. #
  4. require 'init.rb'
  5. q = ARGV.join(' ')
  6. @sphinx = Sphinx::Client.new
  7. # @sphinx.SetSortMode(Sphinx::Client::SPH_SORT_ATTR_ASC, 'created_at')
  8. results = @sphinx.Query(q)
  9. puts "Query '#{q}' retrieved #{results['total']} of #{results['total_found']} matches in #{results['time']} sec.";
  10. puts "Query stats:";
  11. results['words'].each do |word, info|
  12. puts " '#{word}' found #{info['hits']} times in #{info['docs']} documents\n"
  13. end
  14. puts
  15. n = 1
  16. results['matches'].each do |doc|
  17. print "#{n}. doc_id=#{doc['id']}, weight=#{doc['weight']}"
  18. doc['attrs'].each do |attr, value|
  19. print ", #{attr}=#{value}"
  20. end
  21. puts
  22. n = n+1
  23. end