$ cat t.rb
framework 'CoreServices'
storage = NSMutableData.new
idx = SKIndexCreateWithMutableData(storage, 'myIndex', KSKIndexInverted, nil)
Dir.glob('*.c').each do |path|
doc = SKDocumentCreate('file', nil, File.basename(path))
SKIndexAddDocumentWithText(idx, doc, File.read(path), true)
CFRelease(doc)
end
SKIndexFlush(idx)
query = ARGV.first
search = SKSearchCreate(idx, query, 0)
documentIDs = Pointer.new('q', 100)
scores = Pointer.new('f', 100)
outFound = Pointer.new('q')
while true
ok = SKSearchFindMatches(search, 100, documentIDs, scores, 0, outFound)
found = outFound[0]
if found > 0
documents = Pointer.new(:id, found)
SKIndexCopyDocumentRefsForDocumentIDs(idx, found, documentIDs, documents)
found.times do |n|
puts "found: #{SKDocumentGetName(documents[n])} (score: #{scores[n]})"
end
end
break unless ok
end
$ ./miniruby t.rb FIXME
found: gc.c (score: 12.0658931732178)
found: parse.c (score: 2.83560252189636)
found: string.c (score: 1.33235919475555)
found: y.tab.c (score: 2.83532977104187)
found: thread.c (score: 7.34140586853027)
found: process.c (score: 3.73652815818787)
found: io.c (score: 1.50885021686554)
found: enum.c (score: 3.12123870849609)
found: encoding.c (score: 8.63234233856201)
found: bs.c (score: 8.4449462890625)
found: array.c (score: 1.99167764186859)