lucene-solr-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Shawn Heisey <>
Subject Re: Solrj Stats encoding problem
Date Wed, 05 Jun 2013 22:06:42 GMT
On 6/5/2013 2:11 PM, ethereal wrote:
> Hi,
> I've tested a query using solr admin web interface and it works fine.
> But when I'm trying to execute the same search using solrj, it doesn't
> include Stats information.
> I've figured out that it's because my query is encoded.
> Original query is like q=eventTimestamp:[2013-06-01T12:00:00.000Z TO
> 2013-06-30T11:59:59.999Z]&stats=true&stats.field=numberOfBytes&stats.facet=eventType
> The query in java is like
> q=eventTimestamp%3A%5B2013-06-01T12%3A00%3A00.000Z+TO+2013-06-30T11%3A59%3A59.999Z%5D%26stats%3Dtrue%26stats.field%3DnumberOfBytes%26stats.facet%3DeventType
> If I copy this query to browser address bar, it doesn't work, but it does if
> I replace encoded &:= with original values. What should I do do make it work
> through java?
> The code is like the following:
> SolrQuery solrQuery = new SolrQuery();
> solrQuery.setQuery(queryBuilder.toString());
> QueryResponse query = getSolrServer().query(solrQuery);

The only QueryBuilder objects I can find are in the Lucene API, so I 
have no idea what that part of your code is doing.  Here's how I would 
duplicate the query you reference in SolrJ.  The query string is broken 
apart so that the lines won't wrap awkwardly:

String url = "http://localhost:8983/solr/collection1";
SolrServer server = new HttpSolrServer(url);

String qs = "eventTimestamp:"
   + "[2013-06-01T12:00:00.000Z TO 2013-06-30T11:59:59.999Z]";
SolrQuery query = new SolrQuery();
query.set("stats", "true");
query.set("stats.field", "numberOfBytes");
query.set("stats.facet", "eventType");

QueryResponse rsp = server.query(query);


View raw message