XQuery/Basic Search

Motivation
You want to create a basic HTML search page and search service.

Method
We will create two files. One is an HTML form and the other is a RESTful search service that takes a single parameter from the URL which is the search query. The search service will search a collection of XML files.

Here is the base path to our test search collection:

/db/test/search

The data to be searched will be in the following collection:

/db/test/search/data

In "Browse Collections" in the Admin interface, create the collection "test"; create the collection "search" under it; lastly, create the collection "data" under "search". Upload the two XML documents listed under "Sample Data" to "data"; upload "search-form.xq" and "search.xq" to "search" (instead of uploading, you can Save to URL, using oXygen, or use the Webstart client).

/db/test/search/search-form.xq
We will create a basic HTML form that has just one input field for the query.

Note that the action will pass the value from the form to a RESTful service. The only parameter will be "q", the query string.

Search Service
The following file should be placed in /db/test/search/search.xq

Running your Search
To test your search service from a URL, copy the following into the browser navigation toolbar:

http://localhost:8080/exist/rest/db/test/search/search.xq?q=apple

You should see the following result:



To drive this service from a form, click the following link or copy it into your browser navigation toolbar:

http://localhost:8080/exist/rest/db/test/search/search-form.xq