Brian Cassidy via RT wrote:
Show quoted text> <URL:
https://rt.cpan.org/Ticket/Display.html?id=45798 >
>
> On Wed May 06 21:35:09 2009, gstead@cox.net wrote:
>
>> Solr 1.4 provides access to Terms via TermsComponent. This allows for
>> simple autocomplete functionality, which can be quite handy. A
>> high-level approach is described here:
>>
http://www.mattweber.org/2009/05/02/solr-autosuggest-with-
>> termscomponent-and-jquery/
>>
>> WebService-Solr does not support this call, yet the logic is extremely
>> similar to search, the main difference being the path /autoSuggest
>> instead of /search.
>>
>> To support autoSuggest, we created the following hack for
>> WebService-Solr. I'm sending it along for incorporation into Solr.pm,
>> allowing others to take advantage of this feature. If you have any
>> questions/comments or need me to do 1.4 testing, just let me know.
>>
>
> Honestly, I'm not too keen on releasing functionality that may be a
> moving target (i.e. Solr 1.4 isn't "official" yet). Though this addition
> is pretty simple, so I think we can make an exception.
>
>
>> sub autoSuggest {
>> my ( $self, $query, $params ) = @_;
>> $params ||= {};
>> $params->{'q'} = $query;
>> my $response = WebService::Solr::Response->new(
>> $self->agent->get( $self->_gen_url( 'autoSuggest', $params
>> )
>> ) );
>> return $response;
>> }
>>
>
> A few comments about this "patch":
>
> * I will likely rename it to auto_suggest as it is in like with the Perl
> style
> * is the $query param necessary here? In the example you've linked, it
> doesn't use "q" in the parameters at all.
>
> I'll await your reply before proceeding.
>
You're exactly right, the q param is not used for autoSuggest queries.
The user would normally assign a query to terms.lower and terms.prefix
(in $params) before invoking the call. They're still there because we
literally copied sub search and changed the path.
To confirm, this adjusted code also runs fine:
{
# monkey patching
# we need this, because WebService::Solr don't have this
# may be, on some day, this method will appear in WebService::Solr,
# and so we will be needed to delete this hacking
package WebService::Solr;
sub auto_suggest {
my ( $self, $params ) = @_;
$params ||= {};
my $response = WebService::Solr::Response->new(
$self->agent->get( $self->_gen_url( 'autoSuggest', $params )
) );
return $response;
}
}
It also makes me wonder if there should be a vanilla caller, a bit like
this:
sub generic_solr_request {
my ( $self, $path, $params ) = @_;
$params ||= {};
my $response = WebService::Solr::Response->new(
$self->agent->get( $self->_gen_url( $path, $params ) ) );
return $response;
}
Then we could access other Solr features by naming the path and params.
E.g., I also use the data import handler, which is
/dataimport?command=full-import, /dataimport?command=delta-import, or
similar. Just a thought! You're in control, I'm just throwing out ideas...
best regards,
-Graham