#2 楼@ryancheung 我最开始的方案是找到这个字符,然后直接在数据库里面删除掉。不过后来提交了个缺陷给 sunspot 项目组,有人回复了,解决方案如下:
直接修改 Data Extractor,不过是非官方的。。。。。。
moduleSunspot# # DataExtractors present an internal API for the indexer to use to extract# field values from models for indexing. They must implement the #value_for# method, which takes an object and returns the value extracted from it.#moduleDataExtractor#:nodoc: all# # AttributeExtractors extract data by simply calling a method on the block.#classAttributeExtractordefinitialize(attribute_name)@attribute_name=attribute_nameenddefvalue_for(object)Filter.new(object.send(@attribute_name)).valueendend# # BlockExtractors extract data by evaluating a block in the context of the# object instance, or if the block takes an argument, by passing the object# as the argument to the block. Either way, the return value of the block is# the value returned by the extractor.#classBlockExtractordefinitialize(&block)@block=blockenddefvalue_for(object)Filter.new(Util.instance_eval_or_call(object,&@block)).valueendend# # Constant data extractors simply return the same value for every object.#classConstantdefinitialize(value)@value=valueenddefvalue_for(object)Filter.new(@value).valueendend# # A Filter to allow easy value cleaning#classFilterdefinitialize(value)@value=valueenddefvaluestrip_control_characters@valueenddefstrip_control_characters(value)returnvalueunlessvalue.is_a?Stringvalue.chars.inject("")do|str,char|unlesschar.ascii_only?and(char.ord<32orchar.ord==127)str<<charendstrendendendendend