Search Index API
We recommend that you access this OrchestraCMS Services based API through the REST endpoint. Returned payloads are encoded in JSON string format. Authentication is based on a Salesforce session or potentially AWS/Google for media.
The name, title, description, keywords, type, and URL attributes are mapped by default. Any additional attributes to be indexed must be added via custom mapping. The custom mapping process is described in the Custom Attribute Mapping section.
Initialization is required for APEX only:
OrchestraCMS Runtime
cms.ApexServiceInterface sapi = (cms.ApexServiceInterface) cms.ServiceEndpoint.getService('SearchAPI');
External Runtime
Map <String, String> context_params = new Map <String, String>();
context_params.put('sname', 'site_name'); // Replace site_name with the name of your OrchestraCMS site
cms.ApexServiceInterface sapi = (cms.ApexServiceInterface) cms.ServiceEndpoint.getService('SearchAPI', context_params);
getItemList (Predefined Targets Only)
Returns a list of size (ocmsCount) records from the cms__Search_Index__c starting from the specified (ocmsStart). If no values are provided for ocmsCount and ocmsStart they will be assigned default values of (0) and (50) respectively.
Parameters
- service : String, Value must be set to SearchAPI.
- action : String, Value must be set to getItemList.
- sname : String, The site name.
- ocmsStart : Integer (optional), The item to start from, defaults to 0.
- ocmsCount : Integer (optional), Number of rows to return, defaults to 50.
- filterFuturePublished : Boolean (optional), When set to true, future published records will not be returned, defaults to false.
Return Value (JSON Object)
- cursor : Integer, Location in the list (used to track a high water mark).
- type : Enum, Values: Content, Page, Media File Extension {.png, .jpg, .pdf, etc..}.
- key : String, The ID of the content, page, or the url for media.
- originKey : String, The version origin ID of the content or page.
- state : String, Values: new, expired.
- language : String, Language code.
Apex Example
Map <String, Object> arguments = new Map <String, Object>();
arguments.put('sname', 'site_name'); // Replace site_name with the name of your OrchestraCMS site
arguments.put('ocmsStart', 23);
arguments.put('ocmsCount', 2);
List <Map <String, String>> results = (List <Map <String, String>>) sapi.executeApex('getItemList', arguments);
JavaScript Example
var data = {
service: 'SearchAPI',
action: 'getItemList',
ocmsStart: 23,
ocmsCount: 2
};
// Handle response of a successful ajax call
var callBackHandler = function(json, Success) {}
var options = {
cb: callBackHandler,
cbHandlerOnComplete: function(textStatus){}, // Handle response on complete
readonly: false // Whether it is a read only call
};
doServiceRequest(data, options);
API Endpoint Example
http://www.example.com/services/apexrest/cms/ocmsrest/?action=getItemList&service=SearchAPI&sname=[site_name]&ocmsStart=23&ocmsCount=2
Replace [site_name] with your OrchestraCMS Site Name.
JSON-Serialized Response Example
{"success":
{"message":
[{"key": "a00000000000000001",
"originKey": "a00000000000000000",
"type": "Page",
"language": "en_GB",
"state": "new",
"cursor": "23"
},
{"key": "a00000000000000004",
"originKey": "a00000000000000003",
"type": "Content",
"language": "fr_CA",
"state": "new",
"cursor": "24"
}
]
}
}
getItem
Returns a JSON object of the cms__Search_Index__c records requested.
Parameters
- service : String, Value must be set to SearchAPI.
- action : String, Value must be set to getItem.
- sname : String, The site name.
- ocmsKey : String (optional), Id for Content, Page, or Media Content.
- ocmsLang : String (optional), Comma separated list of language codes. If no Language is provided, the return value is going to be a list of records for every available language.
- includePagesForContent : String (optional, default: false), Search Index Records with a type of `Content` will return an additional parameter called `pages`, which will be a list of Page Bundles that the content is on. If the content is not on a page, the Search Results page that is configured will be returned.
Return Value (JSON Object)
- fields : Map<String, Map<String, Object>>,
Map of languageCode to Map of fields. In the case of LibraryContent, the languageCode will be 'NA'.
Standard and user-defined custom fields created on the Search Index object with an optional custom identifier/name.
Standard fields include: name, title, description, keywords, type (content type or file type for media) and URL (The link to which the result will be sent to).
If you do not include a language (ocmsLang), this property will have a list of mappings (one for each language the item has available to it). Otherwise, only one map for the specified language will return.
- key : String, The ID of the content, page, or the Library_Content__c id for media.
- originKey : String, The version origin ID of the content or page.
- startDate : DateTime (Serialized), Start Date.
- endDate : DateTime (Serialized), Expiry Date.
- classifications : List<String>, Full tag path list.
Tag path is of the form /root/level1/level2/level3. When indexing the full path from the root should be associated with the item. Classifications may be used as a 'filter' on a search or for faceting search results.
- accessControl : String, Comma separated values (CSV) list of UserOrGroupIds, except in the case of Library Content, it is either 'hasUploadAccess' or 'noUploadAccess'.
If sharing is disabled, the value will be 'All' for all page and content records.
If sharing is enabled but content or page is not shared, the value will be 'None'.
- predefinedTargets : List<String>, List of Target Keys or null.
- adhocTargets : Map<String, List<String>>, Content Field Name to list of Target Keys or null.
Apex Example
Map <String, Object> arguments = new Map <String, Object>();
arguments.put('sname', 'site_name'); // Replace site_name with the name of your OrchestraCMS site
arguments.put('ocmsLang', 'en_GB, fr');
arguments.put('ocmsKey', 'a00000000000000000');
Map <String, Map <String, Object>> results = (Map <String, Map <String, Object>>) sapi.executeApex('getItem', arguments);
JavaScript Example
var data = {
service: 'SearchAPI',
action: 'getItem',
ocmsLang: 'en_GB',
ocmsKey: 'a00000000000000000'
};
// Handle response of a successful ajax call
var callBackHandler = function(json, Success) {}
var options = {
cb: callBackHandler,
cbHandlerOnComplete: function(textStatus){}, // Handle response on complete
readonly: false // Whether it is a read only call
};
doServiceRequest(data, options);
API Endpoint Example
http://www.example.com/services/apexrest/cms/ocmsrest/?action=getItems&service=SearchAPI&sname=[site_name]&ocmsLang=en_GB&ocmsKey=a00000000000000000
Replace [site_name] with your OrchestraCMS Site Name.
JSON-Serialized Response Example
{"success":
{"message":
{"fields":
{"Title" :"Test Page",
"Type" :"Text",
"Description":"Test page, not for production use.",
"Name" :"Test_Page",
"Keywords" : null
},
"key" :"a00000000000000001",
"originKey": "a00000000000000000",
"url" :"/Page1",
"endDate" :null,
"adhocTargets" :{},
"accessControl" :null,
"startDate" :"2015-06-03T19:06:54.000Z",
"classifications" :null,
"predefinedTargets":["qlyDvFKR3ode4QrfSyiuKMgCDuw"]
}
}
}
getItems
Returns a JSON object of the cms__Search_Index__c records requested.
Parameters
- service : String, Value must be set to SearchAPI.
- action : String, Value must be set to getItems.
- sname : String, The site name.
- ocmsKeys : String, Comma separated list of IDs for Content, Page, or Media Content.
- ocmsLang : String (optional), Comma separated list of language codes. If no Language is provided, the return value is going to be a list of records for every available language.
- includePagesForContent : String (optional, default: false), Search Index Records with a type of `Content` will return an additional parameter called `pages`, which will be a list of Page Bundles that the content is on. If the content is not on a page, the Search Results page that is configured will be returned.
Return Value (JSON Object - JSON Serialized Apex Map where the key is the ID of Content, Page or Media Content requested)
- fields : Map<String, Map<String, Object>>,
Map of languageCode to Map of fields, in the case of LibraryContent the languageCode will be 'NA'.
Standard and user-defined custom fields created on the Search Index object with an optional custom identifier/name.
Standard fields include: name, title, description, keywords, type (content type or file type for media) and URL (The link to which the result will be sent).
If you do not include a language (ocmsLang), this property will have a list of mappings (one for each language the item has available to it). Otherwise, only one map for the specified language will return.
- key : String, The id of the content, page, or the Library_Content__c id for media.
- originKey : String, The version origin Id of the content or page.
- startDate : DateTime (Serialized), Start Date.
- endDate : DateTime (Serialized), Expiry Date.
- classifications : List<String>, Full tag path list.
Tag path is of the form /root/level1/level2/level3. When indexing the full path from the root should be associated with the item. Classifications may be used as a 'filter' on a search or for faceting search results.
- accessControl : String, Comma separated values (CSV) list of UserOrGroupIds, except in the case of Library Content, it is either 'hasUploadAccess' or 'noUploadAccess'.
If sharing is disabled, the value will be 'All' for all page and content records.
If sharing is enabled but content or page is not shared, the value will be 'None'.
- predefinedTargets : List<String>, List of Target Keys or null.
- adhocTargets : Map<String, List<String>>, Content Field Name to list of Target Keys or null.
Apex Example
Map <String, Object> arguments = new Map <String, Object>();
arguments.put('ocmsLang', 'en_GB, fr');
arguments.put('ocmsKeys', 'a00000000000000000, a00000000000000001, a00000000000000002');
arguments.put('sname', 'site_name'); // Replace site_name with the name of your OrchestraCMS site
Map <String, Map <String, Object>> results = (Map <String, Map <String, Object>>) sapi.executeApex('getItems', arguments);
JavaScript Example
var data = {
service: 'SearchAPI',
action: 'getItems',
ocmsLang: 'en_GB',
ocmsKeys: 'a00000000000000000, a00000000000000001, a00000000000000002'
};
// Handle response of a successful ajax call
var callBackHandler = function(json, Success) {}
var options = {
cb: callBackHandler,
cbHandlerOnComplete: function(textStatus){}, // Handle response on complete
readonly: false // Whether it is a read only call
};
doServiceRequest(data, options);
API Endpoint Example
http://www.example.com/services/apexrest/cms/ocmsrest/?action=getItems&service=SearchAPI&sname=[site_name]&ocmsLang=en_GB&ocmsKeys=["a00000000000000000","a00000000000000001","a00000000000000002"]
Replace [site_name] with your OrchestraCMS Site Name.
JSON-Serialized Response Example
{"success":
{"message":
{"fields":
{"Title" :"Test Page",
"Type" :"Text",
"Description":"Test page, not for production use.",
"Name" :"Test_Page",
"Keywords" : null
},
"key" :"a00000000000000001",
"originKey": "a00000000000000000",
"url" :"/Page1",
"endDate" :null,
"adhocTargets" :{},
"accessControl" :null,
"startDate" :"2015-06-03T19:06:54.000Z",
"classifications" :null,
"predefinedTargets":["qlyDvFKR3ode4QrfSyiuKMgCDuw"]
}
}
}
Custom Attribute Mapping
The primary function of the OrchestraCMS Search Index API is to provide the ability to create connectors between the OrchestraCMS page/content/media index and third party search tools. This enables custom search applications to be used to search for and retrieve OrchestraCMS pages, content and media files.
The OrchestraCMS search index is comprised of records stored in the cms__Search_Index__c object in Salesforce. By default only the Name, Title, Description, Keywords, Type and URL properties of the page, content or media are stored in the index.
To map content attributes, the following steps must be followed:
-
Create a custom field on the cms__Search_Index__c object.
This should be planned out carefully. The attribute mapping in OrchestraCMS will be consumed by your third party index. How many custom fields you create and map here should be considered in relation to how you intend to store the data in your third party index. The idea is to prevent the need to perform too much parsing on the JSON returned by OrchestraCMS to map the data into the fields in your search engine's index. For example your search engine might index email addresses in one field and text in another. So you would want to create two custom fields in the OrchestraCMS Search Index object in Salesforce, one for email and one for text and then map all email attributes to one field and all text attributes to another. Alternatively, if your search engine stores all this data in a single field, you could create a single custom field in the Search Index object to map all your custom attributes.
-
Navigate to the OrchestraCMS Setup menu and select a core content template.
-
Select your custom field.
-
Select the Attribute to map to the custom field.
-
Supply a label if desired.
-
Click Map.
Currently, to map attributes in custom content templates you need to use SOQL to populate the Attribute List field on the Content Layout record for custom content template with a semicolon delimited list of the attribute names that custom content template uses.
Now that the attribute has been mapped, you need to activate the mapping to make it available for indexing. Any previously indexed field will not include this new mapping until the tables are reindexed.
- Within OrchestraCMS, access Setup | Search Index.
-
Select the mapping in the Inactive column and add it to the Active column.
-
Select an OrchestraCMS page to be used as the link when content is returned in the results.
- Be translated in all available site Languages
- Contain the Content View Utility Content
- Be published
Custom field mapping can be included or excluded from the JSON response in the API call by navigating to Setup | Search Index. A default URL for the search target page can also be set here. This is used mainly by the dynamically loaded content.
Excluding Content Types from Indexing
Content types that you do not want to see in the search index can be excluded. For example, If the Menu content type is included in the index, searching for a term that appears as a word in a menu on the site would return all pages the menu was on as results.
OrchestraCMS supports excluding items from the search index based on their content type. In OrchestraCMS Setup | Content Types, you can open a content type and select the Exclude from Search Index checkbox in order not to have content of that type added to the index on publishing.
Since OrchestraCMS allows adding content templates to multiple content types, it is possible to create one content type that indexes the content and one that does not. For example, if you wanted to create text content that would act as a legal disclaimer such as a copyright statement at the bottom of every page, you would not want that text content to be indexed even though you want all other text content to be searchable. In this instance you could create a new content type called Non Searchable Text and set it to Exclude from Search Index. You would then add the existing text content templates to the new text content type.
Running The Indexers
Content and pages are added to the index when they are published. If you need to create the index after an outside import, upgrade, attribute addition or any other event that did not involve publishing the content within OrchestraCMS, you must manually run the OrchestraCMS indexers.
The Indexers should be run in anonymous apex. They are site-specific, so they must be executed for each site in the organization. Each indexer must be executed sequentially for each site, and only after the previous indexer has completed.
Page
cms.ocmsIndexExecutor ie = new cms.ocmsIndexExecutor('pageSearch' , 'site_name'); // Replace site_name with the name of your OrchestraCMS site
Database.executeBatch(ie, 200);
Content
cms.ocmsIndexExecutor ie = new cms.ocmsIndexExecutor('contentSearch' , 'site_name'); // Replace site_name with the name of your OrchestraCMS site
Database.executeBatch(ie, 200);
Library
cms.ocmsIndexExecutor ie = new cms.ocmsIndexExecutor('librarySearch' , 'site_name'); // Replace site_name with the name of your OrchestraCMS site
Database.executeBatch(ie, 200);