如何在java/solrj中解析Solr分析请求的响应?
我有一个java程序在solr服务器中发出请求。我创建了一个触发solr分析服务的查询:如何在java/solrj中解析Solr分析请求的响应?,java,solr,solrj,Java,Solr,Solrj,我有一个java程序在solr服务器中发出请求。我创建了一个触发solr分析服务的查询: HttpSolrClient server = new HttpSolrClient("http://localhost:8983/solr/docs"); SolrQuery query = new SolrQuery(); query.setRequestHandler("/analysis/field"); query.set(
HttpSolrClient server = new
HttpSolrClient("http://localhost:8983/solr/docs");
SolrQuery query = new SolrQuery();
query.setRequestHandler("/analysis/field");
query.set("analysis.fieldtype", "text_en");
query.set("analysis.fieldvalue", "TESTS");
query.set("wt", "json");
我得到的回应是:
{responseHeader={status=0,QTime=2},analysis={field_types={text_en={index={org.apache.lucene.analysis.standard.StandardTokenizer=[{text=TESTS,raw_bytes=[54 45 53 54 53],start=0,end=5,org.apache.lucene.analysis.tokenattributes.PositionLengthAttribute#positionLength=1,type=<ALPHANUM>,position=1,positionHistory=[1]}],org.apache.lucene.analysis.core.StopFilter=[{text=TESTS,raw_bytes=[54 45 53 54 53],start=0,end=5,org.apache.lucene.analysis.tokenattributes.PositionLengthAttribute#positionLength=1,type=<ALPHANUM>,position=1,positionHistory=[1, 1]}],org.apache.lucene.analysis.core.LowerCaseFilter=[{text=tests,raw_bytes=[74 65 73 74 73],start=0,end=5,org.apache.lucene.analysis.tokenattributes.PositionLengthAttribute#positionLength=1,type=<ALPHANUM>,position=1,positionHistory=[1, 1, 1]}],org.apache.lucene.analysis.en.EnglishPossessiveFilter=[{text=tests,raw_bytes=[74 65 73 74 73],start=0,end=5,org.apache.lucene.analysis.tokenattributes.PositionLengthAttribute#positionLength=1,type=<ALPHANUM>,position=1,positionHistory=[1, 1, 1, 1]}],org.apache.lucene.analysis.miscellaneous.SetKeywordMarkerFilter=[{text=tests,raw_bytes=[74 65 73 74 73],start=0,end=5,org.apache.lucene.analysis.tokenattributes.PositionLengthAttribute#positionLength=1,type=<ALPHANUM>,position=1,positionHistory=[1, 1, 1, 1, 1],org.apache.lucene.analysis.tokenattributes.KeywordAttribute#keyword=false}],org.apache.lucene.analysis.en.PorterStemFilter=[{text=test,raw_bytes=[74 65 73 74],start=0,end=5,org.apache.lucene.analysis.tokenattributes.PositionLengthAttribute#positionLength=1,type=<ALPHANUM>,position=1,positionHistory=[1, 1, 1, 1, 1, 1],org.apache.lucene.analysis.tokenattributes.KeywordAttribute#keyword=false}]}}},field_names={}}}
它是一个类org.apache.solr.common.util.SimpleOrderedMap对象
有什么想法吗?提前感谢。基本上,这是Solr的一个缺点,正如您提到的,它不是有效的json,但它是Solr a中所称内容的字符串表示(SimpleOrderedMap是NamedList的一个子类) 一个简单的容器类,用于建模名称/值的有序列表 对。与地图不同:
- 名字可以重复
- 元素的顺序保持不变
- 元素可以通过数字索引访问
- 名称和值都可以为null NamedList提供按元素编号而不是按名称的快速访问
getFieldNameAnalysis(String fieldName)
这将为您提供FieldAnalysisResponse.Analysis
从两种可能的解决方案中,我将推荐后者,因为它更容易掌握和维护。我最终使用了另一种解决方案。在中使用http请求:
http://localhost:8983/solr/docs/analysis/field?wt=json&analysis.showmatch=true&analysis.fieldvalue={custom}&analysis.fieldtype={custom}
我以有效的json格式返回结果。您应该查看FieldAnalysisRequest。我在这里找到了一个例子,希望这能有所帮助。谢谢,我尝试了fieldanalysisrequest,但仍然得到了同样的响应。我终于找到了另一个解决方案,我也将其作为答案发布。
http://localhost:8983/solr/docs/analysis/field?wt=json&analysis.showmatch=true&analysis.fieldvalue={custom}&analysis.fieldtype={custom}