public MI4TServiceResponse <IndexResponse> RemoveDocument(MI4TServiceRequest <IndexRequest> query) { MI4TLogger.WriteLog(ELogLevel.INFO, "Entering into method IndexService.RemoveDocument"); MI4TServiceResponse <IndexResponse> serviceResponse = new MI4TServiceResponse <IndexResponse>(); try { //serviceResponse.ServicePayload = new IndexResponse(); //serviceResponse.ServicePayload.Result = 1; MI4TLogger.WriteLog(ELogLevel.INFO, "RemoveDocument is called publish is true1 "); IndexResponse resultValue; MI4TIndexManager indexManager = new MI4TIndexManager(query.ServicePayload.LanguageInRequest); resultValue = indexManager.RemoveDocument(query.ServicePayload); serviceResponse.ServicePayload = resultValue; MI4TLogger.WriteLog(ELogLevel.INFO, "RemoveDocument is called publish is true 2"); } catch (Exception ex) { serviceResponse.ServicePayload = new IndexResponse(); serviceResponse.ServicePayload.Result = 0; serviceResponse.ServicePayload.ErrorMessage = "RemoveDocument is not called ispublish is false"; MI4TLogger.WriteLog(ELogLevel.INFO, "RemoveDocument is not called ispublish is false"); string logString = MI4TServiceConstants.LOG_MESSAGE + Environment.NewLine; string request = query != null?query.ToJSONText() : "Request = NULL"; logString = string.Concat(logString, string.Format("Service Request: {0}", request), Environment.NewLine, string.Format("{0}{1}", ex.Message, ex.StackTrace)); MI4TLogger.WriteLog(ELogLevel.ERROR, logString); CatchException <IndexResponse>(ex, serviceResponse); } MI4TLogger.WriteLog(ELogLevel.INFO, "Exiting from method IndexService.RemoveDocument"); return(serviceResponse); }
public MI4TServiceResponse <IndexResponse> AddDocument(MI4TServiceRequest <IndexRequest> query) { MI4TLogger.WriteLog(ELogLevel.INFO, "Enter into method IndexService.AddDocumnet()"); MI4TServiceResponse <IndexResponse> serviceResponse = new MI4TServiceResponse <IndexResponse>(); try { string language = query.ServicePayload.LanguageInRequest; IndexResponse resultValue; MI4TIndexManager indexManager = new MI4TIndexManager(language); resultValue = indexManager.AddDocument(query.ServicePayload); MI4TLogger.WriteLog(ELogLevel.INFO, "AddDocumnet is called publish is true"); serviceResponse.ServicePayload = resultValue; } catch (Exception ex) { serviceResponse.ServicePayload = new IndexResponse(); serviceResponse.ServicePayload.Result = 1; serviceResponse.ServicePayload.ErrorMessage = "AddDocumnet is not called ispublish is false"; MI4TLogger.WriteLog(ELogLevel.INFO, "AddDocumnet is not called ispublish is false" + ex.Message); } return(serviceResponse); }
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))); }