WebService::Lucene::Field - Object to represent a field in a document


WebService-Lucene documentation Contained in the WebService-Lucene distribution.

Index


Code Index:

NAME

Top

WebService::Lucene::Field - Object to represent a field in a document

SYNOPSIS

Top

    $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'
    );

DESCRIPTION

Top

METHODS

Top

new( $options )

Creates a new field object from the options provided.

types( )

Returns the types of fields available.

text( $name => $value )

Create a new text field.

keyword( $name => $value )

Create a new keyword field.

unindexed( $name => $value )

Creates a new unindexed field.

unstored( $name => $value )

Creates a new unstored field.

sorted( $name => $value )

Creates a new sorted field.

_new_as( $type, $name => $value )

A shorter way to generate a field object.

is_stored( )

Will the field be stored in the index?

is_indexed( )

Will the field be indexed?

is_tokenized( )

Will the field be tokenized in the index?

get_info( [$type] )

Returns a hashref of info for the current or specified type.

get_type( $info )

Given a hashref of information (stored, indexed, tokenzied) it will return the type of field.

name( [$name] )

Accessor for the field name.

value( [$value] )

Accessor for the field value.

type( [$type] )

Accessor for the field type.

AUTHORS

Top

* Brian Cassidy <brian.cassidy@nald.ca>
* Adam Paynter <adam.paynter@nald.ca>

COPYRIGHT AND LICENSE

Top


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;