public ESI4TIndexManager(string Langauge)
 {
     ESI4TLogger.WriteLog(ELogLevel.INFO, "Entering ESI4TIndexManager:" +
                          Langauge);
     try
     {
         string elasticSearchURL = propConfiguration.GetString(ESI4TServicesConstants.elasticSearch_URL);
         ESI4TLogger.WriteLog(ELogLevel.INFO, "elasticSearch URL: " + elasticSearchURL);
     }
     catch (Exception ex)
     {
         ESI4TLogger.WriteLog(ELogLevel.ERROR, ex.Message + ex.StackTrace);
         throw;
     }
 }
        /// <summary>
        /// Instantiate SolrIndexManager for a core
        /// </summary>
        /// <param name="language"></param>
        public SolrIndexManager(string solr_core)
        {
            GenericStorageExtensionLogger.WriteLog(ELogLevel.INFO, "Entering SolrIndexManager(core) with core:" +
                                                   solr_core);
            try
            {
                Startup.Container.Clear();
                Startup.InitContainer();

                string solrURL = propConfiguration.GetString(GenericStorageExtensionServicesConstants.SOLR_URL);
                solrURL = string.Concat(solrURL, GenericStorageExtensionServicesConstants.DELIMITER_SLASH, solr_core);

                GenericStorageExtensionLogger.WriteLog(ELogLevel.INFO, "SOLR URL: " + solrURL);

                Boolean instanceExistsAlready = InstanceExists();
                lock (containerLock)
                {
                    if (!string.IsNullOrEmpty(solrURL))
                    {
                        if (!instanceExistsAlready)
                        {
                            try
                            {
                                Startup.Init <Dictionary <string, object> >(solrURL);
                            }
                            catch (Exception ex)
                            {
                                // Work Around: Need to use mutex here to resolve it properly
                                Startup.Container.Clear();
                                Startup.InitContainer();
                                Startup.Init <Dictionary <string, object> >(solrURL);
                                throw ex;
                            }
                        }
                    }
                }

                GenericStorageExtensionLogger.WriteLog(ELogLevel.INFO, "Instance exists: " +
                                                       instanceExistsAlready.ToString());
            }
            catch (Exception ex)
            {
                GenericStorageExtensionLogger.WriteLog(ELogLevel.ERROR, ex.Message + ex.StackTrace);
                throw ex;
            }
            GenericStorageExtensionLogger.WriteLog(ELogLevel.INFO, "Entering SolrIndexManager.SolrIndexManager(core)");
        }
Esempio n. 3
0
 public MI4TIndexManager(string Langauge)
 {
     GenericStorageExtensionLogger.WriteLog(ELogLevel.INFO, "Entering MI4TIndexManager:" +
                                            Langauge);
     try
     {
         string MongoDBURL = propConfiguration.GetString(GenericStorageExtensionServicesConstants.Search_URL);
         GenericStorageExtensionLogger.WriteLog(ELogLevel.INFO, "Mongo URL: " + MongoDBURL);
     }
     catch (Exception ex)
     {
         GenericStorageExtensionLogger.WriteLog(ELogLevel.ERROR, ex.Message + ex.StackTrace);
         throw;
     }
 }
Esempio n. 4
0
 public MI4TIndexManager(string Langauge)
 {
     MI4TLogger.WriteLog(ELogLevel.INFO, "Entering MI4TIndexManager:" +
                         Langauge);
     try
     {
         string MongoDBURL = propConfiguration.GetString(MI4TServicesConstants.mongoDB_URL);
         MI4TLogger.WriteLog(ELogLevel.INFO, "Mongo URL: " + MongoDBURL);
     }
     catch (Exception ex)
     {
         MI4TLogger.WriteLog(ELogLevel.ERROR, ex.Message + ex.StackTrace);
         throw;
     }
 }
Esempio n. 5
0
        public Stream GetContentFromMongoDB(MI4TServiceRequest <SearchRequest> request)
        {
            string resultJSON = string.Empty;

            MI4TLogger.WriteLog(ELogLevel.INFO, "Entering into GetContentFromMongoDB");
            try
            {
                if (request != null && request.ServicePayload != null)
                {
                    string MongoDBIndexConfigPath = Utility.GetConfigurationValue("IndexServiceConfig");
                    propConfiguration = ConfigurationManager.GetInstance().GetConfiguration(MongoDBIndexConfigPath)
                                        as IPropertyConfiguration;
                    containerLock = new object();
                    string result           = string.Empty;
                    var    connectionString = propConfiguration.GetString(MI4TServicesConstants.mongoDB_URL);
                    var    client           = new MongoClient(connectionString);
                    var    server           = client.GetServer();
                    var    database         = server.GetDatabase(propConfiguration.GetString(MI4TServicesConstants.dbName));
                    var    collection       = database.GetCollection <MongoDBModelSearch>(propConfiguration.GetString(MI4TServicesConstants.tableName));

                    var andList = new List <IMongoQuery>();
                    foreach (DictionaryEntry entry in request.ServicePayload.Filters)
                    {
                        MI4TLogger.WriteLog(ELogLevel.INFO, "Reading request.ServicePayload.Filters");
                        switch (request.ServicePayload.QueryType.ToUpper())
                        {
                        case "AND":
                            andList.Add(Query.EQ(entry.Key.ToString(), entry.Value.ToString()));
                            break;

                        case "OR":
                            andList.Add(Query.Or(Query.EQ(entry.Key.ToString(), entry.Value.ToString())));
                            break;

                        default:
                            andList.Add(Query.Not(Query.EQ(entry.Key.ToString(), entry.Value.ToString())));
                            break;
                        }
                    }
                    var query = Query.And(andList);
                    MI4TLogger.WriteLog(ELogLevel.INFO, "Query generated");
                    //Map/Reduce
                    var map =
                        "function() {" +
                        "    for (var key in this) {" +
                        "        emit(key, { count : 1 });" +
                        "    }" +
                        "}";

                    var reduce =
                        "function(key, emits) {" +
                        "    total = 0;" +
                        "    for (var i in emits) {" +
                        "        total += emits[i].count;" +
                        "    }" +
                        "    return { count : total };" +
                        "}";

                    var mr = collection.MapReduce(map, reduce);
                    foreach (var document in mr.GetResults())
                    {
                        document.ToJson();
                    }

                    MI4TLogger.WriteLog(ELogLevel.INFO, "Calling collection.FindOne(query)");
                    //  var entity = collection.Find(query).ToListAsync();
                    var result1 = collection.FindAs <MongoDBModelSearch>(query);
                    resultJSON = result1.ToJson();

                    MI4TLogger.WriteLog(ELogLevel.INFO, "OUTPUT: " + resultJSON);
                }
            }
            catch (Exception ex)
            {
                MI4TLogger.WriteLog(ELogLevel.ERROR, "ERROR: " + ex.Message + ex.StackTrace);
            }
            return(new MemoryStream(Encoding.UTF8.GetBytes(resultJSON)));
        }