solrj创建富文本索引

        今天主要使用solrj为富文本内容创建索引,参考网上的例子,一直没有调试成功。solrj客户端报的是org.apache.solr.common.SolrException: Internal Server Error错误,没有提示任何信息,因此自己感觉一头雾水,不知从何下手。solr程序后台没有报任何错误。

    后来把dist文件夹下的lib包都拷贝到solr程序中,solr后台终于显示了错误信息。根据错误信息的提示把contrib\extraction下的所有jar报都拷贝到solr程序中,程序终于运行起来了。

   下面是利用solrj创建富文本内容索引的程序。

   

import java.io.File;
import java.io.IOException;
import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.SolrServer;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.impl.CommonsHttpSolrServer;
import org.apache.solr.client.solrj.request.AbstractUpdateRequest;
import org.apache.solr.client.solrj.request.ContentStreamUpdateRequest;
import org.apache.solr.client.solrj.response.QueryResponse;

public class SolrJDemo2 {

	
	  public static void main(String[] args) {

		    try {
		      //Solr cell can also index MS file (2003 version and 2007 version) types.
		      String fileName = "D://lucene3//SQL性能优化.docx"; 
		      //this will be unique Id used by Solr to index the file contents.
		      String solrId = "SQL性能优化"; 
		      
		      indexFilesSolrCell(fileName, solrId);
		      
		    } catch (Exception ex) {
		      System.out.println(ex.toString());
		    }
		  }
		  
		  /**
		   * Method to index all types of files into Solr. 
		   * @param fileName
		   * @param solrId
		   * @throws IOException
		   * @throws SolrServerException
		   */
		  public static void indexFilesSolrCell(String fileName, String solrId) 
		    throws IOException, SolrServerException {
		    
		    String urlString = "http://127.0.0.1:8080/solr"; 
		    SolrServer solr = new CommonsHttpSolrServer(urlString);
		    
		    ContentStreamUpdateRequest up 
		      = new ContentStreamUpdateRequest("/update/extract");
		    
		    up.addFile(new File(fileName));
		    
		    up.setParam("literal.id", solrId);
		    up.setParam("fmap.content", "attr_content");
		    
		    up.setAction(AbstractUpdateRequest.ACTION.COMMIT, true, true);
		    
		    solr.request(up);
		    
		    QueryResponse rsp = solr.query(new SolrQuery("*:*"));
		    
		    System.out.println(rsp);
		  }

	
}

 

      up.setParam("literal.id", solrId);   //设置document的id域值为solrid
      up.setParam("fmap.content", "msg_content");//设置存储文件内容的域为msg_content,我们必须在schema.xml中定义msg_content字段。

      
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值