[ 
https://issues.apache.org/jira/browse/SOLR-12947?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16670504#comment-16670504
 ] 

Jason Gerlowski commented on SOLR-12947:
----------------------------------------

The attached patch adds 2 classes to supports JSON DSL requests:

*JsonQueryRequest*

This takes the 1st approach above.  That is, it represents the JSON internally 
as a Map and provides a mix of specific and generic setters for building out 
the map representation.
{code}
class JsonQueryRequest extends QueryRequest
    JsonQueryRequest()
    JsonQueryRequest(SolrParams)
    setQuery(String) // Can take simple queries ("text:foo") or local-params 
syntax ("{!lucene df=text v=foo}")
    setQuery(Map<String, Object>) // For nested or move involved query JSON
    setOffset(int)
    setLimit(int)
    ...
{code}

*DirectJsonQueryRequest*
Follows almost exactly in the footsteps of DirectXmlRequest, except that it 
takes a JSON string instead of an XML string.  In most cases users will 
probably want to use JsonQueryRequest as above, but it's so simple and there's 
a few narrow use cases where it'd be preferable, so I thought it made sense to 
add it. (espec. since there was precedent)
{code}
class DirectJsonQueryRequest extends QueryRequest
    DirectJsonQueryRequest(String jsonString)
    DirectJsonQueryRequest(String jsonString, SolrParams params)
{code}

*Miscellaneous Notes*
* I like the flexibility of allowing users to provides their own Map<String, 
Object> to fill in more involved sections of the JSON structure, but it 
requires users to be familiar with the JSON syntax.  Right know we only have 
this problem with queries, but we'll soon run into it with queries as well.  
It'd be nice to add something to abstract this away in all but the most 
involved cases.  Could create a {{JsonQuery}} class that extends {{Map}} that 
abstracts away the Map-creation for all but the most advanced cases, but not 
sure if that's worth the trouble or not.
* patch has Javadocs, tests, and ref-guide changes, so should be ready to go if 
no one has suggestions on the proposed interface.

> SolrJ Helper for JSON Request API
> ---------------------------------
>
>                 Key: SOLR-12947
>                 URL: https://issues.apache.org/jira/browse/SOLR-12947
>             Project: Solr
>          Issue Type: Improvement
>      Security Level: Public(Default Security Level. Issues are Public) 
>          Components: clients - java, SolrJ
>    Affects Versions: 7.5
>            Reporter: Jason Gerlowski
>            Assignee: Jason Gerlowski
>            Priority: Minor
>         Attachments: SOLR-12947.patch
>
>
> The JSON request API is becoming increasingly popular for sending querying or 
> accessing the JSON faceting functionality. The query DSL is simple and easy 
> to understand, but crafting requests programmatically is tough in SolrJ. 
> Currently, SolrJ users must hardcode in the JSON body they want their request 
> to convey.  Nothing helps them build the JSON request they're going for, 
> making use of these APIs manual and painful.
> We should see what we can do to alleviate this.  I'd like to tackle this work 
> in two pieces.  This (the first piece) would introduces classes that make it 
> easier to craft non-faceting requests that use the JSON Request API.  
> Improving JSON Faceting support is a bit more involved (it likely requires 
> improvements to the Response as well as the Request objects), so I'll aim to 
> tackle that in a separate JIRA to keep things moving.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@lucene.apache.org
For additional commands, e-mail: dev-h...@lucene.apache.org

Reply via email to