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


#1

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… :wink: ) …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