It is possible to replace the internal search engine that is used by Oxygen XML WebHelp by using a custom JavaScript file. This customization method allows you to replace the search engine but keep the search results presentation.
To replace WebHelp's internal search engine, follow this procedure:
/**
* Object that implements the methods required by WebHelp to run a search engine.
*/
function CustomSearchEngine() {
/**
* Method required to run the search engine in webhelp. Handler when the users
* executes the query in the search page.
*
* @param {String} query The search input string from the user.
* @param {Function} successHandler Needs to be called if the search operation is executed
* successfully. The parameter needs to have the type of
* WebHelpAPI.SearchResult
* @param {Function} errorHandler Needs to be called if the search operation fails to
* execute successfully. It needs to have the type
* of String.
*/
this.performSearchOperation = function(query, successHandler, errorHandler) {
// implement search engine
// const searchRestult = externalSearchEngine(query);
// convert the result to WebHelpApi.SearchResult
// const formattedResult = convert(searchRestult);
// call successHanlder with the converted result.
// successHandler(formattedResult)
}
/**
* Method required to run the search engine in webhelp. Handler when the
* page is changed in the search page.
*
* @param {Integer} pageToShow The page to be dispalyed.
* @param {Integer} maxItemsPerPage The maximum # of items that can be displayed on a page.
* @param {String} query The search input string from the user.
* @param {Function} successHandler Needs to be called if the search operation is executed
* successfully. The parameter needs to have the type of
* WebHelpAPI.SearchResult
* @param {Function} errorHandler Needs to be called if the search operation fails to
* execute successfully. It needs to have the type
* of String.
*/
this.onPageChangedHandler = function(pageToShow, maxItemsPerPage, query, successHandler,
errorHandler) {
// implement search engine
// const searchRestult = externalSearchEngine(pageToShot, maxItemsPerPage, query);
// convert the result to WebHelpApi.SearchResult
// const formattedResult = convert(searchRestult);
// call successHanlder with the converted result.
// successHandler(formattedResult)
}
}
// Set the Search Engine to WebHelp
WebHelpAPI.setCustomSearchEngine(new CustomSearchEngine());WebHelpAPI.SearchResult.<div>
<script src="${oxygen-webhelp-template-dir}/js/search-engine.js"></script>
</div><resources> section (see Template Resources
for more
details):<fileset>
<include name="js/**"/>
</fileset><webhelp>
element:<html-fragments>
<fragment file="fragments/search-engine-script-fragment.xml"
placeholder="webhelp.fragment.head.search.page"/>
</html-fragments>conse searchMeta = new WebHelpAPI.SearchMeta(searchEngineName, totalSearchItems, currentPage,
maxItemsPerPage, totalPages, origianlSearchExpresion);const searchDocument = new WebHelpAPI.SearchDocument(linkLocation, title, shortDescription);conse searchMeta = new WebHelpAPI.SearchMeta(searchEngineName, totalSearchItems, currentPage,
maxItemsPerPage, totalPages, origianlSearchExpresion);
const searchDocument = new WebHelpAPI.SearchDocument(linkLocation, title, shortDescription);
const documents = [searchDocument]; // An array with one element.
const searchResult = new WebHelpAPI.SearchResult(searchMeta, documents);