ATLAS-4108: updated free-text search processor to support Elasticsearch

Signed-off-by: Madhan Neethiraj <madhan@apache.org>
diff --git a/repository/src/main/java/org/apache/atlas/discovery/FreeTextSearchProcessor.java b/repository/src/main/java/org/apache/atlas/discovery/FreeTextSearchProcessor.java
index 56b514d..92152ff 100644
--- a/repository/src/main/java/org/apache/atlas/discovery/FreeTextSearchProcessor.java
+++ b/repository/src/main/java/org/apache/atlas/discovery/FreeTextSearchProcessor.java
@@ -17,6 +17,8 @@
  */
 package org.apache.atlas.discovery;
 
+import org.apache.atlas.ApplicationProperties;
+import org.apache.atlas.AtlasException;
 import org.apache.atlas.model.discovery.SearchParameters;
 import org.apache.atlas.repository.Constants;
 import org.apache.atlas.repository.graph.GraphHelper;
@@ -41,6 +43,8 @@
     public  static final String SOLR_QT_PARAMETER           = "qt"; // org.apache.solr.common.params.CommonParams.QT;
     public  static final String SOLR_REQUEST_HANDLER_NAME   = "/freetext";
 
+    private static final boolean IS_SOLR_INDEX_BACKEND = isSolrIndexBackend();
+
     private final AtlasIndexQuery indexQuery;
 
     public FreeTextSearchProcessor(SearchContext context) {
@@ -70,7 +74,9 @@
     private GraphIndexQueryParameters prepareGraphIndexQueryParameters(SearchContext context, StringBuilder queryString) {
         List<AtlasIndexQueryParameter> parameters = new ArrayList<>();
 
-        parameters.add(context.getGraph().indexQueryParameter(SOLR_QT_PARAMETER, SOLR_REQUEST_HANDLER_NAME));
+        if (IS_SOLR_INDEX_BACKEND) {
+            parameters.add(context.getGraph().indexQueryParameter(SOLR_QT_PARAMETER, SOLR_REQUEST_HANDLER_NAME));
+        }
 
         return new GraphIndexQueryParameters(Constants.VERTEX_INDEX, queryString.toString(), 0, parameters);
     }
@@ -175,4 +181,16 @@
     public long getResultCount() {
         return indexQuery.vertexTotals();
     }
+
+    private static boolean isSolrIndexBackend() {
+        try {
+            String indexBackEnd = ApplicationProperties.get().getString(ApplicationProperties.INDEX_BACKEND_CONF);
+
+            return ApplicationProperties.INDEX_BACKEND_SOLR.equalsIgnoreCase(indexBackEnd);
+        } catch (AtlasException e) {
+            LOG.error("Failed to get application property {}. Assuming Solr index backend", ApplicationProperties.INDEX_BACKEND_SOLR, e);
+        }
+
+        return true; // default to Solr
+    }
 }
diff --git a/repository/src/main/java/org/apache/atlas/util/AtlasRepositoryConfiguration.java b/repository/src/main/java/org/apache/atlas/util/AtlasRepositoryConfiguration.java
index c37d757..179fa43 100644
--- a/repository/src/main/java/org/apache/atlas/util/AtlasRepositoryConfiguration.java
+++ b/repository/src/main/java/org/apache/atlas/util/AtlasRepositoryConfiguration.java
@@ -253,10 +253,6 @@
             try {
                 isFreeTextSearchEnabled = ApplicationProperties.get().getBoolean(ApplicationProperties.ENABLE_FREETEXT_SEARCH_CONF, true);
 
-                if (isFreeTextSearchEnabled) { // currently free-text is supported only for Solr
-                    isFreeTextSearchEnabled = ApplicationProperties.INDEX_BACKEND_SOLR.equalsIgnoreCase(ApplicationProperties.get().getString(ApplicationProperties.INDEX_BACKEND_CONF));
-                }
-
                 if (isFreeTextSearchEnabled) { // if free-text is enabled, disable full-text - to avoid performance penalty
                     isFullTextSearchEnabled = false;
                 } else {