# Aaf and "foreign" index (build from script, not from aaf)

**URL:** <https://www.ruby-forum.com/t/aaf-and-foreign-index-build-from-script-not-from-aaf/169703>\
**Category:** Ferret\
**Created:** [June 7, 2009, 12:04pm UTC](https://www.ruby-forum.com/t/aaf-and-foreign-index-build-from-script-not-from-aaf/169703 "2009-06-07T12:04:23Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![fink](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/85f322/32.png) [@fink](https://www.ruby-forum.com/u/fink)\
**Post date:** [June 7, 2009, 12:04pm UTC](https://www.ruby-forum.com/t/aaf-and-foreign-index-build-from-script-not-from-aaf/169703/1 "2009-06-07T12:04:23Z")

</div>

Hi there,

it’s a bit difficult to describe in one line, so the subject ist a  
little confusing - sry.

I have a file full of objects and use a ruby-script to store them in my  
database. To save time I decided to build the ferret-index with this  
script too:

index \<\< {:id =\> doc\_hash[:doc\_nr], :titel =\> doc\_hash[:Titel], :autor  
=\> doc\_hash[:Autor], :isbn =\> doc\_hash[:ISBN], :SSchlagwort =\>  
doc\_hash[:SSchlagwort]}

Works great, the hole process (build index and load into db) takes about  
10 minutes.

Unfortunately this does not work as expected: When I now perform a  
search that delivers a single hit, everything works fine, the result ist  
displayed.

here the output from my server:

Will use local index.  
using index in /XXX/XXXX/YYYY  
Book Columns (2.2ms) SHOW FIELDS FROM `books`  
default field list: [:created\_at, :doc\_nr, :SSchlagwort, :ISBN, :autor,  
:updated\_at, :titel]  
Book Load (1.2ms) SELECT \* FROM `books` WHERE (books.id in  
(‘000355278’))  
Query: Ajax autor:gamperl  
total hits: 1, results delivered: 1

But… ( seems to me there’s always a but… 😉 ) …when I perform a  
search that delivers multiple hits I get an error from the  
bookscontroller:

You have a nil object when you didn’t expect it!  
You might have expected an instance of Array.  
The error occurred while evaluating nil.\<=\>

and the server says:

Will use local index.  
using index in /Users/sk/Programmieren/KBGPortal/index/development/book  
Book Columns (2.1ms) SHOW FIELDS FROM `books`  
default field list: [:created\_at, :doc\_nr, :SSchlagwort, :ISBN, :autor,  
:updated\_at, :titel]  
Book Load (20.7ms) SELECT \* FROM `books` WHERE (books.id in  
(‘000136979’,‘000020751’,‘000379879’,‘000399200’,‘000358415’,‘000303862’,‘000402467’,‘000358010’,‘000355278’,‘000376535’))

NoMethodError (You have a nil object when you didn’t expect it!  
You might have expected an instance of Array.  
The error occurred while evaluating nil.\<=\>):

So ferret finds the corresponding book.ids and creates the right sql  
query (the query works fine, sure enough I testet this first).  
I thought, that there ha sto be something wrong with my bookscontroller.  
Then I rebuild the index with aaf directly from my database (it took  
about three hours) and now it worked.

As I will have to reimport the db often I want to build the index with  
the script.

The only thing I found till now is, that aaf names the index:  
ActsAsFerret::define\_index(‘XYZ’,  
:models =\> {  
Book =\> {:fields =\> [:id, :titel, :autor, :isbn, :sschlagwort]}  
while my script does not.

Can anybody help me?  
Thanks in advance,  
Mc
