| 1 | package OpenInteract2::FullTextRules; | ||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||
| 3 | # $Id: FullTextRules.pm,v 1.4 2005/03/18 04:09:48 lachoy Exp $ | ||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use Log::Log4perl qw( get_logger ); | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use OpenInteract2::Constants qw( :log ); | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use OpenInteract2::Context qw( CTX ); | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||
| 10 | 1 | $OpenInteract2::FullTextRules::VERSION = sprintf("%d.%02d", q$Revision: 1.4 $ =~ /(\d+)\.(\d+)/); | |||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||
| 12 | 1 | my ( $log ); | |||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||
| 14 | ######################################## | ||||||||||||||||||||||||||||||||||||
| 15 | # RULESET METHODS | ||||||||||||||||||||||||||||||||||||
| 16 | ######################################## | ||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||
| 18 | # Add the various group checking/validating methods | ||||||||||||||||||||||||||||||||||||
| 19 | # to the subclass and send it on up the line | ||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||
| 21 | 0 | ▶ | sub ruleset_factory { | ||||||||||||||||||||||||||||||||||
|
Subroutine
ruleset_factory: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||
| 22 | 0 | my ( $class, $rs_table ) = @_; | |||||||||||||||||||||||||||||||||||
| 23 | 0 | ▶ | $log ||= get_logger( LOG_APP ); | ||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$log ||= get_logger("OI2.APP")
MC/DC0%0/2
$log ||= get_logger("OI2.APP")
$log
get_logger("OI2.APP")
Truth table0%0/3
A ||= B
A= $logB= get_logger("OI2.APP")
| |||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||
| 25 | 0 | ▶ | my $obj_class = ref $class || $class; | ||||||||||||||||||||||||||||||||||
|
Condition0%0/3
ref $class || $class
MC/DC0%0/2
ref $class || $class
ref $class
$class
Truth table0%0/3
A || B
A= ref $classB= $class
| |||||||||||||||||||||||||||||||||||||
| 26 | 0 | push @{ $rs_table->{post_save_action} }, \&reindex_object; | |||||||||||||||||||||||||||||||||||
| 27 | 0 | push @{ $rs_table->{post_remove_action} }, \&remove_object_from_index; | |||||||||||||||||||||||||||||||||||
| 28 | 0 | ▶ | $log->is_debug && | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 29 | $log->debug( "Full-text indexing capability installed for '$obj_class'" ); | ||||||||||||||||||||||||||||||||||||
| 30 | 0 | return __PACKAGE__; | |||||||||||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||
| 34 | # Remove the previous object information from the index, tokenize the | ||||||||||||||||||||||||||||||||||||
| 35 | # object and save the tokens/frequences back to the index. | ||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||
| 37 | 0 | ▶ | sub reindex_object { | ||||||||||||||||||||||||||||||||||
|
Subroutine
reindex_object: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||
| 38 | 0 | my ( $self, $p ) = @_; | |||||||||||||||||||||||||||||||||||
| 39 | 0 | ▶ | $log ||= get_logger( LOG_APP ); | ||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$log ||= get_logger("OI2.APP")
MC/DC0%0/2
$log ||= get_logger("OI2.APP")
$log
get_logger("OI2.APP")
Truth table0%0/3
A ||= B
A= $logB= get_logger("OI2.APP")
| |||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||
| 41 | 0 | my $class = ref $self; | |||||||||||||||||||||||||||||||||||
| 42 | 0 | my $id = $self->id; | |||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||
| 44 | 0 | ▶ | $log->is_info && $log->info( "Indexing [$class: $id]" ); | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 45 | 0 | my $indexable = $self->_indexable_object_text( $p ); | |||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||
| 47 | 0 | my $indexer = CTX->fulltext_indexer; | |||||||||||||||||||||||||||||||||||
| 48 | 0 | $indexer->refresh_index( $class, $id, $indexable ); | |||||||||||||||||||||||||||||||||||
| 49 | 0 | return 1; | |||||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||
| 53 | # Remove all instances of the object's terms from the index. | ||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||
| 55 | 0 | ▶ | sub remove_object_from_index { | ||||||||||||||||||||||||||||||||||
|
Subroutine
remove_object_from_index: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||
| 56 | 0 | my ( $self, $p ) = @_; | |||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||
| 58 | 0 | my $class = ref $self; | |||||||||||||||||||||||||||||||||||
| 59 | 0 | my $id = $self->id; | |||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||
| 61 | 0 | my $indexer = CTX->fulltext_indexer; | |||||||||||||||||||||||||||||||||||
| 62 | 0 | $indexer->remove_from_index( $class, $id ); | |||||||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||
| 66 | ######################################## | ||||||||||||||||||||||||||||||||||||
| 67 | # INTERNAL METHODS | ||||||||||||||||||||||||||||||||||||
| 68 | ######################################## | ||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||
| 71 | # Get the fields that should be indexed and join the values together | ||||||||||||||||||||||||||||||||||||
| 72 | # with a space (easy), since we're just going to index all the text as | ||||||||||||||||||||||||||||||||||||
| 73 | # one big field. Returns a scalar REF. | ||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||
| 75 | 0 | ▶ | sub _indexable_object_text { | ||||||||||||||||||||||||||||||||||
|
Subroutine
_indexable_object_text: not called CC=13 SCAR=52.0
| |||||||||||||||||||||||||||||||||||||
| 76 | 0 | my ( $self, $p ) = @_; | |||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||
| 78 | 0 | ▶ | $p ||= {}; | ||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$p ||= {}
MC/DC0%0/1
$p ||= {}
$p
Truth table0%0/2
A
A= $p
| |||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||
| 80 | 0 | my $class = ref( $self ); | |||||||||||||||||||||||||||||||||||
| 81 | my $field_list = $p->{fulltext_field} | ||||||||||||||||||||||||||||||||||||
| 82 | 0 | ▶ | || $self->CONFIG->{fulltext_field}; | ||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$p->{'fulltext_field'} || $self->CONFIG->{'fulltext_field'}
MC/DC0%0/2
$p->{'fulltext_field'} || $self->CONFIG->{'fulltext_field'}
$p->{'fulltext_field'}
$self->CONFIG->{'fulltext_field'}
Truth table0%0/3
A || B
A= $p->{'fulltext_field'}B= $self->CONFIG->{'fulltext_field'}
| |||||||||||||||||||||||||||||||||||||
| 83 | 0 | ▶ | unless ( ref $field_list eq 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 84 | 0 | $log->error( "Cannot index object text -- no fields presented ", | |||||||||||||||||||||||||||||||||||
| 85 | "in configuration for class '$class' ", | ||||||||||||||||||||||||||||||||||||
| 86 | "in key 'fulltext_field'." ); | ||||||||||||||||||||||||||||||||||||
| 87 | 0 | return undef; | |||||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||
| 90 | $log->is_info && | ||||||||||||||||||||||||||||||||||||
| 91 | $log->info( "Pulling content for indexing from fields ", | ||||||||||||||||||||||||||||||||||||
| 92 | 0 | ▶ | join( ', ', @{ $field_list }, " for class '$class'" ) ); | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||
| 94 | 0 | my $pre_index_method = $self->CONFIG->{fulltext_pre_index_method}; | |||||||||||||||||||||||||||||||||||
| 95 | 0 | ▶ | if ( $pre_index_method ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 96 | 0 | eval { $self->$pre_index_method() }; | |||||||||||||||||||||||||||||||||||
| 97 | 0 | ▶ | if ( $@ ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 98 | 0 | $log->error( "Caught error executing pre-indexing method ", | |||||||||||||||||||||||||||||||||||
| 99 | "'$pre_index_method()' for class '$class': $@" ); | ||||||||||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||||||||||
| 101 | else { | ||||||||||||||||||||||||||||||||||||
| 102 | 0 | ▶ | $log->is_info && | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 103 | $log->info( "Executed pre-indexing method '$pre_index_method' ok" ); | ||||||||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||
| 107 | 0 | my ( $indexable ) = ""; | |||||||||||||||||||||||||||||||||||
| 108 | 0 | foreach my $field ( @{ $field_list } ) { | |||||||||||||||||||||||||||||||||||
| 109 | 0 | ▶ | if ( defined $self->{ $field } and ! ref $self->{ $field } ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition0%0/3
defined $self->{$field} and not ref $self->{$field}
MC/DC0%0/2
defined $self->{$field} and not ref $self->{$field}
defined $self->{$field}
not ref $self->{$field}
Truth table0%0/3
A and not(B)
A= defined $self->{$field}B= not ref $self->{$field}
| |||||||||||||||||||||||||||||||||||||
| 110 | 0 | $indexable = join( ' ', $indexable, $self->{ $field } ); | |||||||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||||||
| 112 | elsif ( ref $self->{ $field } eq 'SCALAR' ) { | ||||||||||||||||||||||||||||||||||||
| 113 | 0 | $indexable = join( ' ', $indexable, $$self->{ $field } ); | |||||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||
| 116 | # This is for 'page' objects that use a filehandle | ||||||||||||||||||||||||||||||||||||
| 117 | elsif ( ref $self->{ $field } eq 'GLOB' ) { | ||||||||||||||||||||||||||||||||||||
| 118 | 0 | my $fh = $self->{ $field }; | |||||||||||||||||||||||||||||||||||
| 119 | 0 | $indexable = join( ' ', $indexable, <$fh> ); | |||||||||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||||||||||
| 121 | else { | ||||||||||||||||||||||||||||||||||||
| 122 | 0 | $log->info( "Cannot index object '$field' (not a SCALAR or GLOB)"); | |||||||||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||||||
| 125 | 0 | return \$indexable; | |||||||||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||
| 128 | 1 | 1; | |||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||
| 130 | __END__ | ||||||||||||||||||||||||||||||||||||