Sunspot Solr Search as Rails active entry 'LIKE' search

Hi, I used the usual LIKE rail active record in my application, I started using solspot solr search. I would like it to work as close to the rails as you like best.


wine.rb
#sunspot stuff
  searchable :auto_index => true, :auto_remove => true do
  text :name
end
#sunspot stuff


Solr / CONF / schema.xml
<fieldType name="text" class="solr.TextField" omitNorms="false">
  <analyzer>
    <tokenizer class="solr.StandardTokenizerFactory"/>
    <filter class="solr.StandardFilterFactory"/>
    <filter class="solr.LowerCaseFilterFactory"/>
  </analyzer>
</fieldType>


application_controller.rb
search_string = "will input some values here"
query = "%" + search_string + "%"

solr_search = Wine.search do
  fulltext search_string
end
@solr_search_results = solr_search.results.sort_by{|e| e[:id]}

@rails_search_results = Wine.find(:all, :conditions => ['wines.name LIKE ?' , query]).sort_by{|e| e[:id]}


search1

search_string = "grand"

@solr_search_results
186
688
760
768 Grand Rouge
857 Premier Grand Cru
1067 Grand Classique
1584
3389
3708 Grand Cuvèe Brut
3857


@rails_search_results
186
688
760
768 Grand Rouge
857 Premier Grand Cru
969 River Grandeur Cape Blend
972
973
974 River Grandeur Chenin Blanc
975 River Grandeur Pinotage
976 River Grandeur Sauvignon Blanc
977 River Grandeur Shiraz
978 River Grandeur Rose
1067 Grand Classique
1584 Grand Vin De Glenelli
3389 Great Constance Muscat
3708 Grand Cuvèe Brut
3857 Grand Constance Muscat


seems that Solr found recording "Grandeur" in them, he found only exact matches? How can i fix this?


Search2

search_string = "rood"

@solr_search_results
200 Dassies Rood Cinsaut
3198
3394


@rails_search_results
200 Dassies Rood Cinsaut
483
484
1113 Zevenrood
3044 Roodewal
3198
3394
3477 Roodeberg Red
3478 Roodeberg White
3594
3604 Roodeberg Red


, solr "Roodeberg", search_string = 'rood',


Update

Added nGram filter for schema.xml for partial matching, thanks to DanS
But not all results yet

app / solr / conf / schema.xml

<fieldType name="text" class="solr.TextField" omitNorms="false">

    <analyzer type="index">
        <tokenizer class="solr.LowerCaseTokenizerFactory"/>
        <filter class="solr.NGramFilterFactory" minGramSize="3" maxGramSize="15"/>
    </analyzer>

    <analyzer type="query">
        <tokenizer class="solr.LowerCaseTokenizerFactory"/>
    </analyzer>

</fieldType>




It still doesn’t quite do what I want to see, look at the following example



search3

search_string = "merl"

@solr_search_results
130
202
306
336
556
579
592
623
640
689
694
714
776
790
841
865
891
947
1015
1045
1046
1073
1075
1089
1096
1111
1121
1144
1145
1169


@rails_search_results

34 Cavalier Reserve Blend
129
130
202
240
306
336
416
477
483
556
579
592
614
623
640
656
672 Ondine Merlot
689
694
696
714
762
776
790
795
816 JJ Merlot
832
841
842
854 Eagle Crest
865
877
891
892 Merlot Reserve
893
941
943 Cabertnet Sauvignon Merlot Cab Franc Shiraz
947
982 Boet Erasmus
983
984 Classic
1010
1015
1045
1046
1073
1075
1079 /
1089
1093
1096
1104 Z
1111
1121
1144
1145
1169
1186
1254
1260 /
1261
1269
1326
1349
1364
1381
1384
1393
1401
1404
1421
1424
1431
1443
1454
1467
1468
1476
1491
1495
1542
1543
1549
1552 Merlot Reserve
1582
1592
3001
3007
3036
3056
3067
3073
3079
3091
3106
3133
3143
3154 №1
3182
3183 Cab Sauv Merlot Cab Franc
3200
3236
3258
3276
3288
3303
3307
3311
3318 Caapmans
3321
3322
3326
3334
3343
3363
3372
3390
3416 R 62
3418 62
3419 Unplugged 62
3431
3439 KC
3471
3497
3498
3510
3531
3540
3560
3568
3578
3581
3584
3624
3642
3657
3677
3681
3685 C
3693
3728
3755
3771
3773
3820
3859
3882 Dunstone Merlot
3900
3919
3947

+5
2

Update2

! , Solr 30 , , .


MyApp///sunspot_solr.rb

Sunspot.config.pagination.default_per_page = 3000
+3

, .

schema.xml, :

<filter class="solr.EdgeNGramFilterFactory"/>

:

<filter class="solr.NGramFilterFactory"/>

. Solr wiki.

+3

All Articles