Permalink
Browse files

mostly ported

  • Loading branch information...
1 parent 4bb4862 commit 8cb87309c5780e2a02a60bc3cd10aea2882e568b Burke Libbey committed Aug 27, 2009
View
0 .gitignore 100644 → 100755
No changes.
View
67 README.rdoc 100644 → 100755
@@ -1,23 +1,22 @@
-= CouchSphinx
+= MongoSphinx
-The CouchSphinx library implements an interface between CouchDB and Sphinx
-supporting CouchRest to automatically index objects in Sphinx. It tries to
-act as transparent as possible: Just an additional method in the CouchRest
-domain specific language and some Sphinx configuration are needed to get
-going.
+The MongoSphinx library implements an interface between MongoDBand Sphinx
+supporting MongoMapper to automatically index objects in Sphinx. It tries to
+act as transparent as possible: Just an additional method in MongoMapper
+and some Sphinx configuration are needed to get going.
== Prerequisites
-CouchSphinx needs gems CouchRest and Riddle as well as a running Sphinx
+MongoSphinx needs gems MongoMapper and Riddle as well as a running Sphinx
and a CouchDB installation.
sudo gem sources -a http://gems.github.com # Only needed once!
sudo gem install riddle
- sudo gem install couchrest
- sudo gem install ulbrich-couchsphinx
+ sudo gem install mongomapper
+ sudo gem install burke-mongosphinx
-No additional configuraton is needed for interfacing with CouchDB: Setup is
-done when CouchRest is able to talk to the CouchDB server.
+No additional configuraton is needed for interfacing with MongoDB: Setup is
+done when MongoMapper is able to talk to the MongoDB server.
A proper "sphinx.conf" file and a script for retrieving index data have to
be provided for interfacing with Sphinx: Sorry, no UltraSphinx like
@@ -35,14 +34,14 @@ This is a sample configuration for a single "main" index:
pid_file = ./sphinx/searchd.pid
}
- source couchblog {
+ source mongoblog {
type = xmlpipe2
xmlpipe_command = ./sphinxsource.rb
}
- index couchblog {
- source = couchblog
+ index mongoblog {
+ source = mongoblog
charset_type = utf-8
path = ./sphinx/sphinx_index_main
@@ -57,30 +56,31 @@ script interfacing with one single instance:
require 'rubygems'
require 'lib/models' # Depends on location of model files
- data = SERVER.default_database.view('CouchSphinxIndex/couchrests_by_timestamp')
+###TODO
+ data = SERVER.default_database.view('MongoSphinxIndex/couchrests_by_timestamp')
rows = data['rows'] rescue []
- puts CouchSphinx::Indexer::XMLDocset.new(rows).to_s
+ puts MongoSphinx::Indexer::XMLDocset.new(rows).to_s
== Models
Use method <tt>fulltext_index</tt> to enable indexing of a model. The
default is to index all attributes but it is recommended to provide a list of
attribute keys.
-A side effect of calling this method is, that CouchSphinx overrides the
-default of letting CouchDB create new IDs: Sphinx only allows numeric IDs and
-CouchSphinx forces new objects with the name of the class, a hyphen and an
+A side effect of calling this method is, that MongoSphinx overrides the
+default of letting MongoDB create new IDs: Sphinx only allows numeric IDs and
+MongoSphinx forces new objects with the name of the class, a hyphen and an
integer as ID (e.g. <tt>Post-38497238</tt>). Again: Only these objects are
indexed due to internal restrictions of Sphinx.
Sample:
- class Post < CouchRest::ExtendedDocument
- use_database SERVER.default_database
+ class Post
+ include MongoMapper::Document
- property :title
- property :body
+ key :title, String
+ key :body, String
fulltext_index :title, :body
end
@@ -89,25 +89,16 @@ Add options <tt>:server</tt> and <tt>:port</tt> to <tt>fulltext_index</tt> if
the Sphinx server to query is running on a different server (defaults to
"localhost" with port 3312).
-If you are sure your Sphinx is compiled with 64-bit support, you may add
-option <tt>:idsize</tt> with value <tt>64</tt> to generate 64-bit IDs for
-CouchDB (defaults to 32-bits).
-
Here is a full-featured sample setting additional options:
- fulltext_index :title, :body, :server => 'my.other.server', :port => 3313,
- :idsize => 64
+ fulltext_index :title, :body, :server => 'my.other.server', :port => 3313
== Indexing
-CouchSphinx also adds a new design document to CouchDB: It needs to collect
-all relevant objects for running the Sphinx indexer and adds its own views
-to do so. Have a look at CouchDB design document "CouchSphinxIndex" for
-details.
-
Automatically starting the reindexing of objects the moment new objects are
-created can be implemented by adding a save_callback to the model class:
-
+created can be implemented by adding a save callback to the model class:
+
+ ###TODO
save_callback :after do |object|
`sudo indexer --all --rotate` # Configure sudo to allow this call...
end
@@ -147,7 +138,9 @@ Sample:
== Copyright & License
-Copyright (c) 2009 Holtzbrinck Digital GmbH, Jan Ulbrich
+Copyright (c) 2009 Burke Libbey, Ryan Neufeld
+
+CouchSphinx Copyright (c) 2009 Holtzbrinck Digital GmbH, Jan Ulbrich
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
View
0 Rakefile 100644 → 100755
No changes.
View
36 lib/indexer.rb 100644 → 100755
@@ -1,53 +1,53 @@
-# CouchSphinx, a full text indexing extension for CouchDB/CouchRest using
+# MongoSphinx, a full text indexing extension for MongoDB using
# Sphinx.
#
-# This file contains the CouchSphinx::Indexer::XMLDocset and
-# CouchSphinx::Indexer::XMLDoc classes.
+# This file contains the MongoSphinx::Indexer::XMLDocset and
+# MongoSphinx::Indexer::XMLDoc classes.
-# Namespace module for the CouchSphinx gem.
+# Namespace module for the MongoSphinx gem.
-module CouchSphinx #:nodoc:
+module MongoSphinx #:nodoc:
# Module Indexer contains classes for creating XML input documents for the
# indexer. Each Sphinx index consists of a single "sphinx:docset" with any
# number of "sphinx:document" tags.
#
# The XML source can be generated from an array of CouchRest objects or from
- # an array of Hashes containing at least fields "couchrest-type" and "_id"
- # as returned by CouchDB view "CouchSphinxIndex/couchrests_by_timestamp".
+ # an array of Hashes containing at least fields "classname" and "_id"
+ # as returned by MongoDB view "MongoSphinxIndex/couchrests_by_timestamp".
#
# Sample:
#
# rows = [{ 'name' => 'John', 'phone' => '199 43828',
- # 'couchrest-type' => 'Address', '_id' => 'Address-234164'
+ # 'classname' => 'Address', '_id' => 'Address-234164'
# },
# { 'name' => 'Sue', 'mobile' => '828 19439',
- # 'couchrest-type' => 'Address', '_id' => 'Address-422433'
+ # 'classname' => 'Address', '_id' => 'Address-422433'
# }
# ]
- # puts CouchSphinx::Indexer::XMLDocset.new(rows).to_s
+ # puts MongoSphinx::Indexer::XMLDocset.new(rows).to_s
#
# <?xml version="1.0" encoding="utf-8"?>
# <sphinx:docset>
# <sphinx:schema>
# <sphinx:attr name="csphinx-class" type="multi"/>
- # <sphinx:field name="couchrest-type"/>
+ # <sphinx:field name="classname"/>
# <sphinx:field name="name"/>
# <sphinx:field name="phone"/>
# <sphinx:field name="mobile"/>
# <sphinx:field name="created_at"/>
# </sphinx:schema>
# <sphinx:document id="234164">
# <csphinx-class>336,623,883,1140</csphinx-class>
- # <couchrest-type>Address</couchrest-type>
+ # <classname>Address</classname>
# <name><![CDATA[[John]]></name>
# <phone><![CDATA[[199 422433]]></phone>
# <mobile><![CDATA[[]]></mobile>
# <created_at><![CDATA[[]]></created_at>
# </sphinx:document>
# <sphinx:document id="423423">
# <csphinx-class>336,623,883,1140</csphinx-class>
- # <couchrest-type>Address</couchrest-type>
+ # <classname>Address</classname>
# <name><![CDATA[[Sue]]></name>
# <phone><![CDATA[[]]></phone>
# <mobile><![CDATA[[828 19439]]></mobile>
@@ -98,9 +98,9 @@ def initialize(rows = [])
if row.kind_of? CouchRest::Document
object = row
elsif row.kind_of? Hash
- row = row['value'] if row['couchrest-type'].nil?
+ row = row['value'] if row['classname'].nil?
- if row and (class_name = row['couchrest-type'])
+ if row and (class_name = row['classname'])
object = eval(class_name.to_s).new(row) rescue nil
end
end
@@ -118,7 +118,7 @@ def initialize(rows = [])
xml << "<sphinx:field name=\"#{key}\"/>"
end
- xml << '<sphinx:field name="couchrest-type"/>'
+ xml << '<sphinx:field name="classname"/>'
xml << '<sphinx:attr name="csphinx-class" type="multi"/>'
xml << '</sphinx:schema>'
@@ -185,9 +185,9 @@ def initialize(id, class_name, properties)
xml = "<sphinx:document id=\"#{id}\">"
xml << '<csphinx-class>'
- xml << CouchSphinx::MultiAttribute.encode(class_name)
+ xml << MongoSphinx::MultiAttribute.encode(class_name)
xml << '</csphinx-class>'
- xml << "<couchrest-type>#{class_name}</couchrest-type>"
+ xml << "<classname>#{class_name}</classname>"
properties.each do |key, value|
xml << "<#{key}><![CDATA[[#{value}]]></#{key}>"
View
Binary file not shown.
Oops, something went wrong.

0 comments on commit 8cb8730

Please sign in to comment.