| WebService-Lucene documentation | Contained in the WebService-Lucene distribution. |
WebService::Lucene::Field - Object to represent a field in a document
$field = WebService::Lucene::Field->new( {
name => 'foo',
value => 'bar',
type => 'text'
} );
# or via the 'text' method
$field = WebService::Lucene::Field->text(
name => 'foo',
value => 'bar'
);
Creates a new field object from the options provided.
Returns the types of fields available.
Create a new text field.
Create a new keyword field.
Creates a new unindexed field.
Creates a new unstored field.
Creates a new sorted field.
A shorter way to generate a field object.
Will the field be stored in the index?
Will the field be indexed?
Will the field be tokenized in the index?
Returns a hashref of info for the current or specified type.
Given a hashref of information (stored, indexed, tokenzied) it will return the type of field.
Accessor for the field name.
Accessor for the field value.
Accessor for the field type.
Copyright 2006-2009 National Adult Literacy Database
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
| WebService-Lucene documentation | Contained in the WebService-Lucene distribution. |
package WebService::Lucene::Field; use strict; use warnings; use base qw( Class::Accessor::Fast ); my %info = ( text => { stored => 1, indexed => 1, tokenized => 1 }, keyword => { stored => 1, indexed => 1, tokenized => 0 }, unindexed => { stored => 1, indexed => 0, tokenized => 0 }, unstored => { stored => 0, indexed => 1, tokenized => 1 }, sorted => { stored => 0, indexed => 1, tokenized => 0 } ); __PACKAGE__->mk_accessors( qw( name value type ) );
sub types { return keys %info; }
sub text { return shift->_new_as( 'text', @_ ); }
sub keyword { return shift->_new_as( 'keyword', @_ ); }
sub unindexed { return shift->_new_as( 'unindexed', @_ ); }
sub unstored { return shift->_new_as( 'unstored', @_ ); }
sub sorted { return shift->_new_as( 'sorted', @_ ); }
sub _new_as { return shift->new( { type => shift, name => shift, value => shift } ); }
sub is_stored { return $info{ shift->type }->{ stored }; }
sub is_indexed { return $info{ shift->type }->{ indexed }; }
sub is_tokenized { return $info{ shift->type }->{ tokenized }; }
sub get_info { my ( $self, $type ) = @_; $type ||= $self->type; return $info{ $type }; }
sub get_type { my ( $class, $args ) = @_; for my $type ( keys %info ) { my $data = $info{ $type }; my $match = 1; for ( keys %$data ) { $match = 0 && last unless !( $data->{ $_ } ^ ( $args->{ $_ } || 0 ) ); } return $type if $match; } }
1;