SolrJ Response + JSON

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

SolrJ Response + JSON

MitchK
Hello community,

I need to transform SolrJ - responses into JSON, after some computing on those results by another application has finished.

I can not do those computations on the Solr - side.

So, I really have to translate SolrJ's output into JSON.

Any experiences how to do so without writing your own JSON-writer?

Thank you.
- Mitch
Reply | Threaded
Open this post in threaded view
|

Re: SolrJ Response + JSON

Mark Allan
I think you should just be able to add &wt=json to the end of your  
query (or change whatever the existing wt parameter is in your URL).

Mark

On 28 Jul 2010, at 12:54 pm, MitchK wrote:

>
> Hello community,
>
> I need to transform SolrJ - responses into JSON, after some  
> computing on
> those results by another application has finished.
>
> I can not do those computations on the Solr - side.
>
> So, I really have to translate SolrJ's output into JSON.
>
> Any experiences how to do so without writing your own JSON-writer?
>
> Thank you.
> - Mitch
> --
> View this message in context: http://lucene.472066.n3.nabble.com/SolrJ-Response-JSON-tp1002024p1002024.html
> Sent from the Solr - User mailing list archive at Nabble.com.
>


--
The University of Edinburgh is a charitable body, registered in
Scotland, with registration number SC005336.

Reply | Threaded
Open this post in threaded view
|

Re: SolrJ Response + JSON

Rajinimaski
Yeah right... This query will do it....

http://localhost:8090/solr/select/?q=*:*&version=2.2&start=0&rows=10&indent=on&wt=json

This will do your work... This is more liike using xsl transformation
supported by solr..:)

Regards,
Rajani Maski


On Wed, Jul 28, 2010 at 6:24 PM, Mark Allan <[hidden email]> wrote:

> I think you should just be able to add &wt=json to the end of your query
> (or change whatever the existing wt parameter is in your URL).
>
> Mark
>
>
> On 28 Jul 2010, at 12:54 pm, MitchK wrote:
>
>
>> Hello community,
>>
>> I need to transform SolrJ - responses into JSON, after some computing on
>> those results by another application has finished.
>>
>> I can not do those computations on the Solr - side.
>>
>> So, I really have to translate SolrJ's output into JSON.
>>
>> Any experiences how to do so without writing your own JSON-writer?
>>
>> Thank you.
>> - Mitch
>> --
>> View this message in context:
>> http://lucene.472066.n3.nabble.com/SolrJ-Response-JSON-tp1002024p1002024.html
>> Sent from the Solr - User mailing list archive at Nabble.com.
>>
>>
>
> --
> The University of Edinburgh is a charitable body, registered in
> Scotland, with registration number SC005336.
>
>
Reply | Threaded
Open this post in threaded view
|

Re: SolrJ Response + JSON

Ranveer Kumar-2
Rajani is right you can get response by passing wt=json. But I think if
you want to use solrj then
you will require to parse binary format data in json format or you can
use third party json parser.

regards
Ranveer
http://www.onlymyhealth.com

On Thursday 29 July 2010 09:55 AM, rajini maski wrote:

> Yeah right... This query will do it....
>
> http://localhost:8090/solr/select/?q=*:*&version=2.2&start=0&rows=10&indent=on&wt=json
>
> This will do your work... This is more liike using xsl transformation
> supported by solr..:)
>
> Regards,
> Rajani Maski
>
>
> On Wed, Jul 28, 2010 at 6:24 PM, Mark Allan<[hidden email]>  wrote:
>
>    
>> I think you should just be able to add&wt=json to the end of your query
>> (or change whatever the existing wt parameter is in your URL).
>>
>> Mark
>>
>>
>> On 28 Jul 2010, at 12:54 pm, MitchK wrote:
>>
>>
>>      
>>> Hello community,
>>>
>>> I need to transform SolrJ - responses into JSON, after some computing on
>>> those results by another application has finished.
>>>
>>> I can not do those computations on the Solr - side.
>>>
>>> So, I really have to translate SolrJ's output into JSON.
>>>
>>> Any experiences how to do so without writing your own JSON-writer?
>>>
>>> Thank you.
>>> - Mitch
>>> --
>>> View this message in context:
>>> http://lucene.472066.n3.nabble.com/SolrJ-Response-JSON-tp1002024p1002024.html
>>> Sent from the Solr - User mailing list archive at Nabble.com.
>>>
>>>
>>>        
>> --
>> The University of Edinburgh is a charitable body, registered in
>> Scotland, with registration number SC005336.
>>
>>
>>      
>    

Reply | Threaded
Open this post in threaded view
|

Re: SolrJ Response + JSON

Mats Bolstad-2
In reply to this post by MitchK
If you don't mind your JSON format complying with the one Solr uses,
you could use GSON.

SolrQuery solrQuery = new SolrQuery("your query");
QueryResponse response = server.query(solrQuery);
List beans = response.getBeans(YourObject.class);
// some computing ...
GSON gson = new GSON();
String json = gson.toJSON(beans);

Mats Bolstad


On Wed, Jul 28, 2010 at 1:54 PM, MitchK <[hidden email]> wrote:

>
> Hello community,
>
> I need to transform SolrJ - responses into JSON, after some computing on
> those results by another application has finished.
>
> I can not do those computations on the Solr - side.
>
> So, I really have to translate SolrJ's output into JSON.
>
> Any experiences how to do so without writing your own JSON-writer?
>
> Thank you.
> - Mitch
> --
> View this message in context: http://lucene.472066.n3.nabble.com/SolrJ-Response-JSON-tp1002024p1002024.html
> Sent from the Solr - User mailing list archive at Nabble.com.
>
Reply | Threaded
Open this post in threaded view
|

Re: SolrJ Response + JSON

MitchK
Hi Mat,

sounds very interesting, because it seems to be so easy.
You say, that this could comply with Solr's JSON-format.
What are your experiences regarding the differences? I mean, JSON is a
standard,
so what can be different?

Thank you!
- Mitch

Am 29.07.2010 09:42, schrieb Mats Bolstad:

> If you don't mind your JSON format complying with the one Solr uses,
> you could use GSON.
>
> SolrQuery solrQuery = new SolrQuery("your query");
> QueryResponse response = server.query(solrQuery);
> List beans = response.getBeans(YourObject.class);
> // some computing ...
> GSON gson = new GSON();
> String json = gson.toJSON(beans);
>
> Mats Bolstad
>
>
> On Wed, Jul 28, 2010 at 1:54 PM, MitchK<[hidden email]>  wrote:
>    
>> Hello community,
>>
>> I need to transform SolrJ - responses into JSON, after some computing on
>> those results by another application has finished.
>>
>> I can not do those computations on the Solr - side.
>>
>> So, I really have to translate SolrJ's output into JSON.
>>
>> Any experiences how to do so without writing your own JSON-writer?
>>
>> Thank you.
>> - Mitch
>> --
>> View this message in context: http://lucene.472066.n3.nabble.com/SolrJ-Response-JSON-tp1002024p1002024.html
>> Sent from the Solr - User mailing list archive at Nabble.com.
>>
>>      
>    

Reply | Threaded
Open this post in threaded view
|

Re: SolrJ Response + JSON

Mats Bolstad
What I meant is that GSON do not wrap the response as follows:

{
 "responseHeader":{
  "status":0,
  "QTime":x},
 "response":{"numFound":x,"start":0,"docs":[
        {
           /* docs */
        }]
 },
 "facet_counts":{
  "facet_queries":{},
  "facet_fields":{},
  "facet_dates":{}}}

If you care to preserve this format/pattern/whatever, you would need
to insert the JSON produced by GSON into such a body, and generate the
other attributes yourself.

That might not be needed, nor difficult to implement. BUT it's not
done out-of-the-box :)

For the application I'm developing I have a similar concern. I want to
do some authorizing and removing/adding content on the docs before I
send them off to the user. As I've already invested a lot of time
developing client-side code I want to preserve the exact same JSON
format.

Mats Bolstad



On Thu, Jul 29, 2010 at 12:40 PM, Mitch Köhler <[hidden email]> wrote:

> Hi Mat,
>
> sounds very interesting, because it seems to be so easy.
> You say, that this could comply with Solr's JSON-format.
> What are your experiences regarding the differences? I mean, JSON is a
> standard,
> so what can be different?
>
> Thank you!
> - Mitch
>
> Am 29.07.2010 09:42, schrieb Mats Bolstad:
>>
>> If you don't mind your JSON format complying with the one Solr uses,
>> you could use GSON.
>>
>> SolrQuery solrQuery = new SolrQuery("your query");
>> QueryResponse response = server.query(solrQuery);
>> List beans = response.getBeans(YourObject.class);
>> // some computing ...
>> GSON gson = new GSON();
>> String json = gson.toJSON(beans);
>>
>> Mats Bolstad
>>
>>
>> On Wed, Jul 28, 2010 at 1:54 PM, MitchK<[hidden email]>  wrote:
>>
>>>
>>> Hello community,
>>>
>>> I need to transform SolrJ - responses into JSON, after some computing on
>>> those results by another application has finished.
>>>
>>> I can not do those computations on the Solr - side.
>>>
>>> So, I really have to translate SolrJ's output into JSON.
>>>
>>> Any experiences how to do so without writing your own JSON-writer?
>>>
>>> Thank you.
>>> - Mitch
>>> --
>>> View this message in context:
>>> http://lucene.472066.n3.nabble.com/SolrJ-Response-JSON-tp1002024p1002024.html
>>> Sent from the Solr - User mailing list archive at Nabble.com.
>>>
>>>
>>
>>
>
>
Reply | Threaded
Open this post in threaded view
|

Re: SolrJ Response + JSON

MitchK
Hi,

as I promised, I want to give a feedback for transforming SolrJ's output
into JSON with the package from json.org (the package was the json.org's
one):

I need to make a small modification to the package, since they store the
JSON-key-value-pairs in a HashMap, I changed this to a LinkedHashMap to
make sure that the order of the retrived values is the same order as
they were inserted in the map.

The result looks very, very pretty.

It was very easy to transform the SolrJ's output into the desired
JSON-format and I can add now whatever I want to the response.

Kind regards,
- Mitch