These are the documents I have inserted in the database.
<biblio>
<biblioid>123</biblioid>
<mediaid>456</mediaid>
<name>dixit</name>
<title>title</title>
</biblio>
<biblio>
<biblioid>456</biblioid>
<mediaid>789</mediaid>
<name>singla</name>
<title>title1</title>
</biblio>
<media>
<mediaid>456</mediaid>
<mediaName>media1</mediaName>
<title>hello</title>
</media>
<media>
<mediaid>789</mediaid>
<mediaName>media1</mediaName>
<title>hello</title>
</media>
<media>
<mediaid>384</mediaid>
<mediaName>media2</mediaName>
<title>hello</title>
</media>
I want to search those documents having <name>
in <biblio>
as "Dixit" and <medianame>
in <media>
as "media1".
But it should check of only those documents having <mediaid>
is same as in biblio/mediaid
As in our case, the result will be
<biblio>
<biblioid>123</biblioid>
<mediaid>456</mediaid>
<name>dixit</name> <!-- name is matching ("dixit")-->
<title>title</title>
</biblio>
<media>
<mediaid>456</mediaid> <!-- mediaid is same as in biblio/mediaid -->
<mediaName>media1</mediaName> <!-- medianame is matching ("media1") -->
<title>hello</title>
</media>
I can achieve this, first by getting all the biblio docs matching the name ("dixit") then from the results I will extract the mediaid's(456) and then will query the media documents with fetched mediaid's(456) and medianame(media1).
But I want to achieve this by search:search API.
Is there any way to make this happen and Is there any place where I can define the relationship between elements of xmls.
If you put a range index on the media:id, then you will be able to do some super-fast joins. That is 1/2 the battle.
The other half is: If I wanted to do this problematically, I would do it via cts and xQuery.
BUT: If I did want to do this as part of search:search, I would do it with custom constraints - then naturally call them via the search:search library.
A possible custom constraint: biblio-by-media-name
Then if I also had a constraint on the biblio-name called "biblio-name" then I could have a search something like the below example - all delivered via the search api in the end:
biblio-name:Dixit AND biblio-by-media-name:media1
* Note that the document-query is one approach. However, I would possibly build this not on the biblio URI, but perhaps on a range-query on the mediaid element in the biblio files. But that is all about tuning. The results will be the same in the more simplified example above.
https://docs.marklogic.com/guide/search-dev/search-api#id_49750