DBIx::Class::PhoneticSearch - Phonetic search with DBIC


DBIx-Class-PhoneticSearch documentation  | view source Contained in the DBIx-Class-PhoneticSearch distribution.

Index


NAME

Top

DBIx::Class::PhoneticSearch - Phonetic search with DBIC

SYNOPSIS

Top

    package MySchema::User;

    use base 'DBIx::Class';

    __PACKAGE__->load_components(qw(PhoneticSearch Core));

    __PACKAGE__->table('user');

    __PACKAGE__->add_columns(
      id       => { data_type => 'integer', auto_increment => 1, },
      surname  => { data_type => 'character varying', 
                    phonetic_search => 1 },
      forename => { data_type => 'character varying', 
                    phonetic_search => { algorithm => 'Koeln', 
                                         no_indices => 1 } },

    );

    __PACKAGE__->set_primary_key('id');

    __PACKAGE__->resultset_class('DBIx::Class::ResultSet::PhoneticSearch');

    


  # somewhere else
  $rs = $schema->resultset('User');
  $rs->create({ forename => 'John', surname => 'Night' });

  $rs->search_phonetic({ forename => 'Jon' })->first->forename;  # John
  $rs->search_phonetic({ surname => 'Knight' })->first->surname; # Night
  $rs->search_phonetic({ forename => 'Jon', 
                         surname => 'Knight' })->first->surname; # Night
  $rs->search_phonetic([ surname => 'Smith' ,
                         surname => 'Knight' ])->first->surname; # Night (ORed)

    





DESCRIPTION

Top

This components allows for phonetic search of columns. If you add the phonetic_search attribute to a column, this component will add an extra column to the result class which is basically an index of the value based on its pronunciation. Every time the column is updated, the phonetic column is set as well. It uses Text::Phonetic to compute the phonetic representation of the value in that column. Use search_phonetic to search for rows which sound similar to a given value.

The name of the phonetic column consists of the original column name and the algorithm used:

  $column + _phonetic_ + $algorithm

The above example will require two additional columns:

  surname_phonetic_phonix character varying,
  forename_phonetic_koeln character varying,

Make sure they exist in you database!

The default algorithm is Text::Phonetic::Phonix.

This component will also add indices for both the column and the phonetic column. This can be disabled by setting no_indices.

To set the phonetic column on an already populated resultset use update_phonetic_columns.

RESULTSET METHODS

Top

search_phonetic

This method is used to search a resultset for a given set of column/value pairs.

You can call this method with either an arrayref or hashref. Arrayref will cause a query which will join the queries with OR. A hashref will join them with an AND.

Returns a DBIx::Class::ResultSet.

update_phonetic_column

  $rs->update_phonetic_column('columnname');

This method will update the phonetic column of a column.

update_phonetic_columns

Calls update_phonetic_column for each column with an phonetic column.

ADVANCED CONFIGURATION

Top

algorithm

Choose one of DaitchMokotoff DoubleMetaphone Koeln Metaphone Phonem Phonix Soundex SoundexNara.

See Text::Phonetic for more details.

Defaults to Phonix.

no_indices

By default this module will create indices on both the source column and the phonetic column. Set this attribute to a true value to disable this behaviour.

OVERWRITTEN RESULT METHODS

Top

register_column

Set up the environment and add the phonetic columns.

store_column

Set the phonetic column to the encoded value.

sqlt_deploy_hook

This is where the indices are created.

AUTHOR

Top

Moritz Onken, <onken at netcubed.de>

BUGS

Top

Please report any bugs or feature requests to bug-dbix-class-phoneticsearch at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=DBIx-Class-PhoneticSearch. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

Top

You can find documentation for this module with the perldoc command.

    perldoc DBIx::Class::PhoneticSearch




You can also look for information at:

* RT: CPAN's request tracker

http://rt.cpan.org/NoAuth/Bugs.html?Dist=DBIx-Class-PhoneticSearch

* AnnoCPAN: Annotated CPAN documentation

http://annocpan.org/dist/DBIx-Class-PhoneticSearch

* CPAN Ratings

http://cpanratings.perl.org/d/DBIx-Class-PhoneticSearch

* Search CPAN

http://search.cpan.org/dist/DBIx-Class-PhoneticSearch/

COPYRIGHT & LICENSE

Top


DBIx-Class-PhoneticSearch documentation  | view source Contained in the DBIx-Class-PhoneticSearch distribution.