Page tree
Skip to end of metadata
Go to start of metadata

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

Allowed methods

  • GET
  • POST

Parameters in routes.groovy:

  • databaseName(String databaseName): name of the database to read data from, use "server!!path/database.nsf" format; when omitted, current database is used

 

POST variant

router.POST('topics/search') {
   strategy(DOCUMENTS_BY_SEARCH_FT) {
   }
   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": "20000*" 
}

 

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

[
    {
        "date_created": "2017-03-03T11:21+00:00",
        "author": "Martin Jinoch",
        "id": "535C4F22B700C9F4C12580D8003F1CB7",
        "topic": "20000"
    },
    {
        "date_created": "2017-03-03T10:21+00:00",
        "author": "Martin Jinoch",
        "id": "6392B0C99AFBB5E5C12580D8003C5D97",
        "topic": "200000"
    }
]

 

GET variant

router.GET('topics/search/{srchFor}') {
   strategy(DOCUMENTS_BY_SEARCH_FT) {
     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.

.