=======================================
IMPORTANT NOTICE
In the Search Extension project, we made some changes to standardise the HTTP PORT for serving static contents, hence all scripts need to be updated on the consumer sites that are using phase-1 search application.
We no more require node-server for serving the static assets. All these static files can be served using Nginx or Apache.
Wherever you find https://www.example.com in the documentation below you need to replace that with the server-url (This is the IP or Domain/URL of the server where you are hosting JS application (link)).
Support for IE10+ is completely optional. To support IE10+ browser, please add polyfills provided below in documentation.
The search application is meant to be served remotely. hence don’t download assets and include then in your application directly.
To integrate search please follow the documentation below.
Terminologies used in the documentation:
How to Setup the Server for serving static assets remotely.
node -v on your terminal/bash. It should return the node version installed. Also, verify if node package manager is installed by typing npm -v. This will return the version of npm installed on your machine.Once confirmed, follow the instructions below:
Step-1: Preparing static assets
cd inova-search-nodejsSERVER_DOMAIN = https://www.example.com // if static contents are not served from port 80, then you need to provide the port too, i.e. http://www.example.com:8080
SOLR_SERVER=http://<domain>:<port>/solr
SOLR_INDEX= <index name>
SOLR_USERNAME=
SOLR_PASSWORD=
IMAGE_PATH = <images> // images will be publicly accessible using this path (Default:IMAGE_PATH=images)
//Development Configuration (Optional Development Only)
CLIENT_IP= 127.0.0.1
CLIENT_PORT= 5000
bash ./script.sh and select [2] as the option and proceed. This will install all the dependencies required.bash ./script.sh in the project root and select [3] as the option and wait for the process to finish.Step-2: Server setup for Static assets to be served remotely
We are providing the example.conf for Apache here. If you willing to use Nginx please follow any of its standard configuration instruction.
All the static assets are available at <project-root>/public therefore, please make sure your apache/Nginx conf file points to the public file. A sample config (apache) can be found below
Server setup for Static assets to be served remotely.
<VirtualHost *:80>
# Make sure to point on public directory as outlined below
DocumentRoot /var/www/html/js_application/public
ServerName 0.0.0.0
ServerAlias 0.0.0.0
ErrorLog ${APACHE_LOG_DIR}/inova_search_error.log
CustomLog ${APACHE_LOG_DIR}/inova_search_access.log combined
<Directory /var/www/html/js_application/public/>
Order allow,deny
Allow from all
AllowOverride All
#the line below will fix CORS issue
Header set Access-Control-Allow-Origin "*"
</Directory>
</VirtualHost>
Important note
The IP or Domain/URL of the server where you are hosting JS application, will be used as the<server-url>in the installation script to serve all the static assets.
Hence the preferred port to make search accessible to everyone is port 80.
How to install Search on any website/CMS
Our Services installation
Place the following snippet on your page/template where you want to want ‘Our services’ to display.
Note:
Make sure that you append the provided script before the closing of<body/>tag in your HTML page.
<script>
( function ( t, s, id ) {
var targetElem = document.querySelector( t );
if ( targetElem !== null ) {
var script = document.createElement( "script" );
var style = document.createElement( "link" );
style.rel = "stylesheet";
style.href = "".concat( s, "/inova/service/ctstyle.min.css" );
var head = document.querySelector( "head" );
head.appendChild( style );
var div = document.createElement( "div" );
div.id = id;
targetElem.appendChild( div );
script.src = "".concat( s, "/inova/service/bundle.min.js" );
targetElem.appendChild( script );
console.log([INOVA-SEARCH]: Installed successfully);
} else {
console.error([INOVA-SEARCH]:"Unable to Find target to load service" );
}
} )( "<dom target>", "<server-url>", "centretek_our_service" );
</script>
To make the script work, you need to replace two variables <dom taget> and <server-url> in the above snippet according to your configurations.
<dom target>: This is HTML tag id or class name of the HTML element where you want to load the services.
eg <div id="our-service"></div> is avialable in HTML, then replace <dom target> with #our-service in the script
Note:
The provided Dom target must be unique and should be available on the page.
<server-url>: The IP or Domain/URL of the server where you are hosting JS application. The <server-url> must not contain any trailing slashes.
Search Extension installation
(Modal Search and Main Search)
Note
1. Make sure that you append the provided script before the closing of<body/>tag in your html page.
2. Both Modal and Main search are served via single script hence can’t appear simultaneously on a single page due to the limitation of single Dom target use of react JS
Please place the following snippet on your page/template where you want to make Search to appear.
<script>
(function (t, s, id) {
var searchPath='search';
window.localStorage.setItem('search-path', searchPath);
var targetElem = document.querySelector(t);
var resource = 'search';
if (targetElem !== null) {
var script = document.createElement("script");
var style = document.createElement("link");
style.rel = "stylesheet";
style.href = "".concat(s, "/inova/search/ctstyle.min.css"));
var head = document.querySelector("head");
head.appendChild(style);
var div = document.createElement("div");
div.id = id;
targetElem.appendChild(div);
script.src = "".concat(s, "/inova/search/bundle.min.js"));
targetElem.appendChild(script);
console.log([INOVA-SEARCH]: Installed successfully);
} else {
console.error([INOVA-SEARCH]:"Unable to Find target to load Search" );
}
})(<dom target>, "<server-url>", "centretek_search_app");
</script>
To make the script work you need to replace the two variables <dom taget> and <server-url> in the snippet above according to your configurations.
<dom target>: This is HTML tag id or class name of the HTML element where you want to load the search.
eg: if <div id="my-search"></div> is avialable in HTML then replace <dom target> with #my-search in the script
Note
The provided Dom target must be unique and available on the page.
<server-url>: The IP or Domain/URL of the server where you are hosting JS application. the <server-url> must not contain any trailing slashes.
NOTE (Optional)
By default, the search will use/searchas the path to serve Main search page. If you wish to open the Main search page on another path, set the value of variablesearchPathto your desired path in the above snippet.
Note
There is a single script for installing header search and main search. You have to add the provided installation script on your website.
There are some dependencies below that needs to be installed before proceeding (important)
| Location | Requiremnt | Script |
|---|---|---|
<head> section of HTML |
Must Included | <link rel="stylesheet" href="https://www.example.com/centretek_search.min.css"> |
<head> Section of HTML |
ignore if already present | <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css"> |
before </body> after Loading JQuery |
Must include (after Jquery) | <script src="https://www.example.com/centretek_search.js"></script> |
inside <body> before centretek_search.js |
Ignore if already present | <script src="https://code.jquery.com/jquery-3.1.1.slim.min.js" ></script> |
Copy the installation script below, and place it in the page/template of the website.
Note:
Make sure that you append the provided script before the closing of<body/>tag in your HTML page.
var fetchConfig = function fetchConfig( domain, serverName ) {
return new Promise( function ( resolve, reject ) {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function () {
if ( this.readyState === 4 && this.status === 200 ) {
resolve( JSON.parse( this.responseText )[ domain ] );
}
};
xhttp.open( "GET", "".concat( serverName, "/configuration.json" ), true );
xhttp.setRequestHeader('Access-Control-Allow-Origin', 'https://inova-search.com');
xhttp.send();
} );
};
var embedScript = function embedScript( appId, target, config, serverName ) {
localStorage.setItem( "config", config );
var targetElement = document.querySelector( target );
var appdiv = document.createElement( "div" );
appdiv.id = appId;
targetElement.appendChild( appdiv );
var script = document.createElement( "script" );
script.src = "".concat( serverName, "/bundle.min.js" );
document.body.appendChild( script );
};
( function ( appId, target, serverName, domain = "inova" ) {
localStorage.setItem( "domain", domain );
var targetElement = document.querySelector( target );
if ( !Boolean( targetElement ) ) {
console.error( "[CENTRETEK_JS] No Valid Target is found" );
return;
};
if ( document.documentMode !== 9 && window.navigator.appVersion.indexOf( "MSIE 9." ) == -1 ) {
fetchConfig( domain, serverName )
.then( function ( response ) {
embedScript( appId, target, JSON.stringify( response || {} ), serverName );
console.log( "[CENTRETEK_JS] Script installed successfully" );
} )
.catch( function ( error ) {
console.error("[CENTRETEK_JS] Unable to find the configuration.json", error );
} );
} else {
console.log("[CENTRETEK_JS]: You are using unsupported browser." );
}
} )( "centretek_react_application", "<dom target>", "<server-url>", "<consumer-site-domain>" );
To make the script work, you need to replace three variables <dom taget>, <server-url> and <consumer-site-domain> in the snippet provided above, according to your configurations.
<dom target>: This is HTML tag id or classname of the HTML element where you want to load the search.
eg: if <div id="my-search"></div> is avialable in HTML, then replace <dom target> with #my-search in the script
Note:
The provided Dom target must be unique and should be available on the page.
<server-url>: The IP or Domain/URL of the server where you are hosting JS application. The <server-url> must not contain any trailing slashes.
<consumer-site-domain> choose any domain name below
My header search works fine but the main search is not working ?
You can troubleshoot the issue by following the steps below.
RewriteRule ^(.*)\/(\?.*)?$ $1$2 [R=301,L]No icons or images are appearing on the search ?
font-awesome as per the dependencies explained above.IMAGE_PATH in .env, the file is set and you can access those images publicly on https://www.example.com/[IMAGE_PATH].</Head>. Polyfills are already added in the repository and will be accessible on https://www.example.com/polyfill.min.js