These are the sample XMLs I'm uploading to my database:
<?xml version="1.0" encoding="UTF-8"?>
<AXFRoot>
<MAObject type="default" mdclass="NEWS_VIDEO" label="News Video">
<ID name="">123456</ID>
<Meta name="MAINTITLE" format="string" label="Title">Clifford Irving hugs his wife Edith after her release from a Nassau jail.</Meta>
<Meta name="SYSTEM_OBJECTOWNER" format="string" label="Owner">DEFAULT</Meta>
<Meta name="KEYWORDS" format="string" label="Keywords">clifford-irving edith-irving prisoner-releases 1972-08-18 nassau new-york US nassau-county-jails prisons wifes husbands media, [],</Meta>
</MAObject>
<AXFRoot>
<?xml version="1.0" encoding="UTF-8"?>
<AXFRoot>
<MAObject type="default" mdclass="NEWS_VIDEO" label="News Video">
<ID name="">456123</ID>
<Meta name="MAINTITLE" format="string" label="Title">CAMEL NEWS CARAVAN- SEGMENT 2: US Military women march in Formosa in 1950.</Meta>
<Meta name="SYSTEM_OBJECTOWNER" format="string" label="Owner">DEFAULT</Meta>
<Meta name="KEYWORDS" format="string" label="Keywords">Military women-march Formosa-in-1950 United-States-army US</Meta>
</MAObject>
<AXFRoot>
<?xml version="1.0" encoding="UTF-8"?>
<AXFRoot>
<MAObject type="default" mdclass="NEWS_VIDEO" label="News Video">
<ID name="">78946</ID>
<Meta name="MAINTITLE" format="string" label="Title">Commercial US Title</Meta>
<Meta name="SYSTEM_OBJECTOWNER" format="string" label="Owner">DEFAULT</Meta>
<Meta name="KEYWORDS" format="string" label="Keywords">commercial 2009 english advertisement movie parts</Meta>
</MAObject>
<AXFRoot>
What I want to do here is that, when I search for the word US by /search?q=US, I want the query result to have a data field in JSON which contains all the places which has the word US.
Eg : data :{clifford-irving edith-irving prisoner-releases 1972-08-18 nassau new-york US nassau-county-jails prisons wifes husbands media, [],CAMEL NEWS CARAVAN- SEGMENT 2: US Military women march in Formosa in 1950.Military women-march Formosa-in-1950 United-States-army US Commercial US Title}
Is there a way of doing such queries in MarkLogic?
Using the Search API, you can get back an XML structure with a snippet showing each match in context.
You might need to specify a large max-snippet-chars value to make sure you get the entire snippet text:
Anyway, you can then transform the XML structure into a JSON object. For instance, using the REST API, you can specify a post-processing transform for search:
By the way, the XML vocabulary appears to provide markup semantics via attribute values (especially the name attribute). To be able to index and restrict search matches based on the markup semantics, you should consider changing the model so that the values are the markup, as in a MAINTITLE element and a OBJECTOWNER element. Generic markup like a meta element is not useful to index.
Hoping that helps,