1 #!/usr/bin/env python 2 3 from simplex import * 4 import sys, time 5 6 try: 7 separator = sys.argv.index("--") 8 filename, numeric, interval = sys.argv[1:4] 9 fields = map(int, sys.argv[4:separator]) 10 terms = groups(sys.argv[separator+1:], len(fields)) 11 except (IndexError, ValueError): 12 print >>sys.stderr, "Usage: %s <filename> <interval> <field>... -- <term value>..." % sys.argv[0] 13 sys.exit(1) 14 15 f = open(filename) 16 accessor = DelimitedRecord(fields, numeric=(numeric == "true")) 17 18 try: 19 t = time.time() 20 l = make_index(f, accessor.get_key, int(interval)) 21 print "Indexed in %s seconds." % (time.time() - t) 22 23 # Now use the index. 24 25 index = IndexedFile(f, l, accessor.get_key) 26 for term in terms: 27 28 # Convert the term to the appropriate type. 29 30 term = accessor.convert(term) 31 32 # Perform the search. 33 34 t = time.time() 35 line = index.find(term) 36 if line: 37 print "Found (at %s seconds)...\n%s" % (time.time() - t, line) 38 39 finally: 40 f.close() 41 42 # vim: tabstop=4 expandtab shiftwidth=4