2013年1月7日 星期一

Utilize TermsComponent in LucidWorksEnterprise(LWE)


1. Modify solrconfig.xml
You can find lots of samples in internet. I still keep "autocomplete" because I still want to keep primary design of LWE
<requestHandler class="org.apache.solr.handler.component.SearchHandler" name="/autocomplete">
<lst name="defaults">
   <bool name="terms">true</bool>
   <str name="terms.fl">autocomplete</str>
   <str name="terms.sort">count</str>
   <str name="terms.limit">20</str>
</lst>
   <arr name="components">
<str>terms</str>
   </arr>
</requestHandler>
<searchComponent class="solr.TermsComponent" name="terms"/>

2. Modify search.rb in [LWE]\app\webapps\lwe-ui\WEB-INF\app\models\core
a. In order to make TermsComponent works and not to alter LWE a lot, we want to add 1. terms.prefix=xxxx or change "q"  to "terms.prefix". Finally, I choose option#1. My approach is adding one parameter in the http request at line#230(keyword is when :autocomplete) in function,  solr_params(xxxx), new codes are :
params.merge!(
'terms.prefix' => params[:q]
)
b. Because SpellCheck and TermsComponent returns diff. data scheme, we need to add one parser at line#400(keyword is def autocompletions)
if @results['spellcheck'] == nil
@results['terms']['autocomplete'] rescue []    
else
@results['spellcheck']['suggestions'].at(1)['suggestion'] rescue []    
end



沒有留言:

張貼留言