{"id":28408821,"url":"https://github.com/cfoster/xquery-exercise","last_synced_at":"2026-01-28T21:01:32.099Z","repository":{"id":20272118,"uuid":"23545225","full_name":"cfoster/xquery-exercise","owner":"cfoster","description":"XQuery Exercise fun","archived":false,"fork":false,"pushed_at":"2014-09-01T19:17:46.000Z","size":144,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-30T04:40:48.927Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"XQuery","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cfoster.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-09-01T14:30:00.000Z","updated_at":"2014-09-01T15:24:45.000Z","dependencies_parsed_at":"2022-09-18T23:51:02.866Z","dependency_job_id":null,"html_url":"https://github.com/cfoster/xquery-exercise","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/cfoster/xquery-exercise","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cfoster%2Fxquery-exercise","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cfoster%2Fxquery-exercise/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cfoster%2Fxquery-exercise/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cfoster%2Fxquery-exercise/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cfoster","download_url":"https://codeload.github.com/cfoster/xquery-exercise/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cfoster%2Fxquery-exercise/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28851838,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-28T15:15:36.453Z","status":"ssl_error","status_checked_at":"2026-01-28T15:15:13.020Z","response_time":57,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-06-02T04:37:49.238Z","updated_at":"2026-01-28T21:01:32.082Z","avatar_url":"https://github.com/cfoster.png","language":"XQuery","funding_links":[],"categories":[],"sub_categories":[],"readme":"# XQuery Exercise and Answers\n\n## XQuery Exercise\r\rA MarkLogic database contains 100 million documents similar to the sample in appendix A. Each document is in a collection \"data\" and a collection \"data-NAME\" where NAME is the type of the document.\r\rYou are required to write a web service in XQuery for MarkLogic that allows a client to search for documents in the database and return documents similar to Appendix B:\r\r1. The search service will have the URL: `/search?q=term`\r\r2. The client can search for a word occurring anywhere in the documents.\n\r\r3. The client should be able to restrict the search to the elements `\u003ctitle\u003e` and/or `\u003csynopses\u003e`.\r\r4. The client should be able to restrict the search to only documents with a specific type.\n\rAll search information must be contained in the \"q\" parameter.\r\rPlease provide the XQuery code for your search service and any MarkLogic specific configuration settings required to make it work.\n\r\r### Appendix A\n\r```xml\r\u003cclip revision=\"2\" pid=\"p01gd0zf\"\u003e \u003cpartner\u003e\r\u003clink pid=\"s0000001\"/\u003e\r\u003c/partner\u003e\r\u003cids\u003e\r\u003cid type=\"pid\"\u003e\rp01gd0zf\r\u003c/id\u003e\r\u003c/ids\u003e\r\u003cmaster_brand/\u003e\r\u003ctitle\u003e\rXiaomi: Global plans for Chinese smartphone maker\r\u003c/title\u003e\r\u003csynopses\u003e\r\u003csynopsis length=\"short\"\u003e\rGlobal plans for Chinese phone maker\r\u003c/synopsis\u003e\r\u003csynopsis length=\"medium\"\u003e\rXiaomi chief executive, Lei Jun, plans to start selling phones outside China. \u003c/synopsis\u003e\r\u003csynopsis length=\"long\"\u003e\rThe chief executive of Xiaomi, Lei Jun, tells the BBC that he plans to sell his company's smartphones outside China.\r\u003c/synopsis\u003e\r\u003c/synopses\u003e\r\u003cgenres/\u003e\r\u003cformats/\u003e\r\u003cmedia_type value=\"audio_video\"/\u003e\r\u003cshoot_date/\u003e\r\u003c/clip\u003e\n\r```\n\r\n### Appendix B\n\r```xml\n\u003cclip\u003e\r\u003cpid\u003ep01gd0zf\u003c/pid\u003e\r\u003cpartner\u003es0000001\u003c/partner\u003e\r\u003cupdated_time\u003e2013-09-10T01:44:43Z\u003c/updated_time\u003e\r\u003ctitle\u003eXiaomi: Global plans for Chinese smartphone maker\u003c/title\u003e\r\u003csynopses\u003e\r\u003cshort\u003eGlobal plans for Chinese phone maker\u003c/short\u003e\r\u003cmedium\u003eXiaomi chief executive, Lei Jun, plans to start selling phones outside China. \u003c/medium\u003e\r\u003clong\u003eThe chief executive of Xiaomi, Lei Jun, tells the BBC that he plans to sell his company's smartphones outside China.\u003c/long\u003e\r\u003c/synopses\u003e\r\u003cmedia_type\u003eVideo\u003c/media_type\u003e\r\u003c/clip\u003e\n\r```\n\n\n## **Answers** (2 Methods)\n\nI created two XQuery search apps to demonstrate how to solve the problem, \"Method 1\" and \"Method 2\".\n\n## Method 1 (Simple)\n\n### How it works\n\nThe first approach is quite basic and simple.\n\n* Basic URL rewriter\n* Uses the Search API to search and parse the users query\n* Transforms results using just XQuery\n\n### Files used in Method 1\n\n```\n/method-1/search.xqy\n/method-1/rewriter.xqy\n/method-1/clip-transform.xqy\n```\n\n### Specific Setup/Config\n* port: 8080\n* rewrite handler: /method-1/rewriter.xqy\n* default user: admin\n* authentication: application-level\n* Modules: Modules (Load Modules into the Modules database)\n* Collection lexicon **is required** for this `search:search` example\n\n\n## Method 2 (More advanced)\n\n### How it works and why\n\nThe second approach is perhaps more flexible for a larger solution.\n\n* Uses Jim Fuller's RXQ [2] (RESTXQ implementation) as a URL Rewriter.\n  * RESTXQ is like JAX-RS, but for XQuery, introduced at XML Prague 2012 [1].\n* Uses Michael Blakeley's XQYSP [3] library instead of MarkLogic's Search API.\n  * If a user has exact requirements, you can always create your own search grammer and use the REx Parser Generator [4].\n* Result items are transformed by XSLT instead of XQuery.\n* Added in a little pagination which also stops millions of results potentially coming through (if there were millions).\n  \n### Files used in Method 2\n\n```\n/method-2/search-entry-point.xqy\n/method-2/xsl/clip-transform.xsl\n\nAnd module library files taken from XQYSP and RXQ:\n\n/lib/query-eval.xqy\n/lib/rxq-rewriter.xqy\n/lib/rxq.xqy\n/lib/xqysp.xqy\n```\n\n### Specific Setup/Config\n\n* port: 80\n* error handler: /lib/rxq-rewriter.xqy?mode=error\n* rewrite handler: /lib/rxq-rewriter.xqy?mode=rewrite\n* default user: admin\n* authentication: application-level\n* Modules: Modules (Load Modules into the Modules database)\n\n\n[1]: http://archive.xmlprague.cz/2012/sessions.html#RESTful-XQuery---Standardised-XQuery-3.0-Annotations-for-REST\n[2]: https://github.com/xquery/rxq\n[3]: https://github.com/mblakele/xqysp\n[4]: http://www.bottlecaps.de/rex/","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcfoster%2Fxquery-exercise","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcfoster%2Fxquery-exercise","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcfoster%2Fxquery-exercise/lists"}