I'm one step further :
- Good : I now know aaf knows about/received the custom analyzer
but
- Bad : the analyzer is not used by aaf ( : it stops on words it should
not stop on)
New test : a "no stop word" analyzer, adapted from the german stemming
analyser @
http://projects.jkraemer.net/acts_as_ferret/wiki/AdvancedUsage
file: model/country.rb
----------------------
class Test2Analyzer < ::Ferret::Analysis::Analyzer
include Ferret::Analysis
def initialize(stop_words = [])
@stop_words = stop_words
end
def token_stream(field, str)
StemFilter.new(StopFilter.new(LowerCaseFilter.new(
StandardTokenizer.new(str)), @stop_words), 'de')
end
end
class Country < ActiveRecord::Base
acts_as_ferret(
:fields => [:name] ,
:remote => true,
:ferret => {:analyzer => Test2Analyzer.new([]) }
)
end
0°/ delete the ferret index directory
1°/ restart the console and rebuild the index :
./script/console
>> Country.rebuild_index
Asked for a remote server ? true, ENV["FERRET_USE_LOCAL_INDEX"] is nil,
looks like we are not the server
Will use remote index server which should be available at
druby://localhost:9010
default field list: [:name]
=> nil
2°/ confirm that aaf knows about my "no_stop_words" custom analyzer :
>> puts Country.aaf_index.to_yaml
--- !ruby/object:ActsAsFerret::RemoteIndex
config:
:fields:
- :name
:mysql_fast_batches: true
:name: countries
:class_name: Country
:index_dir:
/Users/aravet/aaprojets/newgids/newgids_machine/index/development/country
:remote: druby://localhost:9010
:reindex_batch_size: 1000
:store_class_name: false
:ferret_fields:
:name:
:store: :no
:term_vector: :with_positions_offsets
:boost: 1.0
:index: :yes
:highlight: :yes
:single_index: false
:ferret: &id001
:key: :id
:auto_flush: true
:or_default: false
:path:
/Users/aravet/aaprojets/newgids/newgids_machine/index/development/country
:create_if_missing: true
:handle_parse_errors: true
:analyzer: !ruby/object:Test2Analyzer <<<<----------- Good
stop_words: [] <<<<----------- Good
:default_field:
- :name
:enabled: true
ferret_config: *id001
server: !ruby/object:DRb::DRbObject
ref:
uri: druby://localhost:9010
=> nil
3°/ confirm that there is record with name == "the"
>> Country.find_by_name "the"
Country Load (0.000427) SELECT * FROM countries WHERE (countries.`name`
= 'the') LIMIT 1
=> #<Country id: 11, name: "the">
4°/ try and find "t*" it with aaf
=> DOES NOT WORK (does not find Country[:name => "the"])
>> Country.find_by_contents "t*"
Query: t*
total hits: 0, results delivered: 0
=> #<ActsAsFerret::SearchResults:0x31ff754 @per_page=0, @current_page=nil,
@total_hits=0, @results=[], @total_pages=0>
5°/ do the same for "t*", a non stop word
=> IT WORKS (finds Country[:name => "Frankrijk"])
>> Country.find_by_contents "f*"
Country Load (0.000420) SELECT * FROM countries WHERE (countries.id in
('2'))
Query: f*
total hits: 1, results delivered: 1
=> #<ActsAsFerret::SearchResults:0x31fa4ac @per_page=1, @current_page=nil,
@total_hits=1, @results=[#<Country id: 2, name: "Frankrijk">], total_pages1
So, aaf (rev 262)
* associates the right custom analyzer with the model,
* but doesn't seem to use it when finding_by_contents (? and rebuilding the
index ??)
Alain
_______________________________________________
Ferret-talk mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/ferret-talk