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.

有帮助吗?

解决方案

(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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top