[MacRuby-devel] SearchKit in BridgeSupport

Laurent Sansonetti lsansonetti at apple.com
Wed Dec 8 20:59:08 PST 2010


Hi Jonathan,

It looks like SearchKit behaves pretty well with MacRuby trunk and the latest BridgeSupport preview release.

Below is a sample that I just programmed, for fun. It indexes all .c files in the current directory then searches the index using the first parameter to the script as the query.

$ 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)

$ ./miniruby t.rb 'FIXME and XXX'
found: string.c (score: 4.70689010620117)
found: encoding.c (score: 18.6799507141113)
found: bs.c (score: 12.1080780029297)
found: process.c (score: 6.92176055908203)

I think I will commit it in the samples directory, later.

Laurent

On Dec 8, 2010, at 4:06 PM, Jonathan Ragan-Kelley wrote:

> I want to write a simple SearchKit-based utility. I can't seem to find
> SearchKit support anywhere in the new/preview or system-provided
> BridgeSupport versions, however.
> 
> Should it be supported?
> How should I include the framework?
> _______________________________________________
> MacRuby-devel mailing list
> MacRuby-devel at lists.macosforge.org
> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-devel/attachments/20101208/697a4644/attachment-0001.html>


More information about the MacRuby-devel mailing list