Custom Fields in Search

Adding Custom Fields as facet filter in Faceted Search

SearchBlox fields such as title, keywords, language, etc., as well as custom fields such as meta fields for WEB collections, author and subject fields for file collections can be added as facets in faceted search. All fields indexed through CSV, Database and MongoDB collections can also be added as facets in faceted search.

Steps to Add Facets

🚧

Important:

When a new Collection is created, corresponding mapping.json file will be created inside ../webapps/ROOT/WEB-INF/mappings/collections folder.
Example : mapping_001.json

Step 1:
Stop SearchBlox.

Step 2:
For custom fields in all collections, add the fields in mapping.json file inside ../webapps/ROOT/WEB-INF/mappings/collections folder.

Example:
Add the following snippet in mapping.json(Example : mapping_001.json) based on the collection for each custom field. Enter the name of the custom field in the beginning
"customfieldname": {
"type": "text",
"store": true,
"fielddata": true,
"analyzer": "comma_analyzer"
},

Example:
"subject": {
"type": "text",
"store": true,
"fielddata": true,
"analyzer": "comma_analyzer"
},

564564

❗️

Add the preceding snippet without making any syntax errors. Add the field after another field without missing any commas.

Step 3:
In order to add these facets, the facets need to be updated in ../webapps/ROOT/search/facet.js
as shown:

"facets": [{
            "field": "colname",
            "display": "Collection Name",
            "size": "10"
        },
         {
            "field": "subject",
            "display": "Subject",
            "size": "10"
        },
        {
            "field": "contenttype",
            "display": "File Type",
            "size": "10"
        },
        {
            "field": "keywords",
            "display": "keywords",
            "size": "10"
        },
        {
            "field": "lastmodified",
            "display": "Last Modified",
            "dateRange": [{
                    "name": "Last 24 hours",
                    "calendar": "days",
                    "value": "1"
                },
                {
                    "name": "Past Week",
                    "calendar": "days",
                    "value": "7"
                },
                {
                    "name": "Past Month",
                    "calendar": "months",
                    "value": "1"
                },
                {
                    "name": "Past Year",
                    "calendar": "years",
                    "value": "1"
                }
            ]
        }
    ],

Step 4:
Start SearchBlox and reindex.

❗️

  • Custom fields will only be added as filter facets using the preceding steps.
  • Custom fields can either appear as filter facets or they can be searched. Both cannot happen simultaneously.
  • If you want custom fields to be searchable, follow the instructions in the following section.
    Please note that a field can be mapped only once in the JSON file

Making Custom Fields Searchable

By default, custom fields from WEB, File and Custom collections cannot be searched even if they are added as facets using the steps outlined in the preceding section.

If you need the content from meta fields or custom fields to be searched, add the following mapping to the mapping.json file found within the /ROOT/WEB-INF folder. Restart SearchBlox and then reindex the collection.

"section":{
"type": "text",
"copy_to": "custom_all"
},

otherwise provide "copy_to": "custom_all" to the existing mapping as shown
"customfieldname": {
"type": "text",
"store": true,
"fielddata": true,
"analyzer": "comma_analyzer",
"copy_to": "custom_all"
},

🚧

Applicable for WEB, File and Custom Collection

Adding Custom Date fields as facet filter

if you want to use a published date as a facet field with the following meta tag in your HTML page:

or Note: The format of date should be as shown above You need to add the following mapping to the mapping.json file found within the /searchblox/WEB-INF folder, and then create a new collection to index the web pages:

"published":{
"type": "date",
"store": true
},

Preceding changes are to be made in particular mapping.json on using particular collection,
Please make sure to clear and reindex for the changes to take effect.

Click here for more information: https://searchblox.zendesk.com/hc/en-us/articles/201888250-Can-I-use-my-own-field-for-a-custom-date-and-use-it-for-sorting-
The contents of facet.js file are as follows:

In order to add this date facet, the facets need to be updated in ../webapps/ROOT/search/facet.js
as shown:

{
            "field": "published",
            "display": "Published Date",
            "dateRange": [{
                    "name": "Last 24 hours",
                    "calendar": "days",
                    "value": "1"
                },
                {
                    "name": "Past Week",
                    "calendar": "days",
                    "value": "7"
                },
                {
                    "name": "Past Month",
                    "calendar": "months",
                    "value": "1"
                },
                {
                    "name": "Past Year",
                    "calendar": "years",
                    "value": "1"
                }
            ]
        }

Mapping custom date format

If your date field has a custom date format it has to be mapped in ../ROOT/WEB-INF/mappings/collections/ for a particular mapping.json.
For example, if your meta date is as shown here

Mapping to be provided in mapping.json
"published":
{"type":"date",
"store":"yes",
"format": "yyyy-MM-dd HH:mm:ss"
},