# Indexed?

**URL:** <https://www.ruby-forum.com/t/indexed/151101>\
**Category:** Ferret\
**Created:** [October 16, 2008, 8:04pm UTC](https://www.ruby-forum.com/t/indexed/151101 "2008-10-16T20:04:10Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![tomtoday](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/35a633/32.png) [@tomtoday](https://www.ruby-forum.com/u/tomtoday)\
**Post date:** [October 16, 2008, 8:04pm UTC](https://www.ruby-forum.com/t/indexed/151101/1 "2008-10-16T20:04:10Z")

</div>

Hi,  
I have problem with indexing simple structire.  
Indexing single element works, but dong it in a little bit more complex  
code fails.

require ‘ferret’  
include Ferret # 0.11.5 on win32  
require ‘engtagger’ # [http://engtagger.rubyforge.org/](http://engtagger.rubyforge.org/)

class CorpusIndexedElement  
attr\_accessor :sentence, :pos, :offset, :word

def initialize(sentence, offset, word, pos)  
@sentence = sentence  
@offset = offset  
@word = word  
@pos = pos  
end

def to\_ferret\_index\_hash  
#puts sentence, offset, word, pos  
{ :sentence =\> sentence, :offset =\> offset, :word =\> word, :pos =\>  
pos }  
end  
end

def index\_corpus\_sentence(tagger, sentence)  
tagged = tagger.add\_tags(sentence)  
result = []

offset = 0  
tagged.split.each do |element|  
m = /\<(\D\*)\>(._)\<(\D_)\>/.match(element)  
result \<\< CorpusIndexedElement.new(sentence, offset, m[2], m[1])  
offset += m[2].size + 1  
end

result  
end

sentences = [  
“Chocolate comprises a number of raw and processed foods that are  
produced from the seed of the tropical cacao tree.”,  
“Pure, unsweetened chocolate contains primarily cocoa solids and cocoa  
butter in varying proportions.”  
]

tagger = EngTagger.new  
index = Ferret::I.new

sentences.each do |sentence|  
index\_corpus\_sentence(tagger, sentence).each do |element|  
index \<\< element.to\_ferret\_index\_hash  
end  
end

# this gives no results

puts index.search(‘word: “and”’)

# but his works:

#index \<\< CorpusIndexedElement.new(“a test  
sentence”,0,“test”,“xy”).to\_ferret\_index\_hash  
#puts index.search(‘word: “test”’)

I run out of ideas ☹

Cheers,  
Tomasz

---

<div class="post-metadata">

**Author:** ![tomtoday](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/35a633/32.png) [@tomtoday](https://www.ruby-forum.com/u/tomtoday)\
**Post date:** [October 28, 2008, 8:38pm UTC](https://www.ruby-forum.com/t/indexed/151101/2 "2008-10-28T20:38:16Z")

</div>

Hi,

I’m not exactly sure what you’re doing there, but ‘and’ is in Ferret’s  
list of default stop words and therefore won’t be indexed by default.  
maybe this is the whole problem?

Cheers,  
Jens

PS: please post via the real mailing list, this web interface sucks for  
posting.

Tom Bak wrote:

> Hi,  
> I have problem with indexing simple structire.  
> Indexing single element works, but dong it in a little bit more complex  
> code fails.

[…]

> # this gives no results
> 
> puts index.search(‘word: “and”’)
> 
> # but his works:
> 
> #index \<\< CorpusIndexedElement.new(“a test  
> sentence”,0,“test”,“xy”).to\_ferret\_index\_hash  
> #puts index.search(‘word: “test”’)
> 
> I run out of ideas ☹
> 
> Cheers,  
> Tomasz
