Hi Sini,

I started a reply yesterday to this that got lost somewhere over Germany.

The JSON you've included looks like one tailored to hit the built app itself, not the Search API. How did you construct this JSON? It just doesn't look right to me for any of the APIs that we currently have.

The REST API (and AppBuilder) use the MarkLogic Search API under the covers. As of MarkLogic 6 you can use the Search API with XML or JSON configuration.

Here's a JSON query I just grabbed (using firebug) from the oscars example application.

|{"query":{"qtext":"d","and-query":{"queries":[{"range-constraint-query":{"constraint-name":"award","value"||:["lead-actor"]}}]}}}
|
The URL is was sent to was:

http://localhost:8003/v1/search?format=json&view=all&options=all&start=1&pageLength=10

In order to mimic this in QC, you'd need the "all" options node and the query above, transformed into XML. I can GET the contents of the "all" options at

http://localhost:8003/v1/config/query/all

Here's how we transform that query (I don't think this is supposed to be documented at ML6, because of how we configure JSON-XML transforms -- the magic is in the $config. I'm assuming you want gory details). There will be a public function for it someday.

xquery version "1.0-ml";
import module namespace json = "http://marklogic.com/xdmp/json"; at "/MarkLogic/json/json.xqy";

import module namespace sut = "http://marklogic.com/rest-api/lib/search-util";
    at "/MarkLogic/rest-api/lib/search-util.xqy";

json:transform-from-json(
'{"query":{"qtext":"d","and-query":{"queries":[{"range-constraint-query":{"constraint-name":"award","value":["lead-actor"]}}]}}}',
$sut:json-config-query)

I'll paste in the whole search:resolve code now so you can see if you get what's going on. The options actually used in appbuider apps are far bigger than what I've included here:

xquery version "1.0-ml";

import module namespace search = "http://marklogic.com/appservices/search";
    at "/MarkLogic/appservices/search/search.xqy";

import module namespace json = "http://marklogic.com/xdmp/json"; at "/MarkLogic/json/json.xqy";

import module namespace sut = "http://marklogic.com/rest-api/lib/search-util";
    at "/MarkLogic/rest-api/lib/search-util.xqy";

let $query := json:transform-from-json(
'{"query":{"qtext":"d","and-query":{"queries":[{"range-constraint-query":{"constraint-name":"award","value":["lead-actor"]}}]}}}',
$sut:json-config-query)
return search:resolve($query, <search:options xmlns:search="http://marklogic.com/appservices/search";>
  <search:constraint name="award">
<search:range collation="http://marklogic.com/collation/"; type="xs:string" facet="true">
<search:facet-option>limit=10</search:facet-option>
      <search:attribute ns="" name="award"/>
      <search:element ns="http://marklogic.com/wikipedia"; name="nominee"/>
    </search:range>
  </search:constraint>
</search:options>)

Hope that helps not confuse things more !

Charles






On 02/11/2013 02:20 PM, David Lee wrote:
I don't want to leave you hanging, but someone from the App Services team is probably 
better to answer your questions which are App Builder and REST API specific.  My answers 
were with respect to how things work "under the hood" in the server itself.



-----------------------------------------------------------------------------
David Lee
Lead Engineer
MarkLogic Corporation
[email protected]
Phone: +1 812-482-5224
Cell:  +1 812-630-7622
www.marklogic.com<http://www.marklogic.com/>


From: [email protected] 
[mailto:[email protected]] On Behalf Of sini narayanan
Sent: Monday, February 11, 2013 8:34 AM
To: MarkLogic Developer Discussion
Subject: Re: [MarkLogic Dev General] Search Query

Hi David,

Thanks. I have already gone through the search and rest-api guides. But I'm 
still not able to figure out a solution for my requirement.

I have the an application built using app builder. I have done some 
customization in the application. The customization is as below:
1. When a user performs a search and clicks on the "Export" link (custom link 
created) in the results page, a new document is getting generated in the DB.

2. The new document created in the DB has the json query string as an entry in 
it.
Example of the document in DB:
<QueryString>{"text":"","page":1,"facets":{"city":{"constraintType":"range","noShadow":true,"value":["Paris"]}}}</QueryString>

3. Now, what I need to know is, how do I reproduce my search results by 
executing this json query string?

4. It is said that the json has to be converted into xml. Which is the function 
that I should use, json:transform-from-json() OR xdmp:from-json?

5. If I get an xml format, how do I call the search:search to perform the 
query. In the above example, I need to search for city:Paris.


Please help.

Thanks,
Sini

On Mon, Feb 11, 2013 at 5:51 PM, David Lee 
<[email protected]<mailto:[email protected]>> wrote:
Ultimately AppBuilder ends up using search:search or cts:search in "the back 
end"  (MarkLogic DB).
JSON is converted to XML to perform the searches.

A good start for understanding search concepts from the server perspective is :
http://docs.marklogic.com/guide/search-dev

JavaScript code in AppBuilder uses the REST API which under the hood uses the 
above.
http://docs.marklogic.com/guide/rest-dev




-----------------------------------------------------------------------------
David Lee
Lead Engineer
MarkLogic Corporation
[email protected]<mailto:[email protected]>
Phone: +1 812-482-5224<tel:%2B1%20812-482-5224>
Cell:  +1 812-630-7622<tel:%2B1%20812-630-7622>
www.marklogic.com<http://www.marklogic.com/>

From: 
[email protected]<mailto:[email protected]>
 
[mailto:[email protected]<mailto:[email protected]>]
 On Behalf Of sini narayanan
Sent: Sunday, February 10, 2013 11:57 PM
To: MarkLogic Developer Discussion
Subject: [MarkLogic Dev General] Search Query

Hi all,

How exactly is the search happening at the backend when we search for a 
particular document in the application builder?
Is it in json format or something else. Please calrify.
In the controller.js file, I noticed that the query string formed is in json 
format. Is this json query converted into some other format to search the DB?

If I have a json query, how do I search DB with the same.

For example: If i have the json query like below, can I use the same to query 
the DB seperately in QC.

{"text":"","page":1,"facets":{"city":{"constraintType":"range","noShadow":true,"value":["Paris"]}}}

Thanks,
Sini

_______________________________________________
General mailing list
[email protected]<mailto:[email protected]>
http://developer.marklogic.com/mailman/listinfo/general




_______________________________________________
General mailing list
[email protected]
http://developer.marklogic.com/mailman/listinfo/general

--
Charles Greer
Senior Engineer
MarkLogic Corporation
[email protected]
Phone: +1 707 408 3277
www.marklogic.com

_______________________________________________
General mailing list
[email protected]
http://developer.marklogic.com/mailman/listinfo/general

Reply via email to