xClass Search API
Copy
This section describes how to extend xClass search programmatically.
SearchMode has been extended by the following properties:
- supportXClassSearch enables you to use XClass Search with a specific SearchMode implementation. The default value for this property is false.
- xClassSearchCriteriaXPath contains the XPath that helps find xClass search criteria in the search query.
It is necessary to set “supportXClassSearch” flag in the constructor of a custom search mode.
SearchMode:
JavaScript
function MyCustomSearch(searchContainer) { // This flag enables the possibility to use xClass Search with this SearchMode this.supportXClassSearch = true; // MyCustomSearch initialization code // Call base SearchMode constructor SearchMode.prototype.constructor.call(this, searchContainer, aras); } MyCustomSearch.prototype = new SearchMode; // MyCustomSearch implementation
Note
If the xClass Search criteria is not compatible with the custom search mode a validation message appears every time you try to build a query using xClass criteria.
In order to use xClass criteria with a custom search mode without validation errors, it is necessary to extend the testAmlForCompatibility, getAml, and setAml functions of the custom search mode:
SearchMode:
JavaScript
function MyCustomSearch(searchContainer) { // This flag enables the possibility to use xClass Search with this SearchMode this.supportXClassSearch = true; // MyCustomSearch initialization code SearchMode.prototype.constructor.call(this, searchContainer, aras); } MyCustomSearch.prototype = new SearchMode; MyCustomSearch.prototype.setAml = function AMLSearchMode_setAml(searchAML) { let xClassCriteria; // call base setAml function to load searchAML into the current query item SearchMode.prototype.setAml.call(this, searchAML); // if current SearchMode supports xClassSearch if (this.supportXClassSearch) { // try to find xClassSearch criteria xClassCriteria = this.currQryItem.item.selectSingleNode(this.xClassSearchCriteriaXPath); if (xClassCriteria) { // if xClassSearch criteria exists then remove it from the current query item xClassCriteria = this.currQryItem.item.removeChild(xClassCriteria); // replace searchAML by AML without xClassSearch criteria searchAML = this.currQryItem.item.xml; } } // some business logic of custom SearchMode to populate it based on provided searchAML // if xClassSearch criteria was found previously if (xClassCriteria) { // append stored xClassSearch criteria to the current query item this.currQryItem.item.appendChild(this.currQryItem.dom.importNode(xClassCriteria, true)); } } MyCustomSearch.prototype.getAml = function AMLSearchMode_getAml() { let xClassCriteria; // if current SearchMode supports xClassSearch if (this.supportXClassSearch) { // try to find xClassSearch criteria xClassCriteria = this.currQryItem.item.selectSingleNode(this.xClassSearchCriteriaXPath); if (xClassCriteria) { // if xClassSearch criteria exists then remove it from the current query item xClassCriteria = this.currQryItem.item.removeChild(xClassCriteria); } } // some business logic to populate current query item by search criteria for custom SearchMode // if xClassSearch criteria was found previously if (xClassCriteria) { // append stored xClassSearch criteria to the current query item this.currQryItem.item.appendChild(xClassCriteria); } } MyCustomSearch.prototype.testAmlForCompatibility = function (searchAml) { let searchQuery = searchAml; if (this.supportXClassSearch) { // if current SearchMode supports xClassSearch const queryDom = this.aras.createXMLDocument(); queryDom.loadXML(searchAml); // try to find xClassSearch criteria const xClassCriteria = queryDom.documentElement.selectSingleNode(this.xClassSearchCriteriaXPath); if (xClassCriteria) { // if xClassSearch criteria exists then remove it from AML which should be validated queryDom.documentElement.removeChild(xClassCriteria); searchQuery = queryDom.documentElement.xml; } } return SearchMode.prototype.testAmlForCompatibility.call(this, searchQuery); }