I ask, because I am trying to implement an autocomplete feature, which
depends on being able to search for terms that start with a given
prefix. It appears that Solr has this feature (via the facet.prefix
parameter):
http://wiki.apache.org/solr/SimpleFacetParameters#facet.prefix
(with an example which illustrates almost exactly what I'm trying to
do: http://wiki.apache.org/solr/SimpleFacetParameters#Facet_prefix_.28term_suggest.29)
It might appear that this behaviour can be obtained in the Sunspot
0.10 release using a "starts_with" query, coupled with faceting on the
field you're searching over. However, if the field has multiple values
(as in my case), then the facet list gets polluted with field values
that you're not interested in. Obviously, I do have a solution which
is to retrieve all facet values, and do some post-processing, however
this seems a shame if there is functionality in Solr to do this.
My experience of Sunspot has been hugely positive. I've found it
tremendously easy to implement, and to work with. Thank you!
Kieran
Not a bad idea - feel free to file a ticket at
http://outoftime.lighthouseapp.com/projects/20339-sunspot/tickets - of
course a patch attached to the ticket would be even better!
To get that functionality right now, you can use the adjust_solr_params method:
Post.search do
facet(:my_field)
adjust_solr_params do |params|
params[:"f.#{Sunspot::Setup.for(Post).field(:my_field).indexed_name}.facet.prefix"]
= "someprefix"
end
end
The above solution interacts with the non-public API so it's
definitely not an ideal solution, but it should work.
Thanks!
Mat
> --
> You received this message because you are subscribed to the Google Groups "Sunspot" group.
> To post to this group, send email to ruby-s...@googlegroups.com.
> To unsubscribe from this group, send email to ruby-sunspot...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/ruby-sunspot?hl=en.
>
>
On Feb 11, 3:42 pm, Mat Brown <m...@patch.com> wrote:
> Hey Kieran,
>
> Not a bad idea - feel free to file a ticket athttp://outoftime.lighthouseapp.com/projects/20339-sunspot/tickets- of
> course a patch attached to the ticket would be even better!
>
> To get that functionality right now, you can use the adjust_solr_params method:
>
> Post.search do
> facet(:my_field)
> adjust_solr_params do |params|
> params[:"f.#{Sunspot::Setup.for(Post).field(:my_field).indexed_name}.facet.prefix"]
> = "someprefix"
> end
> end
>
> The above solution interacts with the non-public API so it's
> definitely not an ideal solution, but it should work.
>
> Thanks!
> Mat
>
>
>
>
>
> On Thu, Feb 11, 2010 at 10:29, Kieran <kierantopp...@gmail.com> wrote:
> > Hi, I'm wondering whether there are any plans for Sunspot to support
> > facet prefixes - i.e. to limit the faceted terms to those starting
> > with a given string prefix?
>
> > I ask, because I am trying to implement an autocomplete feature, which
> > depends on being able to search for terms that start with a given
> > prefix. It appears that Solr has this feature (via the facet.prefix
> > parameter):
>
> >http://wiki.apache.org/solr/SimpleFacetParameters#facet.prefix
>
> > (with an example which illustrates almost exactly what I'm trying to
> > do:http://wiki.apache.org/solr/SimpleFacetParameters#Facet_prefix_.28ter...)
Yep, you're on the right track with that. AbstractFieldFacet also has
a private helper method that will generate the appropriate parameter
key for you.
Mat
Amendment follows (from http://gist.github.com/302130):
query.adjust_solr_params do |params|
params[:"f.#{Sunspot::Setup.for(MyModel).dynamic_field_factory(:custom).build(:my_field).indexed_name}.facet.prefix"]
= my_leading_str
end
Kieran
On Feb 11, 4:38 pm, Mat Brown <m...@patch.com> wrote:
> Hey Kieran,
>
> Yep, you're on the right track with that. AbstractFieldFacet also has
> a private helper method that will generate the appropriate parameter
> key for you.
>
> Mat
>
Sweet!