Hey ... I just tried to convert my code to 0.10 .. But i''m currently not sure how to use fields.. i really like some of the new api.. its leaner and i like the fact that these strange consts are gone (like Ferret::Search::BooleanClause::Occur::MUST) .. I see that you''re now having Ferret::Index::FieldInfo to describe the fields of the index.. thats good.. and i now see that documents and fields are much smaller and easier to create.. thats good as well :-) now what i dont get is how to add a field to a document.. i can create a new field or a document, but how to make give the field a name? i would expect something like doc = Document.new fiels = Field.new("my data to be indexed", 1.5) doc.add_field( ''title'', field ) or doc.title = field .. can''t see anything like that in the API though.. Ben
On Wed, Aug 23, 2006 at 08:22:42PM +0200, Benjamin Krause wrote:> Hey ... > > I just tried to convert my code to 0.10 .. But i''m currently not sure > how to use fields.. > > i really like some of the new api.. its leaner and i like the fact that > these strange consts are gone (like > Ferret::Search::BooleanClause::Occur::MUST) .. > > I see that you''re now having Ferret::Index::FieldInfo to describe the > fields of the index.. thats good.. and i now see that documents and > fields are much smaller and easier to create.. thats good as well :-) > > now what i dont get is how to add a field to a document.. i can create a > new field or a document, but how to make give the field a name? i would > expect something like > > doc = Document.new > fiels = Field.new("my data to be indexed", 1.5) > doc.add_field( ''title'', field ) > > or > > doc.title = field .. > > can''t see anything like that in the API though..it''s as easy as doc[:title] = field Jens -- webit! Gesellschaft f?r neue Medien mbH www.webit.de Dipl.-Wirtschaftsingenieur Jens Kr?mer kraemer at webit.de Schnorrstra?e 76 Tel +49 351 46766 0 D-01069 Dresden Fax +49 351 46766 66
On 8/24/06, Jens Kraemer <kraemer at webit.de> wrote:> On Wed, Aug 23, 2006 at 08:22:42PM +0200, Benjamin Krause wrote: > > Hey ... > > > > I just tried to convert my code to 0.10 .. But i''m currently not sure > > how to use fields.. > > > > i really like some of the new api.. its leaner and i like the fact that > > these strange consts are gone (like > > Ferret::Search::BooleanClause::Occur::MUST) .. > > > > I see that you''re now having Ferret::Index::FieldInfo to describe the > > fields of the index.. thats good.. and i now see that documents and > > fields are much smaller and easier to create.. thats good as well :-) > > > > now what i dont get is how to add a field to a document.. i can create a > > new field or a document, but how to make give the field a name? i would > > expect something like > > > > doc = Document.new > > fiels = Field.new("my data to be indexed", 1.5) > > doc.add_field( ''title'', field ) > > > > or > > > > doc.title = field .. > > > > can''t see anything like that in the API though.. > > it''s as easy as doc[:title] = field > > JensJust to clarify. Hashes are the new Documents. If you don''t use the boost field then use a Hash. It''s much simpler. Everyone knows how to use a Hash. index << {:title => "Shawshank Redemption", :tags => ["Drama", "Suspense", "Jail", "Prison"]} In fact if you don''t want to use the Document class at all; class Hash include BoostMixin end doc = {:title => "Shawshank Redemption", :tags => ["Drama", "Suspense", "Jail", "Prison"]} doc.boost = 100.0 NOTE: all fields should now be Symbols. Strings will work in most cases but Symbols are what is expected. They''re much more efficient anyway. I mean to do a big write up explaining the changes but I just don''t have the time right now. Perhaps tomorrow. Cheers, Dave
hey..>> it''s as easy as doc[:title] = fieldthats quite easy.. indeed :)> NOTE: all fields should now be Symbols. Strings will work in most > cases but Symbols are what is expected. They''re much more efficient > anyway.what if i add a field to a doc that was not initialized using fieldinfos? will this be added anyway and just fallback to the default fieldinfos? is there a way to prevent fields from beeing added if there is no fieldinfo definition? And if not, will there be a way? Thanks, Ben
On 8/24/06, Benjamin Krause <bk at benjaminkrause.com> wrote:> hey.. > > >> it''s as easy as doc[:title] = field > > thats quite easy.. indeed :) > > > NOTE: all fields should now be Symbols. Strings will work in most > > cases but Symbols are what is expected. They''re much more efficient > > anyway. > > what if i add a field to a doc that was not initialized using fieldinfos? > will this be added anyway and just fallback to the default fieldinfos? > is there a way to prevent fields from beeing added if there is no > fieldinfo definition? And if not, will there be a way? > > Thanks, > BenGreat question. Another thing I should elloborate on. When you create the FieldInfos object you can set the default fields for any unknown fields you add later. For example fi = FieldInfos.new(:store => :no, :term_vector => :no) # fields are normally stored by default but now we''ve set the default :store # value to :no so we need to explicitly state that we want to store fields; fi.add_fields(:title, :store => :yes, :index => :untokenized) index = Index.new(:field_infos => fi) index << {:title => "asdg", :content => "asdlkgjhasdkgjh"} Cheers, Dave