SWISH::API::Remote::Result - Represents a single 'hit' from swished


SWISH-API-Remote documentation Contained in the SWISH-API-Remote distribution.

Index


Code Index:

NAME

Top

SWISH::API::Remote::Result - Represents a single 'hit' from swished

DESCRIPTION

Top

Performs searches on a remote swished server using an interface similar to SWISH::API

my @properties = $result->Properties();

returns a sorted list of the properties fetched for the result.

my $value = $result->Property('swishtitle');

returns a the named property.

SEE ALSO

Top

SWISH::API::Remote::Results, SWISH::API::Remote, swish-e

AUTHOR

Top

Josh Rabinowitz, <joshr@localdomain>

COPYRIGHT AND LICENSE

Top


SWISH-API-Remote documentation Contained in the SWISH-API-Remote distribution.

package SWISH::API::Remote::Result;
use SWISH::API::Remote::FunctionGenerator;
use URI::Escape;
use fields qw( properties );
use strict;
use warnings;

############################################
sub new {
    my $proto = shift;
    my $class = ref($proto) || $proto;
    my $self  = {};
    bless( $self, $class );
    $self->{properties} = {};    # empty hash
    return $self;
}

############################################
sub New_From_Query_String {
    my ( $qs, $resultsprops ) = @_;
    my $newobj = new SWISH::API::Remote::Result;
    my @parts = split ( /&/, $qs );
    for my $p (@parts) {
        my ( $n, $v ) = map { uri_unescape($_) } split ( /=/, $p, 2 );	# split, THEN unescape
        $resultsprops->[$n] = "Unknown$n" unless defined( $resultsprops->[$n] ); 
        #warn "Property number $n ( $resultsprops->[$n] ) : value $v\n";
		if (defined($n)) {
			$newobj->{properties}{ $resultsprops->[$n] } = $v || "";
		}
    }

    #print Data::Dumper::Dumper($newobj);
    return $newobj;
}

############################################
sub Property {
    my ( $self, $prop ) = @_; 
    #print "Looking up property $prop\n";
    return exists( $self->{properties} ) ? $self->{properties}{$prop} : "";
}

############################################
sub Properties {
	my $self = shift;
	return sort(keys( %{ $self->{properties} } ));	# we sort so the order is consistent
}

1;

__END__