Resetting ferret index before test runs

I need to reset the ferret index between test runs.

It seems like there are a few ways to reset the ferret index.

  • Deleting the index directory – is this really bad form?
  • calling rebuild_index
  • (any others?)

What would y’all recommend? (Sorry, I’m from Texas)

Preferably, I’d like a way to reset the index that I can integrate
into a selenium test.

-David

I need to reset the ferret index between test runs.

It seems like there are a few ways to reset the ferret index.

  • Deleting the index directory – is this really bad form?

This is ok, if it’s fast enough for you.

What would y’all recommend? (Sorry, I’m from Texas)

I’d personally keep an index somewhere outside of the normal path, and
“cp -lr” it into the path


Kyle M.
Software Engineer
CastTV, Inc

You should provide a RAMDirectory to your Index during your tests.
That way, each new Index instance creates a new empty RAM stored
index, which’s faster for tests and doesn’t create any files :slight_smile:

Have a look at the RAMDirectory class :slight_smile:

Jérémie.


Jérémie ‘ahFeel’ BORDIER
Rift Technologies - http://www.installclick.com
Blog - http://www.unixaumonde.com

Comments…

On Jun 24, 2007, at 2:10 PM, Kyle M. wrote:

“cp -lr” it into the path
I don’t understand how this solves my problem… Are you saying that
I should remove the symbolic links before each test run?

Also, not sure if this is a good idea for development, since BSD (Mac
OS X) doesn’t have the -l option on cp. My fc6 box (deployment) has
it though.

-David

Hi!

On Sun, Jun 24, 2007 at 01:35:46PM -0500, David J. wrote:

I need to reset the ferret index between test runs.

It seems like there are a few ways to reset the ferret index.

  • Deleting the index directory – is this really bad form?

Not really, but it can cause problems if you have an index instance open
in this directory. Closing any open indexes and them removing the
directory is the best way to ensure the index is cleared out.

  • calling rebuild_index

You should do this after removing the old index, of course :wink: In
theory, removing the old index before calling rebuild_index should not
be needed, but it won’t hurt either:

Model.aaf_index.close
FileUtils.rm_rf Model.aaf_configuration[:index_dir]
Model.rebuild_index

What would y’all recommend? (Sorry, I’m from Texas)

In general you should think about how often you need the index to be
rebuilt. With larger fixture volumes reindexing in your setup method
can really slow down your tests - in this case think about only
rebuilding the index less frequently, i.e. only before the tests that
really need the index are run.

You could also split your tests in index changing and not index changing
tests, and choose the appropriate rebuild frequency on a case by case
basis to reduce the slow down by frequent rebuilds.

If you keep an index to be used for testing ready somewhere, replacing
RAILS_ROOT/index/test/model with this one in setup should work, too.
Just be sure to call Model.aaf_index.close before replacing the index
directory to avoid any hickups.

Replacing the persistent index directory implementation used in tests
with a RAMDirectory based on a persistent test index that is never
changed is a good idea, too, but won’t work with acts_as_ferret out of
the box.

Jens


Jens Krämer
webit! Gesellschaft für neue Medien mbH
Schnorrstraße 76 | 01069 Dresden
Telefon +49 351 46766-0 | Telefax +49 351 46766-66
[email protected] | www.webit.de

Amtsgericht Dresden | HRB 15422
GF Sven Haubold, Hagen Malessa