solr 使用 suggest 自动 提示,查询不到结果 SpellCheckComponent

远方的人-加油 发布于 2014/05/07 19:34
阅读 1K+
收藏 0

@震秦 你好,想跟你请教个问题:

@震秦 你好,想跟你请教个问题: 

<!-- mm suggest,, copyField is merge field a to dest=ab-->
	<searchComponent name="suggest" class="solr.SpellCheckComponent">
	  <str name="queryAnalyzerFieldType">textSpell</str> 
	  <lst name="spellchecker">
		<str name="name">direct</str>
		<str name="field">productName</str>
		<str name="classname">solr.DirectSolrSpellChecker</str> 
		<str name="distanceMeasure">internal</str> 
		<float name="accuracy">0.5</float> 
		<int name="maxEdits">2</int> 
		<int name="minPrefix">1</int> 
		<int name="maxInspections">5</int> 
		<int name="minQueryLength">4</int> 
		<float name="maxQueryFrequency">0.01</float>
		<!--<str name="sourceLocation">dict.txt</str>--> <!--if appoint the sourceLocation,the field is not work-->  
	  </lst>
	</searchComponent>


<!--mm suggest-->
	<requestHandler name="/suggest" class="solr.SearchHandler" startup="lazy">
	  <lst name="defaults">
		<str name="df">text</str>
		<str name="spellcheck.dictionary">direct</str> 
		<str name="spellcheck">on</str> 
		<str name="spellcheck.extendedResults">true</str>       
		<str name="spellcheck.count">10</str> 
		<str name="spellcheck.collate">true</str> 
		<str name="spellcheck.collateExtendedResults">true</str> 
	  </lst>
	  <arr name="last-components">
		<str>suggest</str>
	  </arr>
	</requestHandler>



solrj 调用 


HttpSolrServer solrServer =SolrServer.getInstance().getServer();
		solrServer.setRequestWriter(new BinaryRequestWriter()); 
		SolrQuery sQuery = new SolrQuery();
		ModifiableSolrParams params=new ModifiableSolrParams();
		params.set("qt", "/suggest");//spellhandler
		params.set("q",content);
		///CommonParams.QT 条件命名
		params.set("spellcheck", "on");  
        params.set("spellcheck.build", "true");  
		
        params.set("spellcheck.count", "10");  
        //params.set("spellcheck.alternativeTermCount", "4");  
       // params.set("spellcheck.onlyMorePopular", "false");
        
        //params.set("spellcheck.extendedResults", "false");  
       // params.set("spellcheck.maxResultsForSuggest", "5");  
  
        //params.set("spellcheck.collate", "true");  
       // params.set("spellcheck.collateExtendedResults", "true");  
        //params.set("spellcheck.maxCollationTries", "5");  
        //params.set("spellcheck.maxCollations", "3");
        
		sQuery.add(params);
		try {
			
			// 第一种方式 获得 entitylist 
			QueryResponse response = solrServer.query(sQuery);
			SpellCheckResponse spellCheckResponse = response.getSpellCheckResponse();
			if(spellCheckResponse != null){
				List<Suggestion> suggestionList=spellCheckResponse.getSuggestions();
				for(Suggestion suggestion:suggestionList){
					if(suggestion.getNumFound()!=0){
						List<String> suggestWordList=suggestion.getAlternatives();
						JsonMapper jsonMapper=JsonMapper.awalysMapper();
						String json = jsonMapper.toJson(suggestWordList);
						
						HttpServletResponse response1=ServletActionContext.getResponse();
						response1.setContentType("text/plain");
						response1.setCharacterEncoding("UTF-8");
						PrintWriter out=response1.getWriter();
						out.print(json);
						out.flush();
						out.close();
						break;
					}
				}
			}

List<Suggestion> suggestionList=spellCheckResponse.getSuggestions(); 没有任何 suggestion返回 。。

怎么办 ,求教


加载中
0
sillycow
sillycow

你好,这个问题解决了吗?


0
青木川_空楼高阁
可以用这个方法,queryResponse.getSuggestion()
返回顶部
顶部