Use this strategy to select documents from the database using full-text search.

Allowed methods

Parameters in routes.groovy:

 

Both GET and POST calls expect these parameters to be passed:

POST variant

router.POST('topics/search') {
   strategy(DOCUMENTS_BY_SEARCH_FT_PAGED) {
   }
   mapJson 'id', json:'id', type:'STRING', isformula:true, formula:'@DocumentUniqueID'
   mapJson "date", json:'date_created',type:'DATETIME',isformula:true, formula:'@Created'
   mapJson "topic", json:'topic', type:'STRING'
   mapJson "author", json:'author', type:'STRING',isformula:true,formula:'@Name([CN]; @Author)'
}

 

With route defined above, POSTing following JSON

{
    "search": "10000*",
    "start": 1,
    "count": 5
}

 

to URL http://server.name/path-to/db.nsf/xsp/.xrest/topics/search will return all documents from database containing "20000*", such as

{
    "entries": [
        {
            "date_created": "2017-03-03T11:01+00:00",
            "author": "Martin Jinoch",
            "id": "E044D66CFEA6735AC12580D8003F43C7",
            "topic": "10000"
        },
        {
            "date_created": "2017-03-03T11:01+00:00",
            "author": "Martin Jinoch",
            "id": "66671AF824F5A3D3C12580D8003DE435",
            "topic": "100002"
        },
        {
            "date_created": "2017-03-03T11:01+00:00",
            "author": "Martin Jinoch",
            "id": "F52C541EC8EF970EC12580D8003DE437",
            "topic": "100000"
        },
        {
            "date_created": "2017-03-03T11:01+00:00",
            "author": "Martin Jinoch",
            "id": "01ED9C403BE0ED4FC12580D8003DE436",
            "topic": "100001"
        },
        {
            "date_created": "2017-03-03T11:01+00:00",
            "author": "Martin Jinoch",
            "id": "393C379E0527C246C12580D8003DE434",
            "topic": "100003"
        }
    ],
    "start": 1,
    "total": 11,
    "count": 5
}

 

GET variant

router.GET('topics/search/{srchFor}') {
   strategy(DOCUMENTS_BY_SEARCH_FT_PAGED) {
     ftQuery('srchFor') //Available since Beta 4 
   }
   mapJson 'id', json:'id', type:'STRING', isformula:true, formula:'@DocumentUniqueID'
   mapJson "date", json:'date_created',type:'DATETIME',isformula:true, formula:'@Created'
   mapJson "topic", json:'topic', type:'STRING'
   mapJson "author", json:'author', type:'STRING',isformula:true,formula:'@Name([CN]; @Author)'
}

For GET you can define ftQuery placeholder like shown above and use URL like http://server.name/path-to/db.nsf/xsp/.xrest/topics/search/10000* or you can be passing the search parameter in the URL like this http://server.name/path-to/db.nsf/xsp/.xrest/topics/search?search=10000* In this case do not include the placeholder in the router path definition, ie. router.GET('topics/search')

Note: ftQuery takes precedence, so if you add ?search= to the URL, it will be ignored.

Format of the returned JSON is identical as for POST variant.

Related articles

Related articles appear here based on the labels you select. Click to edit the macro and add or change labels.

Related issues