Skip Menu |

This queue is for tickets about the WebService-Solr CPAN distribution.

Report information
The Basics
Id: 45798
Status: resolved
Priority: 0/
Queue: WebService-Solr

People
Owner: Nobody in particular
Requestors: gstead [...] cox.net
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 0.05
Fixed in: 0.05



Subject: adding autoSuggest support to WebService-Solr
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. best regards, -Graham { # 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 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; } }
On Wed May 06 21:35:09 2009, gstead@cox.net wrote: Show quoted text
> 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. Show quoted text
> 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. -Brian
Subject: Re: [rt.cpan.org #45798] adding autoSuggest support to WebService-Solr
Date: Thu, 07 May 2009 08:04:37 -0700
To: bug-WebService-Solr [...] rt.cpan.org
From: Graham Stead <gstead [...] cox.net>
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
Version 0.06 has been sent to PAUSE with the following changelog entries: 0.06 Thu May 07 2009 - Add auto_suggest to hit the new Solr 1.4 /autoSuggest API (RT #45798) - Refactor a basic GET request into its own public method (generic_solr_request)
Subject: Re: [rt.cpan.org #45798] adding autoSuggest support to WebService-Solr
Date: Thu, 07 May 2009 11:47:27 -0700
To: bug-WebService-Solr [...] rt.cpan.org
From: Graham Stead <gstead [...] cox.net>
Looks fantastic. Will be happy to test and play with 0.06 as soon as the change hits CPAN. best, -Graham