solrj分词Java使用
2015-11-24 11:27
417 查看
小狼最近在看solr分词,环境是搭好了,但是小狼想把这个算出来的分词放到Java端,很纠结
怎么把下面分出来的结果放到Java类中
其中QueryResponse 对象的值是一堆json
怎么把下面分出来的结果放到Java类中
public static String testSolrLocal2() throws SolrServerException{ StringUtill util=new StringUtill(); HttpSolrServer solr = new HttpSolrServer("http://localhost:8888/solr/collection1"); try { solr.setConnectionTimeout(1000); solr.setDefaultMaxConnectionsPerHost(100); solr.setMaxTotalConnections(100); } catch (Exception e) { e.printStackTrace(); } SolrQuery query = new SolrQuery(); query.add(CommonParams.QT, "/analysis/field"); // query type query.add(AnalysisParams.FIELD_VALUE, "杜淳,我爱你"); query.add(AnalysisParams.FIELD_TYPE, "text_it"); QueryResponse response=solr.query(query); NamedList<Object> analysis = (NamedList<Object>) response.getResponse().get("analysis");// analysis node NamedList<Object> field_types = (NamedList<Object>) analysis.get("field_types");// field_types node NamedList<Object> text_it = (NamedList<Object>) field_types.get("text_it");// text_chinese node NamedList<Object> index = (NamedList<Object>) text_it.get("index");// index node List<SimpleOrderedMap<String>> list = (ArrayList<SimpleOrderedMap<String>>) index.get("org.apache.lucene.analysis.standard.StandardTokenizer");// tokenizer node String nextQuery=""; for(Iterator<SimpleOrderedMap<String>> iter = list.iterator(); iter.hasNext();) { nextQuery += iter.next().get("text") + " "; } return nextQuery.trim(); }
其中QueryResponse 对象的值是一堆json
analysis={ field_types={ text_it={ index={ org.apache.lucene.analysis.standard.StandardTokenizer=[ { text=杜, raw_bytes=[ e69d9c ], start=0, end=1, org.apache.lucene.analysis.tokenattributes.PositionLengthAttribute#positionLength=1, type=<IDEOGRAPHIC>, position=1, positionHistory=[ 1 ] }, { text=淳, raw_bytes=[ e6b7b3 ], start=1, end=2, org.apache.lucene.analysis.tokenattributes.PositionLengthAttribute#positionLength=1, type=<IDEOGRAPHIC>, position=2, positionHistory=[ 2 ] }, { text=我, raw_bytes=[ e68891 ], start=3, end=4, org.apache.lucene.analysis.tokenattributes.PositionLengthAttribute#positionLength=1, type=<IDEOGRAPHIC>, position=3, positionHistory=[ 3 ] }, { text=爱, raw_bytes=[ e788b1 ], start=4, end=5, org.apache.lucene.analysis.tokenattributes.PositionLengthAttribute#positionLength=1, type=<IDEOGRAPHIC>, position=4, positionHistory=[ 4 ] }, { text=你, raw_bytes=[ e4bda0 ], start=5, end=6, org.apache.lucene.analysis.tokenattributes.PositionLengthAttribute#positionLength=1, type=<IDEOGRAPHIC>, position=5, positionHistory=[ 5 ] } ], org.apache.lucene.analysis.util.ElisionFilter=[ { text=杜, raw_bytes=[ e69d9c ], start=0, end=1, org.apache.lucene.analysis.tokenattributes.PositionLengthAttribute#positionLength=1, type=<IDEOGRAPHIC>, position=1, positionHistory=[ 1, 1 ] }, { text=淳, raw_bytes=[ e6b7b3 ], start=1, end=2, org.apache.lucene.analysis.tokenattributes.PositionLengthAttribute#positionLength=1, type=<IDEOGRAPHIC>, position=2, positionHistory=[ 2, 2 ] }, { text=我, raw_bytes=[ e68891 ], start=3, end=4, org.apache.lucene.analysis.tokenattributes.PositionLengthAttribute#positionLength=1, type=<IDEOGRAPHIC>, position=3, positionHistory=[ 3, 3 ] }, { text=爱, raw_bytes=[ e788b1 ], start=4, end=5, org.apache.lucene.analysis.tokenattributes.PositionLengthAttribute#positionLength=1, type=<IDEOGRAPHIC>, position=4, positionHistory=[ 4, 4 ] }, { text=你, raw_bytes=[ e4bda0 ], start=5, end=6, org.apache.lucene.analysis.tokenattributes.PositionLengthAttribute#positionLength=1, type=<IDEOGRAPHIC>, position=5, positionHistory=[ 5, 5 ] } ], org.apache.lucene.analysis.core.LowerCaseFilter=[ { text=杜, raw_bytes=[ e69d9c ], start=0, end=1, org.apache.lucene.analysis.tokenattributes.PositionLengthAttribute#positionLength=1, type=<IDEOGRAPHIC>, position=1, positionHistory=[ 1, 1, 1 ] }, { text=淳, raw_bytes=[ e6b7b3 ], start=1, end=2, org.apache.lucene.analysis.tokenattributes.PositionLengthAttribute#positionLength=1, type=<IDEOGRAPHIC>, position=2, positionHistory=[ 2, 2, 2 ] }, { text=我, raw_bytes=[ e68891 ], start=3, end=4, org.apache.lucene.analysis.tokenattributes.PositionLengthAttribute#positionLength=1, type=<IDEOGRAPHIC>, position=3, positionHistory=[ 3, 3, 3 ] }, { text=爱, raw_bytes=[ e788b1 ], start=4, end=5, org.apache.lucene.analysis.tokenattributes.PositionLengthAttribute#positionLength=1, type=<IDEOGRAPHIC>, position=4, positionHistory=[ 4, 4, 4 ] }, { text=你, raw_bytes=[ e4bda0 ], start=5, end=6, org.apache.lucene.analysis.tokenattributes.PositionLengthAttribute#positionLength=1, type=<IDEOGRAPHIC>, position=5, positionHistory=[ 5, 5, 5 ] } ], org.apache.lucene.analysis.core.StopFilter=[ { text=杜, raw_bytes=[ e69d9c ], start=0, end=1, org.apache.lucene.analysis.tokenattributes.PositionLengthAttribute#positionLength=1, type=<IDEOGRAPHIC>, position=1, positionHistory=[ 1, 1, 1, 1 ] }, { text=淳, raw_bytes=[ e6b7b3 ], start=1, end=2, org.apache.lucene.analysis.tokenattributes.PositionLengthAttribute#positionLength=1, type=<IDEOGRAPHIC>, position=2, positionHistory=[ 2, 2, 2, 2 ] }, { text=我, raw_bytes=[ e68891 ], start=3, end=4, org.apache.lucene.analysis.tokenattributes.PositionLengthAttribute#positionLength=1, type=<IDEOGRAPHIC>, position=3, positionHistory=[ 3, 3, 3, 3 ] }, { text=爱, raw_bytes=[ e788b1 ], start=4, end=5, org.apache.lucene.analysis.tokenattributes.PositionLengthAttribute#positionLength=1, type=<IDEOGRAPHIC>, position=4, positionHistory=[ 4, 4, 4, 4 ] }, { text=你, raw_bytes=[ e4bda0 ], start=5, end=6, org.apache.lucene.analysis.tokenattributes.PositionLengthAttribute#positionLength=1, type=<IDEOGRAPHIC>, position=5, positionHistory=[ 5, 5, 5, 5 ] } ], org.apache.lucene.analysis.it.ItalianLightStemFilter=[ { text=杜, raw_bytes=[ e69d9c ], start=0, end=1, org.apache.lucene.analysis.tokenattributes.PositionLengthAttribute#positionLength=1, type=<IDEOGRAPHIC>, org.apache.lucene.analysis.tokenattributes.KeywordAttribute#keyword=false, position=1, positionHistory=[ 1, 1, 1, 1, 1 ] }, { text=淳, raw_bytes=[ e6b7b3 ], start=1, end=2, org.apache.lucene.analysis.tokenattributes.PositionLengthAttribute#positionLength=1, type=<IDEOGRAPHIC>, org.apache.lucene.analysis.tokenattributes.KeywordAttribute#keyword=false, position=2, positionHistory=[ 2, 2, 2, 2, 2 ] }, { text=我, raw_bytes=[ e68891 ], start=3, end=4, org.apache.lucene.analysis.tokenattributes.PositionLengthAttribute#positionLength=1, type=<IDEOGRAPHIC>, org.apache.lucene.analysis.tokenattributes.KeywordAttribute#keyword=false, position=3, positionHistory=[ 3, 3, 3, 3, 3 ] }, { text=爱, raw_bytes=[ e788b1 ], start=4, end=5, org.apache.lucene.analysis.tokenattributes.PositionLengthAttribute#positionLength=1, type=<IDEOGRAPHIC>, org.apache.lucene.analysis.tokenattributes.KeywordAttribute#keyword=false, position=4, positionHistory=[ 4, 4, 4, 4, 4 ] }, { text=你, raw_bytes=[ e4bda0 ], start=5, end=6, org.apache.lucene.analysis.tokenattributes.PositionLengthAttribute#positionLength=1, type=<IDEOGRAPHIC>, org.apache.lucene.analysis.tokenattributes.KeywordAttribute#keyword=false, position=5, positionHistory=[ 5, 5, 5, 5, 5 ] } ] } } }, field_names={ } } }
相关文章推荐
- springmvc 和struts2的区别
- Elipse安装Spring Tool Suite
- Myeclipse快捷键的使用
- springmvc 和struts2的区别
- Struts的工作原理
- jdk安装及 JAVA_HOME环境设置
- java使用监听器实现对在线用户的统计
- Selenium2(webdirver)入门之三元素定位(Java版)
- 低版本textView.setAlpha 报错java.lang.NoSuchMethodError: widget.TextView.setAlpha
- Struts2的工作原理
- Selenium2(webdirver)入门之二TestNg安装(Java版)
- Beetl SpringBoot集成
- 【Java EE (Struts2 + Spring + Hibernate)开发】: Struts2(一)之 【Struts2标签库】
- spring工具类AntPathMatcher
- 对Java中的 int AND Integer的理解
- Hadoop自带WordCount.java程序
- java cookie
- springmvc 和struts2的区别?struts2工作原理?
- mybatis generator eclipse插件的安装
- Selenium2(webdirver)入门之一环境搭建(Java版)