It is possible to do sort using custom fields.
For sorting text/string fields:
The custom field has to be added as a mapping before:
- For custom fields in HTTP, File collection, RSS collection, and custom collection add the fields in ../webapps/searchblox/WEB-INF/mapping.json.
- For custom fields in CSV collections, add the snippet in ./webapps/searchblox/WEB-INF/csv.json.
- For Database collections, add the snippet in ./webapps/searchblox/WEB-INF/jdbc.json.
- For MongoDB collections, add the snippet in ./webapps/searchblox/WEB-INF/mongodb.json.
Add the following snippet in mapping.json, csv.json, jdbc.json, or mongodb.json based on the collection for each custom field. Enter the name of the custom field in the beginning. Showing an example for your reference:
Once you add the custom node in the mapping file please save it and re-index the collection.
Then the custom field can be sorted using the parameters sort and sort by.
For sorting custom date fields:
If the date is in the prescribed format (standard java date formats)
<meta name="published" content="2014-03-15"/>
Then it is not required to add it in mapping.json, and you can directly sort it using the parameters
If the date is in any other format than the standard ones in java, please add it in a specific mapping file along with the date format. However please note that if the date format is not accepted indexing or sorting will not be successful.
To learn about custom fields in search read: Custom fields in Search in SearchBlox