So new to MarkLogic am stuck and not finding the documentation of use. I know what i need to do, just do not know how to do it.
I have a keyvalue? search on my REST server which returns ML's standard search results and XML snippet. I want to create my own custom search result which will output a title element for my XML files.
I am aware that i need to create an XSLT transformation document and upload that to the server but do not know how to target ML's search function or how to write this out.
I have basic knowledge of XSLT, if i just created something that targets each files title using xPath will this work, or does ML require use of their custom functions?
I know its a bit broad, but hopefully someone can point steer me.
Sounds like you are talking about the GET /v1/keyvalue endpoint of MarkLogic REST API. Unfortunately that does not allow you to choose a transform. You can probably use GET /v1/search with a transform param instead though, using a structured query for an element value query. The docs contain a good syntax reference on that.
Docs on creating and managing transforms can be found here:
http://docs.marklogic.com/guide/rest-dev/transforms#chapter
HTH!
You can use extract-metadata in your search options with search:search or the /v1/search/ REST API endpoint to include the title element in a metadata element or JSON property in your results:
import module namespace search = "http://marklogic.com/appservices/search"
at "/MarkLogic/appservices/search/search.xqy";
search:search(
"my query string",
<options xmlns="http://marklogic.com/appservices/search">
<extract-metadata>
<qname elem-ns="" elem-name="title"/>
</extract-metadata>
</options>)
If you need more flexibility, you specify a custom snippet implementation or a results decorator function in your search options.
Is this key-value or full text? For key-value you could use XPath. Any XPath that starts with / or // or fn:collection() or fn:doc() will search the entire database. You can search specific document(s) or collection(s) too.
For full text you'd probably want to use https://docs.marklogic.com/search:search - or possibly https://docs.marklogic.com/cts:search for really low-level control.
There's some example code using search:search from XSL at https://github.com/marklogic/RunDMC which might help. It doesn't use the REST API: it's a traditional form-submit web page. But the view/search.xsl code might give you some idea how to call the search API from XSLT.
That RunDMC code might also help you if you need to call XSL from XQuery: take a look at controller/transform.xqy.
Related
How can I create a services in Capella and call it in my M2DOC Word document?
I want, for example, create a services for print a functional tree, and use this code in many different documents without re-write every time the code.
Thank you a lot.
Stefania
It seems this section of the documentation explains what you want to do: https://www.m2doc.org/ref-doc/nightly/index.html#providing-new-services
I have application in Angularjs2, and developers have not been using ids into it. Now I have to implement the Protractor on same application. Is there anyway to implement the Protractor without using "absolute XPath"?
Thanks in advance!
Please find a huge range of locator-possibilities on the official Protractortest API Page
Every element on a page needs to be uniquely identifiable... else the page wouldn't work, no matter which technology. Therefore with the help of any of the above provided locator-possibilities you'll always find the element you're looking for.
And there is never a need for XPath, except for this only one. (though there is an parentElementArrayFinder introduced in the meantime, so not even that one exception is valid anymore)
UDPATE
If you could use XPath, you can for sure use CSS-Locators.
Here some examples for locators:
$('div.class#id[anyAttribute="anyValue"] div.child.somewhere-below-div-point-class')
element(by.cssContainingText('div[data-index="2"]', 'select this option'))
Or as a specific example the "Learn More" of the "Tree List" section of https://js.devexpress.com/ :
treeListSection = element(by.cssContainingText('div.tab-content h2', 'Tree List')).getDriver();
learnMoreBtn = treeListSection.element(by.cssContainingText('a.tab-button','Learn More'));
learnMoreBtn.click();
Those are just examples, but there is always a way to do it.
If you provide some example-HTML in your Question, I can direct you towards a solution.
UPDATE 2
For getting the Parent Web Element, one could use getDriver() as well
I want to search a tag under /etc/tags in AEM programmatically.
for ex:
folder structure is like
/etc/tags/
uder tags there are multiple tags
1.20101/ate2
2.73883
3.44qqiw
4.222
if i want to search ate2 i should get /etc/tags/20101/ate2.
You can use QueryBuilder API to query it.
Sample Query would be
type=cq:Tag
path=/etc/tags
nodename=ate2
Sample SQL2 Query for the same would be
select * from [cq:Tag] as s where ISDESCENDANTNODE('/etc/tags') AND NAME(s)='ate2'
One solution is write the query as suggested by rakhi, other is to utilize TagManager API that provides you lot of methods to search tags and once you get Tag instance you could get path from it. Javadocs for TagManager can be found here and for Tag here
For reference you could look at the code here. One thing to keep in mind in case you end up using this approach you will need to work by creating a system user to get ResourceResolver instead of calling resolverFactory.getAdministrativeResourceResolver(null), refer to article here
I understand how to use Xpath
http://localhost:8080/exist/rest/db/movies?_query=//movie[title=%22Spider-Man%22]/node()
But how to pass an xquery query? I keep reading everywhere that the REST api is for both xpath and xquery but I can't get my query to work. Here is what I'm trying to pass as an example (I've tested this in the xquery sandbox and it works):
for $movie in doc("movies/movies.xml")/movies/movie[year > 2002]
return <movie> { ($movie/title, $movie/year) } </movie>
How do I pass this in a URL? I dont really know where to start so I've tried just pasting the query above as the GET param, similar to the xpath query. So the url I pass is
http://localhost:8080/exist/rest/db/movies/?_query=for%20$movie%20in%20doc(%22movies/movies.xml%22)/movies/movie[year%20%3E%202002]%20return%20%3Cmovie%3E%20{%20($movie/title,%20$movie/year)%20}%20%3C/movie%3E
The page I get back is this
Am I going about this totally the wrong way? "movies" is a collection in my db.
It looks like your query was successfully executed. The <exist:result/> element looks quite correct, but it simply didn't find any movies which fit your filter criteria. It might also be a namespace issue. You should try your query locally to see if it returns something.
Your <script id="tinyhippos-injected"/> element is rather weird, as I did not expect tiny hippos here. However, this seems to be due to some Chrome extension you use.
Also, if your XQuery is a bit longer a URL paramter will not do and the encoding is difficult to read and maintain anyways. You might want to take a look at the eXist documentation about how to submit a POST request with an XQuery.
We have quite a number of .xqy files in several folders.
Sometimes, I need to invoke an .xqy file (via Marklogic's CQ) to test if it's working.
But I find it rather cumbersome to have to know what parameters to pass in and specify them in the xquery in CQ.
Is there a tool out there that would generate an HTML form that presents to me the parameters of a given .XQY file and invokes it when I press a "submit" button ?
If there is none out there, would somebody here know of how to make such an HTML form ? Right now, I can't seem to find any readily-available xdmp or xquery commands to tell me if an .XQY file is invocable or what parameters it expects to be fed.
Danny
The XQuery standard doesn't support introspection, nor does MarkLogic provide any functions that help with that. The closest you can get with this is using the XQDoc documentation code that is capable of parsing the XQuery code itself and producing descriptions of all function signatures within modules.
You can find more details about it here: http://developer.marklogic.com/code/xqdoc-ws
It doesn't provide a 'Submit' button, but using the XML output of xqdoc, you could make that yourself..
Good luck!
Another option would be to convert your XQuery to XQueryX and you can then process this as XML using XQuery (or XSLT) to generate an XForm or XHTML Form.
Since Danny mentioned unit testing, I'll risk plugging my own framework for that: https://github.com/mblakele/xqut
I usually run XQUT test suites in a cq buffer, but it would be easy enough to wrap one in a simple web page - with or without a form.