# Uninitialized constant UNTOKENIZED

**URL:** <https://www.ruby-forum.com/t/uninitialized-constant-untokenized/66862>\
**Category:** Ferret\
**Created:** [August 29, 2006, 9:39pm UTC](https://www.ruby-forum.com/t/uninitialized-constant-untokenized/66862 "2006-08-29T21:39:48Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [August 29, 2006, 9:39pm UTC](https://www.ruby-forum.com/t/uninitialized-constant-untokenized/66862/1 "2006-08-29T21:39:48Z")

</div>

I’m getting “uninitialized constant UNTOKENIZED” when I try to do  
something like the following:

class Url \< ActiveRecord::Base  
acts\_as\_ferret :fields =\> {‘name’ =\> {},  
‘description’ =\> {},  
‘url’ =\> {:index =\>  
Ferret::Document::Field::Index::UNTOKENIZED},  
‘url\_type’ =\> {}}  
end

I am running ferret 0.10.1 and “bleeding edge version” of acts\_as\_ferret  
I got from  
svn://projects.jkraemer.net/acts\_as\_ferret/trunk/plugin/acts\_as\_ferret.

Any ideas?

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [August 29, 2006, 9:52pm UTC](https://www.ruby-forum.com/t/uninitialized-constant-untokenized/66862/2 "2006-08-29T21:52:32Z")

</div>

Caleb schrieb:

> I am running ferret 0.10.1 and “bleeding edge version” of acts\_as\_ferret  
> I got from  
> svn://projects.jkraemer.net/acts\_as\_ferret/trunk/plugin/acts\_as\_ferret.

i don’t know much about the acts\_as\_ferret plugin, but the CONST you’re  
talking about was part of the 0.9 ferret source tree and is gone from  
ferret 0.10 on…

Ben

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [August 29, 2006, 10:02pm UTC](https://www.ruby-forum.com/t/uninitialized-constant-untokenized/66862/3 "2006-08-29T22:02:34Z")

</div>

Caleb schrieb:

> Thanks. Then, I guess my question is, “How do I set something to be not  
> be tokenized?” To further explain, I would like to be able to type in  
> only a part of a URL (ie: microsoft) and get back any URL that contains  
> that query (ie: [www.microsoft.com](http://www.microsoft.com), [www.foo.com/microsoft](http://www.foo.com/microsoft),  
> [microsoft.foobar.com](http://microsoft.foobar.com), etc.).

again… i can just talk about ferret, not acts\_as\_ferret… you do now  
pass a hash describing all fields as a so called fieldinfo-hash to the  
index. . see  
[http://ferret.davebalmain.com/api/classes/Ferret/Index/FieldInfos.html](http://ferret.davebalmain.com/api/classes/Ferret/Index/FieldInfos.html)  
for more information. i guess this will be fixed within the next days  
and you will get a message from jens as soon as he gets back to his  
computer 🙂

Ben

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [August 30, 2006, 12:10am UTC](https://www.ruby-forum.com/t/uninitialized-constant-untokenized/66862/4 "2006-08-30T00:10:57Z")

</div>

Hi!

On Tue, Aug 29, 2006 at 10:01:11PM +0200, Benjamin K. wrote:

> [http://ferret.davebalmain.com/api/classes/Ferret/Index/FieldInfos.html](http://ferret.davebalmain.com/api/classes/Ferret/Index/FieldInfos.html)  
> for more information. i guess this will be fixed within the next days  
> and you will get a message from jens as soon as he gets back to his  
> computer 🙂

right 😉

Caleb, not tokenizing the url field won’t help you much with your  
problem. An untokenized field’s content is indexed ‘as is’, so indexing  
‘[www.gnu.org](http://www.gnu.org)’ will leave you with that exact term in the index, and a  
search for ‘gnu’ won’t find that. Even searching for ‘gnu\*’ won’t find  
it, since the term starts with ‘www.’ and a wildcard at the beginning of  
the query term (like ‘_gnu_’) is not allowed due to the way the index  
works.

Better would be to use a custom tokenizer that splits the contents for  
this field at ‘.’ and ‘/’ (and maybe strips out the ‘www’, as that will  
be shared by most URLs and won’t help much when it comes to searching)  
so that ‘gnu org’ would be indexed. now a search for ‘gnu’ will find  
what you want.

If you aren’t keen on implementing your own tokenizer, define a method  
that pre-processes the url and splits it like described, and index the  
return value of this method:

so you’d use

class Url \< ActiveRecord::Base  
acts\_as\_ferret :fields =\> {:name =\> {},  
:description =\> {},  
:url\_parts =\> { :index =\> :untokenized },  
:url\_type =\> {}}  
def url\_parts  
# split url and remove common terms  
self.url.split(/[/.]/) - [‘www’, ‘html’]  
end  
end

Concerning the new 0.10 FieldInfo properties: you can use all the  
properties and values described at  
[http://ferret.davebalmain.com/api/classes/Ferret/Index/FieldInfo.html](http://ferret.davebalmain.com/api/classes/Ferret/Index/FieldInfo.html)  
in your call to acts\_as\_ferret, they will be passed straight through to  
Ferret upon index creation.

Jens

–  
webit! Gesellschaft für neue Medien mbH [www.webit.de](http://www.webit.de)  
Dipl.-Wirtschaftsingenieur Jens Krämer removed\_email\_address@domain.invalid  
Schnorrstraße 76 Tel +49 351 46766 0  
D-01069 Dresden Fax +49 351 46766 66

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [August 30, 2006, 1:26am UTC](https://www.ruby-forum.com/t/uninitialized-constant-untokenized/66862/5 "2006-08-30T01:26:17Z")

</div>

Jens K. wrote:

> so you’d use
> 
> class Url \< ActiveRecord::Base  
> acts\_as\_ferret :fields =\> {:name =\> {},  
> :description =\> {},  
> :url\_parts =\> { :index =\> :untokenized },  
> :url\_type =\> {}}  
> def url\_parts  
> # split url and remove common terms  
> self.url.split(/[/.]/) - [‘www’, ‘html’]  
> end  
> end

Thanks! That gives me the information I need. One question remains,  
however. I definately want to do custom tokenizing for urls. However,  
when I use the code quoted above, the url\_parts method is never executed  
(ie: if I put a breakpoint there, the code never hits it). How can I  
get ferret to reference ‘url\_parts’ and call that method?

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [August 29, 2006, 9:55pm UTC](https://www.ruby-forum.com/t/uninitialized-constant-untokenized/66862/6 "2006-08-29T21:55:06Z")

</div>

Benjamin K. wrote:

> Caleb schrieb:
> 
> i don’t know much about the acts\_as\_ferret plugin, but the CONST you’re  
> talking about was part of the 0.9 ferret source tree and is gone from  
> ferret 0.10 on…
> 
> Ben

Thanks. Then, I guess my question is, “How do I set something to be not  
be tokenized?” To further explain, I would like to be able to type in  
only a part of a URL (ie: microsoft) and get back any URL that contains  
that query (ie: [www.microsoft.com](http://www.microsoft.com), [www.foo.com/microsoft](http://www.foo.com/microsoft),  
[microsoft.foobar.com](http://microsoft.foobar.com), etc.).

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [August 30, 2006, 8:56am UTC](https://www.ruby-forum.com/t/uninitialized-constant-untokenized/66862/7 "2006-08-30T08:56:14Z")

</div>

On Wed, Aug 30, 2006 at 01:26:17AM +0200, Caleb wrote:

> > ```
> > self.url.split(/[\/.]/) - ['www', 'html']
> > 
> > ```
> > 
> > end  
> > end
> 
> Thanks! That gives me the information I need. One question remains,  
> however. I definately want to do custom tokenizing for urls. However,  
> when I use the code quoted above, the url\_parts method is never executed  
> (ie: if I put a breakpoint there, the code never hits it). How can I  
> get ferret to reference ‘url\_parts’ and call that method?

it should get called whenever acts\_as\_ferret indexes a record, since it  
is referenced in the :fields hash. what does aaf log when you create a  
new Url record ?

Jens

–  
webit! Gesellschaft für neue Medien mbH [www.webit.de](http://www.webit.de)  
Dipl.-Wirtschaftsingenieur Jens Krämer removed\_email\_address@domain.invalid  
Schnorrstraße 76 Tel +49 351 46766 0  
D-01069 Dresden Fax +49 351 46766 66

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [September 6, 2006, 7:10pm UTC](https://www.ruby-forum.com/t/uninitialized-constant-untokenized/66862/8 "2006-09-06T19:10:23Z")

</div>

Jens K. wrote:

> it should get called whenever acts\_as\_ferret indexes a record, since it  
> is referenced in the :fields hash. what does aaf log when you create a  
> new Url record ?

Sorry for the delayed response. I find it annoying when thread are  
started that could be helpful to others and the author doesn’t take time  
to indicate what ultimately solved the problem. So, I won’t do that  
here.

You’re right, url\_parts IS being called when a Url is CREATED. I was  
thinking that it would be called upon SEARCHING. I guess that wouldn’t  
make sense unless you wanted to re-index everything on every search (not  
a good idea).

So, the url\_parts method works as expected.
