Module: DataMapper::Adapters::Sphinx::XmlPipe2::ClassMethods
- Defined in:
- lib/dm-sphinx-adapter/xmlpipe2.rb
Instance Method Summary collapse
-
#xmlpipe2(source, destination = :default, query = {}) ⇒ Object
Write a Sphinx xmlpipe2 XML stream to $stdout.
Instance Method Details
#xmlpipe2(source, destination = :default, query = {}) ⇒ Object
Write a Sphinx xmlpipe2 XML stream to $stdout.
Parameters
- source<String>
-
The name of the repository to stream from.
- destination<String>
-
The name of the repository to stream to (contains your sphinx definition).
- query<Hash>
-
The conditions with which to find the records to stream.
– TODO:
-
in_memory_adapter doesn’t call the super constructor so there is no field_naming_convention set in
DataMapper 0.9.10. Submit a patch or live with rescue and field.name clause?
-
Keys that aren’t called .id?
-
Composite keys?
-
Method for schema and documents.
-
Less poking round in the internals of the :default adapter if I can?
-
Destination should always be a dm-sphinx-adapter adapter.
-
Optional schema since it overrides any schema you might define in the sphinx configuration.
-
Schema default values from DM property default values.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/dm-sphinx-adapter/xmlpipe2.rb', line 41 def xmlpipe2(source, destination = :default, query = {}) builder = Builder::XmlMarkup.new(:target => $stdout) builder.instruct! builder.sphinx(:docset, :'xmlns:sphinx' => 'sphinx') do builder.sphinx(:schema) do sphinx_fields(destination).each do |field| builder.sphinx(:field, :name => (field.field(destination) rescue field.name)) end sphinx_attributes(destination).each do |attr| builder.sphinx(:attr, { :name => (attr.field(destination) rescue attr.name), :type => xmlpipe2_type(attr.primitive) }) end end all(query.merge(:repository => repository(source))).map do |resource| builder.sphinx(:document, :id => resource.id) do |document| properties(destination).each do |property| # TODO: Pretty sure this isn't the correct way to get and typecast. builder.tag!((property.field(destination) rescue property.name)) do |field| field.cdata!(property.typecast(property.get(resource))) end end end end end end |