Hi Shibu,
You can invoke a main module from Java using the MarkLogic XCC API, however you
cannot call any functions from a library module written by you. Following is a
sample code to call a main module (search.xqy) from java. Although this is not
like calling a stored procedure, like in the RDBMS world, this is the closest
you can get. You can also send parameters to this main module. In order to do
that you need to declare those as xquery external variable. This is an
MarkLogic extension to xquery.
Following is the java code which executes search.xqy with a parameter 'text'
(with value 'my_param_value'). The database is 'mydb'.
Java code
--------------
String connectionPath = "xcc://admin:admin@localhost:8010/mydb";
URI connectionUri = new URI(connectionPath);
ContentSource contentSource =
ContentSourceFactory.newContentSource(connectionUri);
Session session = contentSource.newSession();
ModuleInvoke xdbcRequest = session.newModuleInvoke(null);
xdbcRequest.setNewStringVariable("text", "my_param_value");
xdbcRequest.setModuleUri("search.xqy");
(:invoke the module and get the result back:)
ResultSequence resultSequence = session.submitRequest(xdbcRequest);
XdmItem valueFromServer = resultSequence.itemAt(0);
Search.xqy
------------
declare variable $params as xs:string external;
<Your xqy code with $params goes here>
However, as Justin suggested, if your search needs suffice with whatever search
functions MarkLogic provides, then you can achieve the same using MarkLogic 6's
bundled java Apis. But, if you need some custom search logic to be coded, you
can either take the XCC route (as the code above) or create a REST service on
top of MarkLogic's HTTP server.
Whether you want XCC or REST on MarkLogic, that is a subjective
decision/personal choice.
Hope this helps.
Sent from my iPad
On 23-Jan-2013, at 6:14 PM,
"[email protected]<mailto:[email protected]>"
<[email protected]<mailto:[email protected]>>
wrote:
Send General mailing list submissions to
[email protected]<mailto:[email protected]>
To subscribe or unsubscribe via the World Wide Web, visit
http://developer.marklogic.com/mailman/listinfo/general
or, via email, send a message with subject or body 'help' to
[email protected]<mailto:[email protected]>
You can reach the person managing the list at
[email protected]<mailto:[email protected]>
When replying, please edit your Subject line so it is more specific
than "Re: Contents of General digest..."
Today's Topics:
1. Help - Will Marklogic support calling query with parameters
(Shibu N)
2. Re: Help - Will Marklogic support calling query with
parameters (Justin Makeig)
3. Re: Help - Will Marklogic support calling query with
parameters (Shibu N)
4. Re: Strcutured query on Ml-6 Rest API (manoj viswanadha)
----------------------------------------------------------------------
Message: 1
Date: Wed, 23 Jan 2013 00:31:06 -0800 (PST)
From: Shibu N <[email protected]<mailto:[email protected]>>
Subject: [MarkLogic Dev General] Help - Will Marklogic support calling
query with parameters
To: [email protected]<mailto:[email protected]>
Message-ID:
<[email protected]<mailto:[email protected]>>
Content-Type: text/plain; charset="us-ascii"
Hi Friends,
I'm relatively new to marklogic and I have a requirement where I'll have to
call a query on the server with parameters using the java API. I'm not sure of
the best approach to do this either. whether to use java API/ REST API's.
The query is of the form http://localhost:8010/search.xq?text=searchtext
The query search.xq simply performs a search based on searchtext and returns
the results,
Any tips would be helpful,
Thanks & Regards
Shibu
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://developer.marklogic.com/pipermail/general/attachments/20130123/2ef27769/attachment-0001.html
------------------------------
Message: 2
Date: Wed, 23 Jan 2013 08:48:17 +0000
From: Justin Makeig
<[email protected]<mailto:[email protected]>>
Subject: Re: [MarkLogic Dev General] Help - Will Marklogic support
calling query with parameters
To: MarkLogic Developer Discussion
<[email protected]<mailto:[email protected]>>
Message-ID:
<548a8e281a113547aebebe56be215ad30b8...@exchg10-be01.marklogic.com<mailto:548a8e281a113547aebebe56be215ad30b8...@exchg10-be01.marklogic.com>>
Content-Type: text/plain; charset="windows-1252"
Shibu, I?d start with the Java API that comes as part of MarkLogic 6. Among
other things, it allows you to manage documents and perform searches. You can
find the ?Java Developer?s Guide? at <http://docs.marklogic.com/guide/java>.
You can also download the JARs (or access the Maven repository) from
<http://developer.marklogic.com/products/java>. The download page has links to
other helpful getting started guides.
If the built-in Java or REST APIs don?t do what you need, you can also build
your own HTTP services, as it appears you?ve started below. However, for common
tasks, such as search, you?ll be duplicating the functionality of REST and Java
APIs that we?ve included in MarkLogic 6.
Justin
Justin Makeig
Director, Product Management
MarkLogic Corporation
[email protected]<mailto:[email protected]>
www.marklogic.com<http://www.marklogic.com>
On Jan 23, 2013, at 12:31 AM, Shibu N
<[email protected]<mailto:[email protected]>>
wrote:
Hi Friends,
I'm relatively new to marklogic and I have a requirement where I'll have to
call a query on the server with parameters using the java API. I'm not sure of
the best approach to do this either. whether to use java API/ REST API's.
The query is of the form http://localhost:8010/search.xq?text=searchtext
The query search.xq simply performs a search based on searchtext and returns
the results,
Any tips would be helpful,
Thanks & Regards
Shibu
_______________________________________________
General mailing list
[email protected]<mailto:[email protected]>
http://developer.marklogic.com/mailman/listinfo/general
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://developer.marklogic.com/pipermail/general/attachments/20130123/33f2390d/attachment-0001.html
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4375 bytes
Desc: not available
Url :
http://developer.marklogic.com/pipermail/general/attachments/20130123/33f2390d/attachment-0001.bin
------------------------------
Message: 3
Date: Wed, 23 Jan 2013 02:21:45 -0800 (PST)
From: Shibu N <[email protected]<mailto:[email protected]>>
Subject: Re: [MarkLogic Dev General] Help - Will Marklogic support
calling query with parameters
To: MarkLogic Developer Discussion
<[email protected]<mailto:[email protected]>>
Message-ID:
<[email protected]<mailto:[email protected]>>
Content-Type: text/plain; charset="utf-8"
Thanks Justin for that Info,
I did do some reading into the java API's. I have seen examples searching for
documents, but in this case I'm trying to invoke the search.xq file using the
API. Just wanted to know if this is possible. The search.xq file is like a
stored procedure which would give me the required results by accepting the
parameters for searchtext.
Thanks & Regards
Shibu
--- On Wed, 1/23/13, Justin Makeig
<[email protected]<mailto:[email protected]>> wrote:
From: Justin Makeig
<[email protected]<mailto:[email protected]>>
Subject: Re: [MarkLogic Dev General] Help - Will Marklogic support calling
query with parameters
To: "MarkLogic Developer Discussion"
<[email protected]<mailto:[email protected]>>
Date: Wednesday, January 23, 2013, 12:48 AM
Shibu, I?d start with the Java API that comes as part of MarkLogic 6. Among
other things, it allows you to manage documents and perform searches. You can
find the ?Java Developer?s Guide? at <http://docs.marklogic.com/guide/java>.
You can also download the JARs (or access the Maven repository) from
<http://developer.marklogic.com/products/java>. The download page has links to
other helpful getting started guides.?If the built-in Java or REST APIs don?t
do what you need, you can also build your own HTTP services, as it appears
you?ve started below. However, for common tasks, such as search, you?ll be
duplicating the functionality of REST and Java APIs that we?ve included in
MarkLogic 6.
Justin
Justin Makeig
Director, Product Management
MarkLogic Corporation
[email protected]<mailto:[email protected]>
www.marklogic.com<http://www.marklogic.com>
On Jan 23, 2013, at 12:31 AM, Shibu N
<[email protected]<mailto:[email protected]>>?wrote:
Hi Friends,
I'm relatively new to marklogic and I have a requirement where I'll have to
call a query on the server with parameters using the java API. I'm not sure of
the best approach to do this either. whether to use java API/ REST API's.
The query is of the form http://localhost:8010/search.xq?text=searchtext
The query search.xq simply performs a search based on searchtext and returns
the results,
Any tips would be helpful,
Thanks & Regards
Shibu_______________________________________________
General mailing list
[email protected]<mailto:[email protected]>
http://developer.marklogic.com/mailman/listinfo/general
-----Inline Attachment Follows-----
_______________________________________________
General mailing list
[email protected]<mailto:[email protected]>
http://developer.marklogic.com/mailman/listinfo/general
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://developer.marklogic.com/pipermail/general/attachments/20130123/0392bdc0/attachment-0001.html
------------------------------
Message: 4
Date: Wed, 23 Jan 2013 18:13:46 +0530
From: manoj viswanadha
<[email protected]<mailto:[email protected]>>
Subject: Re: [MarkLogic Dev General] Strcutured query on Ml-6 Rest API
To: MarkLogic Developer Discussion
<[email protected]<mailto:[email protected]>>
Message-ID:
<CAEe++vLf-RKokxviiaCiCzjmPN2fyEwx2kG84WpF=flnpb4...@mail.gmail.com<mailto:CAEe++vLf-RKokxviiaCiCzjmPN2fyEwx2kG84WpF=flnpb4...@mail.gmail.com>>
Content-Type: text/plain; charset="iso-8859-1"
Hi Erik,
Thanks for your quick reply. I want to use structured query without passing
options. i want to directly pass everything in the
service as like corona structured query. Is there any way to use this rest
API?
Thanks,
Manoj
On Tue, Jan 22, 2013 at 10:06 PM, Erik Hennum
<[email protected]<mailto:[email protected]>>wrote:
Hi, Majoj:
A structured query has two parts:
* Persisted query options that identify the indexes you're querying
against.
* A query that supplies the criteria and any boolean composers for the
criteria.
This two-part structure makes it possible to supply the query either with
a Google-like string or with a structure.
In JSON, here's the options structure for an element value query:
{"options":{"constraint":[
{"name":"YOUR_CONSTRAINT_NAME",
"value":{"element":{
"name":"YOUR_ELEMENT_NAME",
"ns":"YOUR_ELEMENT_NAMESPACE"}}}]}}
Here's the query structure for an element value query:
{"query":{"queries":[
{"value-constraint-query":{
"constraint-name":"YOUR_CONSTRAINT_NAME",
"text":["YOUR_CRITERIA_VALUE"]}}]}}
For more detail, please see:
http://docs.marklogic.com/guide/rest-dev/search
Erik Hennum
------------------------------
*From:*
[email protected]<mailto:[email protected]>
[
[email protected]<mailto:[email protected]>]
on behalf of manoj viswanadha [
[email protected]<mailto:[email protected]>]
*Sent:* Tuesday, January 22, 2013 1:28 AM
*To:* MarkLogic Developer Discussion
*Subject:* [MarkLogic Dev General] Strcutured query on Ml-6 Rest API
HI all,
I have explored the different Features on ML-6 Rest API.
I have a small requirement where i will be using strcuturedQuery with
element-value-query.
I want to search my results based on the particular element which i tried
using below.
*http://localhost/v1/search?structuredQuery=*
* {"query":*
*{"element-value-query":*
* {"element-name":"name of the element",*
*"text":["some value"]}}}&collection=collectionname&format=xml*
*
*
Above query should search for the element with particular value but its
giving all the results in database.
Can anyone help me in achieving this or how we can use structured query
with any cts:query.
Thanks,
Manoj.
_______________________________________________
General mailing list
[email protected]<mailto:[email protected]>
http://developer.marklogic.com/mailman/listinfo/general
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://developer.marklogic.com/pipermail/general/attachments/20130123/dcc6f94e/attachment.html
------------------------------
_______________________________________________
General mailing list
[email protected]<mailto:[email protected]>
http://developer.marklogic.com/mailman/listinfo/general
End of General Digest, Vol 103, Issue 31
****************************************
"This e-mail and any files transmitted with it are for the sole use of the
intended recipient(s) and may contain confidential and privileged information.
If you are not the intended recipient, please contact the sender by reply
e-mail and destroy all copies of the original message. Any unauthorized review,
use, disclosure, dissemination, forwarding, printing or copying of this e-mail
or any action taken in reliance on this e-mail is strictly prohibited and may
be unlawful."
_______________________________________________
General mailing list
[email protected]
http://developer.marklogic.com/mailman/listinfo/general