views:

46

answers:

2

I have a very simple SQL table that I want to import into Solr but because of the features I want for search I can't determine the best schema.

The user will start typing into an input box and after 3 characters it will send the request to the server and pull out the most relevant results returning the top 15 matching id and name.

Table ex)

id | name
----------------
1 | boating magazines
2 | boats weekly
3 | boaters collection
4 | shipping lane
5 | ships today

Search and expected return ex)

boa | [1, boating magazines], [2, boaters weekly], [3, boaters collection] 
boat | [1, boating magazines], [2, boaters weekly], [3, boaters collection], [4, shipping lane], [5, ships today]
shi | [4, shipping lane], [5, ships today]
ship | [1, boating magazines], [2, boaters weekly], [3, boaters collection], [4, shipping lane], [5, ships today]
boating | [1, boating magazines], [2, boaters weekly], [3, boaters collection], [4, shipping lane], [5, ships today]

(obviously those would be returned as xml)

Any info on how I would achieve this would be appreciated. Thanks.

A: 

what do you want to know exactly?

if your question is how to get your data there? easiest way is posting xml files....

how do you define your schema.xml? you dont have to, there are pre-defined wildcard fields for strings, they end with _s i think.

how do you form the query?... well as easy as myfield_string:"boa*"

obviously xml? why? json is smaller and just as good for this purpose!

have you checked out the official tutorial? http://lucene.apache.org/solr/tutorial.html

do you want to do an autosuggesting for words or whole documents?

first is very easy. solr even has its very optimized handler for that. check out this tutorial: http://www.mattweber.org/2009/05/02/solr-autosuggest-with-termscomponent-and-jquery/

second one gets more interesting. what if someone types "collection of boats" or something like that? i personally would recommend using dismax handler with a wildcard at the end for autosuggesting. then words are in logical OR conjunction and the not finished word is matched at the beginning...

Joe Hopfgartner
sorry I was under the impression that Solr only returns XML. Yes I was asking how to define the schema for this situation.
+1  A: 

You can implement this using either facet.prefix, TermsComponent or NGrams.

One of those articles also shows how to bind it using jQuery or you could use ajax-solr.

By the way, a specific autosuggest component is to be included in the next release of Solr.

Mauricio Scheffer
Ahh great, after doing some reading am I right to assume that NGrams is the most popular method for this?
@user103219: yes, ngrams are a good solution.
Mauricio Scheffer
Thanks a bunch, used the NGrams one and got it working. Fails on a bunch of the use cases but I'm sure that just has to do with picking the correct filters.