solr - Retrieve JSON facet with SolrJ -


i use solrj along json facet api facets. solrj query response object contained documents, no facets. facet nested structure. solrj support json facets or i'll need parse self?

furthermore, facets on child objects contained counts, no values. how can facet terms, france, italy below example?

    facets={     count=57477,     apparels={         buckets=         {             val=chanel,             count=6,             madein={                 count=6             }         }     } } 

you must parse facet result since not obvious parse it. may use response.getresponse().get("facets"); or may request server directly , parse result yourself.

direct request may done method below.

   public static inputstream getinputstreamwithpost(final string url) throws exception {      final url obj = new url(url);     final httpurlconnection con = (httpurlconnection) obj.openconnection();      // optional default post     con.setrequestmethod("post");      // add request header     con.setrequestproperty("user-agent",                            "mozilla/5.0 (windows; u; windows nt 6.1; en-gb;     rv:1.9.2.13) gecko/20101203 firefox/3.6.13 (.net clr 3.5.30729)");     return con.getinputstream(); } 

java json parser in "javax.json" package have use implementation of methods maven repository implementation.

<!-- https://mvnrepository.com/artifact/org.glassfish/javax.json -->     <dependency>         <groupid>org.glassfish</groupid>         <artifactid>javax.json</artifactid>         <version>1.0.4</version>         <scope>provided</scope>     </dependency> 

below parsing result directly java's json parser.

try (final jsonreader rdr = json.createreader(inputstream)) {          final jsonobject jobject = rdr.readobject();         jsonobject jobject1 = jobject.getjsonobject("facets");         jobject1 = jobject1.getjsonobject(metadataname);         final jsonarray jsonarray = (jobject1.getjsonarray("buckets"));          (int = 0; < jsonarray.size(); i++) {             final jsonobject jsonobject = jsonarray.getjsonobject(i);             system.out.println(jsonobject.getstring("val"));             system.out.println(jsonobject.getint("count"));         }          return jsonarray;     } 

Comments

Popular posts from this blog

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -