0

I am trying to get a Ruby on Rails application running on Ubuntu. It utilizes Xapian in order to search for documents. I already installed the xapian-full Gem in version 1.1.3.4 as instructed by the Gemfile and I created the directory files/default where the Xapian database will probably be.

database = Xapian::Database.new('files/default');

As soon as the code runs into this line, there is an error:

IOError in SearchController#index

DatabaseOpeningError: Couldn't detect type of database

Do I need to initialize the database or something? I looked the Xapian Docs and I searched for the error message on the internet, but none of this really helped.

Community
  • 1
  • 1
YMMD
  • 3,730
  • 2
  • 32
  • 43

1 Answers1

0

(Writing this answer with knowledge of Xapian, but not the xapian-full Gem, so it's possible some details may be wrong - but the error comes from Xapian, so I'm pretty sure this is on the right lines.)

The error is because you created the directory files/default. Instead, just create the files directory, and ensure the process running Xapian has permission to write to that directory.

Why does Xapian raise an error here? Well, it's because Xapian databases consist simply of a directory containing a special set of files. When Xapian::Database.new is called, it checks if the database already exists before creating a new one. In the default opening mode, if the database directory already exists, it assumes that it shouldn't overwrite whatever's there with a new database, so it tries to open the existing database. Because the directory is just empty, this throws the error you see.

Richard Boulton
  • 1,368
  • 1
  • 9
  • 9
  • Thanks for this illuminating comment! Sadly this changes the error message to another one: `DatabaseOpeningError: Couldn't stat 'files/default'` I have no Idea what `stat` means. Do you have another idea what could be the reason for that? – YMMD May 17 '12 at 11:23
  • What's the stack trace from within ruby? There are different ways of creating (in the C++ library) `Xapian::Database` objects, and the approach used in `xapian-full` with the code path you're using (`Xapian::Database.new`) will affect what it's trying to do. If I had to guess, I'd say that it's trying to open an existing database, but there isn't one (nor way there with an empty directory, as you originally tried). So there may be another way of creating a new database that you'll have to use first. – James Aylett May 20 '12 at 12:23
  • The stack trace started at my `Xapian::Database.new` function call and ended in the quoted error message without anything in between. It came directly from Xapian. Anyway, I fixed it now: The error was that the index has not been generated properly. I did this manually using `omindex` and now everything works as expected. Since your response answers my original question I'll accept it of course. Thanks to both of you for helping me! – YMMD May 21 '12 at 15:44