Apache-Solr

 view release on metacpan or  search on metacpan

ChangeLog  view on Meta::CPAN


version 1.04: Mon 23 May 09:24:40 CEST 2016

	Fixes:
	- regression test fails on hash randomization [cpantesters]
	  rt.cpan.org#114542 [Slaven Rezic]

version 1.03: Sat 21 May 09:32:33 CEST 2016

	Fixes:
	- expandSelect() over-eager to protect generic configuration
	  flags to be used as specific field flags.  [Mark Elrod]

version 1.02: Tue Mar  8 19:47:39 CET 2016

	Fixes:
	- implement the update attribute [Mark Elrod]
	- boost float accept rounding error.

version 1.01: Thu Dec 11 15:54:03 CET 2014

ChangeLog  view on Meta::CPAN

version 0.97: Fri Nov 15 15:11:30 CET 2013

	Changes:
	- undefined value for boolean becomes 'missing', not 'false'
	  [Andrew Beverley]

	Fixes:
	- handling result without hits.

	Improvements:
	- expandExtract() accepts SCALAR
	- ignore fields with undefined content

version 0.96: Thu Oct 10 15:42:25 CEST 2013
	Improvements:
	- adding a few new configuration fields, from 4.0.0 -> 4.5

version 0.95: Fri Feb  1 16:47:38 CET 2013
	Fixes:
	- ::Result::selected() deep recursion.

	Improvements:
	- new ::Result::nextSelected()
	- ::Result::selected() does not need the optional $solr object anymore

version 0.94: Thu Jan 31 15:12:34 CET 2013
	Fixes:
	- extractDocument(string) did not work.

	Improvements:
	- catch and check deprecation warning in t/12facet.t
	- accept parameter hashes for fmap, resource and boost in expandExtract
	- honour autocommit in extractDocument()
	- the user agent will be default be shared when multiple Solr objects
	  are created.
	- do not die on HTML answers: put it in $result->success
	- add \n to ::Results::errors()
	- add ::coreStatus, ::coreReload, and ::coreUnload

version 0.93: Wed Jan 30 15:53:08 CET 2013
	Improvements:
	- support perl pre-5.10 by removal single use of //
	- ::Document::boost() now also for fields
	- further documentation improvements
	- much better error reporting, use $result->errors()
	- surpress early warning about connection errors.
	- take filename from extractDocument() even if the data is
	  specified as string.
	- extended the power of expandExtract()

version 0.92: Thu Dec  6 09:48:18 CET 2012
	- fix delete()
	- no multiple deletes in JSON available (it seems)
	- implement extractDocument()
	- avoid added wt=> for select more than one

version 0.91: Tue Dec  4 09:41:10 CET 2012
	- ::Document field lookups by hash, not grep.
	- ::Result::selected() returns ::Document, not HASH.  Then, ask

MANIFEST  view on Meta::CPAN

lib/Apache/Solr/Document.pod
lib/Apache/Solr/JSON.pm
lib/Apache/Solr/JSON.pod
lib/Apache/Solr/Result.pm
lib/Apache/Solr/Result.pod
lib/Apache/Solr/Tables.pm
lib/Apache/Solr/XML.pm
lib/Apache/Solr/XML.pod
t/01use.t
t/10endpoint.t
t/11expand.t
t/12facet.t
t/20xml.t
t/21json.t
t/30result.t
t/31sequential.t
t/32version.t
t/a.pdf
META.yml                                 Module YAML meta-data (added by MakeMaker)
META.json                                Module JSON meta-data (added by MakeMaker)

lib/Apache/Solr.pm  view on Meta::CPAN

		unless blessed $uri && $uri->isa('URI');
	$self->{AS_server} = $uri;
}


#--------------------------

sub select(@)
{	my $self = shift;
	my $args = @_ && ref $_[0] eq 'HASH' ? shift : {};
	$self->_select($args, scalar $self->expandSelect(@_));
}
sub _select($$) {panic "not extended"}


sub queryTerms(@)
{	my $self  = shift;
	$self->_terms(scalar $self->expandTerms(@_));
}
sub _terms(@) {panic "not implemented"}

#-------------------------------------

sub addDocument($%)
{	my ($self, $docs, %args) = @_;
	$docs  = [ $docs ] if ref $docs ne 'ARRAY';

	my $sv = $self->serverVersion;

lib/Apache/Solr.pm  view on Meta::CPAN

	$self->_rollback;
}


sub extractDocument(@)
{	my $self  = shift;

	$self->serverVersion ge '1.4'
		or error __x"extractDocument() requires Solr v1.4 or higher";
		
	my %p   = $self->expandExtract(@_);
	my $data;

	# expand* changes '_' into '.'
	my $ct  = delete $p{'content.type'};
	my $fn  = delete $p{file};
	$p{'resource.name'} ||= $fn if $fn && !ref $fn;

	$p{commit} = _to_bool $self->autocommit
		unless exists $p{commit};

	if(defined $p{string})
	{	# try to avoid copying the data, which can be huge
		$data = $ct =~ m!^text/!i

lib/Apache/Solr.pm  view on Meta::CPAN

			next;
		}

		push @t, $k => $boolparams{$param} ? _to_bool($_) : $_
			for ref $v eq 'ARRAY' ? @$v : $v;
	}
	@t;
}


sub expandTerms(@)
{	my $self = shift;
	my $p = @_==1 ? shift : [@_];
	my @t = $self->_simpleExpand($p, 'terms.');
	wantarray ? @t : \@t;
}


sub _expand_flatten($$)
{	my ($self, $v, $prefix) = @_;
	my @l = ref $v eq 'HASH' ? %$v : @$v;
	my @s;
	push @s, $prefix.(shift @l) => (shift @l) while @l;
	@s;
}

sub expandExtract(@)
{	my $self = shift;
	my @p = @_==1 ? @{(shift)} : @_;
	my @s;
	while(@p)
	{	my ($k, $v) = (shift @p, shift @p);
		if(!ref $v || ref $v eq 'SCALAR')
			 { push @s, $k => $v }
		elsif($k eq 'literal' || $k eq 'literals')
			 { push @s, $self->_expand_flatten($v, 'literal.') }
		elsif($k eq 'fmap' || $k eq 'boost' || $k eq 'resource')
			 { push @s, $self->_expand_flatten($v, "$k.") }
		else { panic "unknown set '$k'" }
	}

	my @t = @s ? $self->_simpleExpand(\@s) : ();
	wantarray ? @t : \@t;
}


# probably more config later, currently only one column
# "also-per-field" means, not only $set.$more, but also f.$field.$set.$more
my %sets =   #also-per-field?
  ( expand  => [0]
  , facet   => [1]
  , hl      => [1]
  , mlt     => [0]
  , stats   => [0]
  , suggest => [0]
  , group   => [0]
  );
 
sub expandSelect(@)
{	my $self = shift;
	my @s;
	my (@flat, %seen_set);
	while(@_)
	{	my ($k, $v) = (shift, shift);
		$k =~ s/_/./g;
		my @p = split /\./, $k;

		# fields are $set.$more or f.$field.$set.$more
		my $per_field    = $p[0] eq 'f' && @p > 2;

lib/Apache/Solr.pod  view on Meta::CPAN

=head2 Commands

=head3 Search

=over 4

=item $obj-E<gt>B<queryTerms>($terms)

Search for often used terms. See F<http://wiki.apache.org/solr/TermsComponent>

$terms are passed to L<expandTerms()|Apache::Solr/"Parameter pre-processing"> before being used.

B<Be warned:> The result is not sorted when XML communication is used,
even when you explicitly request it.

example: 

  my $r = $self->queryTerms(fl => 'subject', limit => 100);
  if($r->success)
  {    foreach my $hit ($r->terms('subject'))
      {    my ($term, $count) = @$hit;

lib/Apache/Solr.pod  view on Meta::CPAN

  }

  if(my $r = $self->queryTerms(fl => 'subject', limit => 100))
     ...

=item $obj-E<gt>B<select>( [\%options], @parameters )

Find information in the document collection.

This method has a HUGE number of parameters.  These values are passed in
the uri of the http query to the solr server.  See L<expandSelect()|Apache::Solr/"Parameter pre-processing"> for
all the simplifications offered here.  Sets of there parameters
may need configuration help in the server as well.

[1.06] You may pass some options to process the selected results (the
L<Apache::Solr::Result|Apache::Solr::Result> object initiation).  For instance, C<sequential>.
For backwards compatability reasons, they have to be passed in a HASH
as optional first parameter.

=back

lib/Apache/Solr.pod  view on Meta::CPAN


=back

=over 4

=item $obj-E<gt>B<deprecated>($message)

Produce a warning $message about deprecated parameters with the
indicated server version.

=item $obj-E<gt>B<expandExtract>(PAIRS|ARRAY)

Used by L<extractDocument()|Apache::Solr/"Updates">.

[0.93] If the key is C<literal> or C<literals>, then the keys in the
value HASH (or ARRAY of PAIRS) get 'literal.' prepended.  "Literals"
are fields you add yourself to the SolrCEL output.  Unless C<extractOnly>,
you need to specify the 'id' literal.

[0.94] You can also use C<fmap>, C<boost>, and C<resource> with an
HASH (or ARRAY-of-PAIRS).  [0.97] the value in each PAIR may be a SCALAR

lib/Apache/Solr.pod  view on Meta::CPAN


example: 

  my $result = $solr->extractDocument(string => $document,
      resource_name => $fn, extractOnly => 1,
      literals => { id => 5, b => 'tic' }, literal_xyz => 42,
      fmap => { id => 'doc_id' }, fmap_subject => 'mysubject',
      boost => { abc => 3.5 }, boost_xyz => 2.0
  );

=item $obj-E<gt>B<expandSelect>(PAIRS)

The L<select()|Apache::Solr/"Search"> method accepts many, many parameters.  These are passed
to modules in the server, which need configuration before being usable.

Besides the common parameters, like 'q' (query) and 'rows', there
are parameters for various (pluggable) backends, usually prefixed
by the backend abbreviation.

=over 4

=item * expand

=item * facet -> F<http://wiki.apache.org/solr/SimpleFacetParameters>

=item * hl (highlight) -> F<http://wiki.apache.org/solr/HighlightingParameters>

=item * mlt -> F<https://solr.apache.org/guide/8_11/morelikethis.html>

=item * stats -> F<http://wiki.apache.org/solr/StatsComponent>

=item * suggest -> F<https://solr.apache.org/guide/8_11/suggester.html>

=item * group -> F<http://wiki.apache.org/solr/FieldCollapsing>

=back

You may use WebService::Solr::Query to construct the query ('q').

example: 

  my @r = $solr->expandSelect(
      q => 'inStock:true', rows => 10,
      facet => {limit => -1, field => [qw/cat inStock/], mincount => 1},
      f_cat_facet => {missing => 1},
      hl    => {},
      mlt   => { fl => 'manu,cat', mindf => 1, mintf => 1 },
      stats => { field => [ 'price', 'popularity' ] },
      group => { query => 'price:[0 TO 99.99]', limit => 3 },
  );

  # becomes (one line)
  ...?rows=10&q=inStock:true
    &facet=true&facet.limit=-1&facet.field=cat
       &f.cat.facet.missing=true&facet.mincount=1&facet.field=inStock
    &mlt=true&mlt.fl=manu,cat&mlt.mindf=1&mlt.mintf=1
    &stats=true&stats.field=price&stats.field=popularity
    &group=true&group.query=price:[0+TO+99.99]&group.limit=3

=item $obj-E<gt>B<expandTerms>(PAIRS|ARRAY)

Used by L<queryTerms()|Apache::Solr/"Search"> only.

example: 

  my @t = $solr->expandTerms('terms.lower.incl' => 'true');
  my @t = $solr->expandTerms([lower_incl => 1]);   # same

  my $r = $self->queryTerms(fl => 'subject', limit => 100);

=item $obj-E<gt>B<ignored>($message)

Produce a warning $message about parameters which will get ignored
because they were not yet supported by the indicated server version.

=item $obj-E<gt>B<removed>($message)

lib/Apache/Solr/Result.pod  view on Meta::CPAN

The URI where the request is sent to.

=item $obj-E<gt>B<errors>()

All errors collected by this object into one string.

=item $obj-E<gt>B<httpError>()

=item $obj-E<gt>B<params>()

List of (expanded) parameters used to call the solr server.

=item $obj-E<gt>B<request>( [$request] )

Set/get the HTTP::Request object used in this query.

=item $obj-E<gt>B<response>( [$response] )

Set/get the HTTP::Response object received from this query action.

=item $obj-E<gt>B<sequential>()

lib/Apache/Solr/Tables.pm  view on Meta::CPAN

collectElevatedDocsWhenCollapsing
commit
debug
debug.explain.structured
docValues
echoHandler
elevateOnlyDocsMatchingQuery
enableElevation
exactMatchFirst
exclusive
expand
expand.nullGroup
exactMatchFirst
extractOnly
facet
facet.contains.ignoreCase
facet.date.hardend
facet.exists
facet.missing
facet.range.hardend
facet.zeros
forceElevation

t/11expand.t  view on Meta::CPAN

# the server will not be called in this script.
my $server = 'http://localhost:8080/solr';
my $core   = 'my-core';

my $solr = Apache::Solr->new(server => $server, core => $core);
ok(defined $solr, 'instantiated client');
isa_ok($solr, 'Apache::Solr');

### Expansion of facets tested in t/12facet.t

### expandTerms

my @t = $solr->expandTerms(fl => 'subject', limit => 100
  , mincount => 5, 'terms.maxcount' => 10, raw => 1, raw => 0
  , lower_incl => 1, terms_upper_incl => 0
  , prefix => 'at', regex => 'a.*b');

is(join("\n",@t,''), <<_EXPECT, 'test term expansion');
terms.fl
subject
terms.limit
100
terms.mincount

t/11expand.t  view on Meta::CPAN

terms.lower.incl
true
terms.upper.incl
false
terms.prefix
at
terms.regex
a.*b
_EXPECT

###### expandExtract

my @t2 = $solr->expandExtract(a => 1, extractOnly => 1
  , 'literal.id' => 5, literal => { b => 'tic' }, literals => { c => 'tac' }
  , literal_xyz => 42
  , fmap => { id => 'doc_id' }, fmap_subject => 'mysubject'
  , boost => { abc => 3.5 }, boost_xyz => 2.0
);
is(join("\n",@t2,''), <<_EXPECT, 'test extract expansion');
a
1
extractOnly
true

t/11expand.t  view on Meta::CPAN

fmap.id
doc_id
fmap.subject
mysubject
boost.abc
3.5
boost.xyz
2
_EXPECT

### expandSelect

my @t3 = $solr->expandSelect
  ( q => 'inStock:true', rows => 10
  , facet => {limit => -1, field => [qw/cat inStock/], mincount => 1}
  , f_cat_facet => {missing => 1}
  , hl    => {}
  , mlt   => { fl => 'manu,cat', mindf => 1, mintf => 1 }
  , stats => { field => [ 'price', 'popularity' ] }
  , group => { query => 'price:[0 TO 99.99]', limit => 3 }
  );

my @t3b;

t/12facet.t  view on Meta::CPAN


sub check_get($$$)
{   my ($url, $params, $test) = @_;

    # take the parameters from the url
    $url =~ s/.*\?//;
    my @url = map { split /\=/, $_, 2 } split /\&/, $url;
    s/\+/ /g,s/%([a-zA-Z0-9]{2})/chr hex $1/ge for @url;

    # the order may be important, but ignored for these tests
    my $expanded = $solr->expandSelect(%$params);
#warn Dumper \@url, $expanded;
    is_deeply({@url}, {@$expanded}, $test);
}

### Facet Fields

check_get
   "$server/select?q=ipod&rows=0&facet=true&facet.limit=-1&facet.field=cat&facet.field=inStock",
  { q => 'ipod', rows => 0
  , facet => { limit => -1, field => [ qw/cat inStock/ ] }
  }, 'example 1 get';



( run in 1.840 second using v1.01-cache-2.11-cpan-5623c5533a1 )