2008/12/8 Jens Wille <jens.wille / uni-koeln.de>:
> here's my take on the task: Poor Man's Search ;-)

I like that name. :-)

>  <http://github.com/blackwinter/pms>
>
> it's a different approach with support for boolean operators as well
> as - back to topic! - proximity operators. pms builds an index for
> the input documents and stores the token positions along with the
> document numbers. still pretty rough, but working...
>
>> text = <<EOT
>> Hello world, how are you today? I said "Hello"
>> to the other guy but he would not answer although
>> all the world could hear me.
>> EOT
>>
>> proximity_search text, 3, "hello", "World" do |a,b|
>>   printf "Found at char positions %3d and %3d\n", a, b
>> end
>
>  require 'pms/ext'
>
>  search = text.search('hello').near('world', 3)

Nice!  I like the idea to create the search criteria by calling methods.

But I have a remark from an API point of view: I'd probably separate
the search specification from the index building.  If I read your code
properly then you create the search criterion from the input text.  If
you use that approach the index will be recreated for every other
search.  It's probably cleaner and also more efficient if query
creation, index creation and search are separated.

Kind regards

robert

-- 
remember.guy do |as, often| as.you_can - without end