Searching using wildcards

110 views
Skip to first unread message

cyx

unread,
Jul 22, 2009, 9:04:43 AM7/22/09
to Sunspot
Hi,

I'm trying sunspot (coming from acts_as_solr), looks pretty cool so
far! One thing I can't figure out is how to do wildcard searching i.e.

Span*

which returns Spanish, Spaniard, etc etc.

Is this possible at all with Sunspot? If so please enlighten me.

Thanks.

Matthew A. Brown

unread,
Jul 22, 2009, 9:39:01 AM7/22/09
to ruby-s...@googlegroups.com
Howdy,

Prefix search isn't currently supported - were you looking to do that
with text (tokenized) fields, or attribute (non-tokenized) fields?
From your example I'm guessing the former, but just want to be clear
on it.

Anyway, it would be easy enough to implement, the main question would
be how the API could be most intuitive...

Mat

cyx

unread,
Jul 22, 2009, 10:29:45 AM7/22/09
to Sunspot
Hi,

Yes I'm looking to do it an a tokenized field.

I'm not sure if it would be great but maybe it could be implemented as
an option parameter to the keyword method, i.e.

search do
keyword :name, 'Unite', :wildcard => true
end

or something to that effect. Not sure if it's logical to put it in non-
tokenized attributes, but it would look nice like

search do
with(:name).matching('Unite')
end

anyway just suggesting. Great work btw.

Matthew A. Brown

unread,
Jul 22, 2009, 10:51:48 AM7/22/09
to ruby-s...@googlegroups.com
Good suggestion - I'll give some thought to it and put it on my TODO - thanks!

Matthew A. Brown

unread,
Nov 15, 2009, 12:58:10 PM11/15/09
to Vassil Kovatchev, Sunspot

Hi Vassil,

Prefix queries can be created in Sunspot 0.10 using the starts_with method - note that if you want to prefix on fulltext fields, you will want to use a text_fields block. See my post on http://outoftime.github.com for more on that.

Stemming is done by Solr if an appropriate filter is placed in the filter chain. Sunspot's built-in Solr instance uses the filter chain that ships by default with Solr itself, which doesn't include stemming. But all you have to do is add it into the chain in solrconfig.xml and you should be set. Check out the Solr wiki for more on that. To run the sunspot-solr executable with a custom solrconfig, you'll need to pass in the flag for solr home - run 'sunspot-solr -h' to get info on that.

Hope that helps!

Mat

On Nov 11, 2009 10:30 PM, "Vassil Kovatchev" <vassil.k...@gmail.com> wrote:

Hello Matthew,

Did you get a chance to implement the wildcard support?
If not, can you give me some pointers as to what can I do to make the
code pass wildcard queries? I understand you want to keep things clean
and in sync with the current DSL, but I'm prototyping a project and a
quick-and-dirty solution will be good enough as a proof of concept.
Also, I noticed that stemming doesn't seem to work with Sunspot. For
example if I have two documents with contents "test" and "tests"
respectively, querying for "test" returns only the one that contains
the word "test" while I'd expect it to return both "test" and "tests"
as a result of term stemming. I'm using "text" type for the field
being indexed.
Your thoughts?

Cheers,
Vassil

On Jul 22, 9:51 am, "Matthew A. Brown" <mat.a.br...@gmail.com> wrote: > Good suggestion - I'll give...

> On Wed, Jul 22, 2009 at 10:29, cyx<cyx.uc...@gmail.com> wrote: > > > Hi, > > > Yes I'm looking to ...

> >> > far! One thing I can't figure out is how to dowildcardsearching i.e.

> > >> > Span* > > >> > which returns Spanish, Spaniard, etc etc. > > >> > Is this possible at all w...

Vassil Kovatchev

unread,
Nov 15, 2009, 4:18:38 PM11/15/09
to Matthew A. Brown, Sunspot
Great, Matthew - this is exactly what I needed. Will give this a try.
Thanks for the reply!

Vassil

Sent from my iPhone
Reply all
Reply to author
Forward
0 new messages