How to install Hyper Estraier and the Ruby bindings on Mac OS X, including a mini example on how to use the P2P capabilities
This is a slightly modified version of some Japanese fellow’s documention on how to install Hyper Estraier on Mac OS X
First we need libiconv:
1 $ cd /usr/local/src 2 $ wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.11.tar.gz 3 $ tar zxvf libiconv-1.11.tar.gz 4 $ cd libiconv-1.11 5 $ ./configure 6 $ make 7 $ sudo make install
zlib:
1 $ cd /usr/local/src 2 $ wget http://www.zlib.net/zlib-1.2.3.tar.gz 3 $ tar zxvf zlib-1.2.3.tar.gz 4 $ ./configure 5 $ make 6 $ sudo make install
QDBM :
1 $ cd /usr/local/src 2 $ wget http://qdbm.sourceforge.net/qdbm-1.8.74.tar.gz 3 $ tar zxvf qdbm-1.8.74.tar.gz 4 $ cd qdbm-1.8.74 5 $ ./configure --enable-zlib 6 $ make mac 7 $ make check-mac 8 $ sudo make install-mac
Hyper Estraier
1 $ cd /usr/local/src 2 $ wget http://hyperestraier.sourceforge.net/hyperestraier-1.4.9.tar.gz 3 $ tar zxvf hyperestraier-1.4.9.tar.gz 4 $ cd hyperestraier-1.4.9 5 $ ./configure 6 $ make mac 7 $ make check-mac 8 $ sudo make install-mac
Finally we’ll install the pure ruby bindings:
1 $ cd rubypure 2 $ ./configure 3 $ make 4 $ sudo make install
To verify that Hyper Estraier is installed and working, try one of the examples in the examples folder, or follow these instructions:
First create and start a P2P node:
1 estmaster init casket 2 estmaster start casket
Open http://localhost:1978/master_ui in your browser and create a node called dictionary.
Then run this code which adds a record to the index:
1 require "estraierpure" 2 include EstraierPure 3 4 node = Node::new 5 node.set_url("http://localhost:1978/node/dictionary") 6 node.set_auth("admin", "admin") 7 8 doc = Document::new 9 # @uri : the location of a document which any document should have. 10 doc.add_attr("@uri", "This is the URL, required?") 11 # @title : the title used as a headline in the search result. 12 doc.add_attr("@title", "This is the title, required?") 13 doc.add_text("Text goes here") 14 15 result = node.put_doc(doc) 16 unless result 17 printf("error: %s\n", node.status) 18 end
Next we’ll perform a query which returns the object we just added:
1 require "estraierpure" 2 include EstraierPure 3 4 # create and configure the node connecton object 5 node = Node::new 6 node.set_url("http://localhost:1978/node/dictionary") 7 8 # create a search condition object 9 cond = Condition::new 10 11 # set the search phrase to the search condition object 12 cond.set_phrase("Text goes here") 13 14 # get the result of search 15 nres = node.search(cond, 0); 16 if nres 17 # for each document in the result 18 for i in 0...nres.doc_num 19 # get a result document object 20 rdoc = nres.get_doc(i) 21 # display attributes 22 value = rdoc.attr("@uri") 23 printf("URI: %s\n", value) if value 24 value = rdoc.attr("@title") 25 printf("Title: %s\n", value) if value 26 # display the snippet text */ 27 printf("%s", rdoc.snippet) 28 end 29 else 30 STDERR.printf("error: %d\n", node.status) 31 end
The query language is documented here.
If you’re indexing ActiveRecord objects use acts_as_searchable:
1 gem install acts_as_searchable
How to install the exception_logger Rails plugin and protect the logs with basic authentication
This snippet explains how to install and use the Rails exception_logger plugin. I’ll also show you how to protect your logs by extending the plugin with basic authentication.
1 script/plugin source http://svn.techno-weenie.net/projects/plugins 2 script/plugin install exception_logger
I’m using Rails Edge on this project, so I had to install classic pagination also:
1 script/plugin install svn://errtheblog.com/svn/plugins/classic_pagination
Next create and execute the migration file:
1 ./script/generate exception_migration 2 rake db:migrate
Before starting the server we need to setup the routes:
1 map.exceptions '/logged_exceptions/:action/:id', :controller => 'logged_exceptions', :action => 'index', :id => nil
You also need to include the ExceptionLoggable in your ApplicationController:
1 class ApplicationController < ActionController::Base 2 include ExceptionLoggable 3 ...
Start your server and access the exception log at /logged_exceptions.
Exceptions can contain email addresses, passwords, credit card numbers, so you’ll want to protect /logged_exceptions from the public. This can be done by adding the following code to the end of environment.rb:
1 config.after_initialize do 2 require 'application' unless Object.const_defined?(:ApplicationController) 3 LoggedExceptionsController.class_eval do 4 before_filter :authenticate 5 6 protected 7 8 def authenticate 9 authenticate_or_request_with_http_basic do |username, password| 10 username == "foo" && password == "bar" 11 end 12 end 13 end 14 end
With this code we add a before filter that shows a login dialog to anyone trying to access /logged_exception/. Note that this requires Rails 2.0 basic authentication to work, so make sure you have the proper version installed.
Installing Ultraviolet and Oniguruma
First install Oniguruma
Oniguruma is a regular expression engine that Ultraviolet uses to parse text; Ruby also uses Oniguruma by the way. If you don’t have Oniguruma on your system you’ll get this error while installing Ultraviolet (at least on Ubuntu Linux):
1 oregexp.c:2:23: error: oniguruma.h: No such file or directory
This tells you that you should download and install Oniguruma. For me version 5.8.0 was the only version that worked, so execute this command to get the right version of Oniguruma:
1 $ wget http://www.geocities.jp/kosako3/oniguruma/archive/onig-5.8.0.tar.gz
You now have the source package on your computer, so decompress it with the following command:
1 $ tar zxvf onig-5.8.0.tar.gz
If everything went fine, change current directory:
1 $ cd onig-5.8.0/
Next, run configure:
1 $ ./configure
Watch the output closely and fix any errors reported, then run make:
1 $ make
To build and install Onigurama run:
1 $ sudo make install
I managed to get the following errors from Ultraviolet with other versions of Oniguruma, but these went away after installing 5.8.0 and re-installing Oniguruma:
1 Parsing error in // ==UserScript==: wrong number of arguments (2 for 0) #<Textpow::SyntaxNode:0xb7c91780>
Installing Ultraviolet and dependencies
Next install Ultraviolet with RubyGems:
1 $ sudo gem install -r ultraviolet --include-dependencies 2 3 Select which gem to install for your platform (i486-linux) 4 1. oniguruma 1.1.0 (mswin32) 5 2. oniguruma 1.1.0 (ruby) 6 3. Skip this gem 7 4. Cancel installation 8 > 2 9 Building native extensions. This could take a while... 10 Successfully installed ultraviolet-0.10.0 11 Successfully installed textpow-0.9.0 12 Successfully installed oniguruma-1.1.0 13 Successfully installed plist-3.0.0
Test that Ultraviolet works by running the following code with irb:
1 $ irb 2 3 require 'rubygems' 4 require 'uv' 5 puts Uv.syntaxes.join( "\n" ) 6 puts Uv.themes.join( "\n" ) 7 input = <<HTML<<HTML 8 <html> 9 <body> 10 </body> 11 </html> 12 HTMLHTML 13 14 puts Uv.parse( input, "xhtml", "html", true, "slush_poppies")
Problems
You might get this error:
1 require 'uv' 2 LoadError: libonig.so.2: cannot open shared object file: No such file or directory - /usr/lib/ruby/gems/1.8/gems/oniguruma-1.1.0/lib/oregexp.so
This message is a bit confusing. It means Ruby can’t find libonig.so.2, not oregexp.so as you could believe.
To fix this, check if the library has been linked:
1 $ ldconfig -p|grep libonig
If the library is not linked, add the path to the directory where the file is located to /etc/ld.so.conf:
1 /usr/local/lib 2 3 include /etc/ld.so.conf.d/*.conf
Then run:
1 $ ldconfig
Another way of fixing this problem would be to tell the build script to install it to /usr/lib.