Created
April 20, 2015 09:10
-
-
Save optyler/4566d53b5e089c9cbb49 to your computer and use it in GitHub Desktop.
HAL Rest api (Solr 4.8) over SolrJ-5.0.0.jar
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.qwam; | |
import org.apache.solr.client.solrj.SolrQuery; | |
import org.apache.solr.client.solrj.SolrServerException; | |
import org.apache.solr.client.solrj.impl.HttpSolrClient; | |
import org.apache.solr.client.solrj.impl.XMLResponseParser; | |
import org.apache.solr.client.solrj.response.FacetField; | |
import org.apache.solr.client.solrj.response.QueryResponse; | |
/** | |
* Created by pferreira on 17/04/15. | |
*/ | |
public class TESTSolr { | |
protected class QESXMLResponseParser extends XMLResponseParser { | |
public QESXMLResponseParser() { | |
super(); | |
} | |
@Override | |
public String getContentType() { | |
return "text/xml; charset=UTF-8"; | |
} | |
} | |
public TESTSolr() { | |
SolrQuery query = new SolrQuery(); | |
query.setFacet(true); | |
query.setFacetMinCount(1); | |
query.setRows(new Integer(100)); | |
query.setStart(new Integer(0)); | |
query.addFacetField("docType_s"); | |
query.set("f.docType_s.facet.limit", 25); | |
query.setQuery("(text:(pierre))"); | |
HttpSolrClient client = new HttpSolrClient("http://api.archives-ouvertes.fr/search/PASTEUR"); | |
client.setParser(new QESXMLResponseParser()); | |
try { | |
QueryResponse queryResponse = client.query(query); | |
FacetField f = queryResponse.getFacetField("docType_s"); | |
System.out.println(f.getName()); | |
for ( FacetField.Count c : f.getValues() ) { | |
System.out.println( c.getName() + " : " + c.getCount() ); | |
} | |
} catch (SolrServerException e) { | |
e.printStackTrace(); | |
} | |
} | |
public static void main(String[] args) { | |
new TESTSolr(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment