Module: MongoSphinx::Indexer
- Defined in:
- lib/indexer.rb
Overview
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 “classname” and “_id” as returned by MongoDB view “MongoSphinxIndex/couchrests_by_timestamp”.
Sample:
rows = [{ 'name' => 'John', 'phone' => '199 43828',
'classname' => 'Address', '_id' => 'Address-234164'
},
{ 'name' => 'Sue', 'mobile' => '828 19439',
'classname' => 'Address', '_id' => 'Address-422433'
}
]
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="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>
<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>
<classname>Address</classname>
<name><![CDATA[[Sue]]></name>
<phone><![CDATA[[]]></phone>
<mobile><![CDATA[[828 19439]]></mobile>
<created_at><![CDATA[[]]></created_at>
</sphinx:document>
</sphinx:docset>"