public GenericStorageExtensionServiceResponse <IndexResponse> RemoveDocument(GenericStorageExtensionServiceRequest <IndexRequest> query)
        {
            GenericStorageExtensionLogger.WriteLog(ELogLevel.INFO, "Entering into method IndexService.RemoveDocument");
            GenericStorageExtensionServiceResponse <IndexResponse> serviceResponse = new GenericStorageExtensionServiceResponse <IndexResponse>();
            string result = string.Empty;

            try
            {
                IndexResponse    resultValue;
                SolrIndexManager indexManager = new SolrIndexManager(query.ServicePayload.LanguageInRequest);
                resultValue = indexManager.RemoveDocument(query.ServicePayload);
                serviceResponse.ServicePayload = resultValue;
            }
            catch (Exception ex)
            {
                string logString = GenericStorageExtensionServiceConstants.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));
                GenericStorageExtensionLogger.WriteLog(ELogLevel.ERROR, logString);
                CatchException <IndexResponse>(ex, serviceResponse);
            }
            GenericStorageExtensionLogger.WriteLog(ELogLevel.INFO, "Exiting from method IndexService.RemoveDocument");
            return(serviceResponse);
        }
        public GenericStorageExtensionServiceResponse <IndexResponse> AddDocument(GenericStorageExtensionServiceRequest <IndexRequest> query)
        {
            GenericStorageExtensionLogger.WriteLog(ELogLevel.INFO, "Enter into method IndexService.AddDocumnet()");
            GenericStorageExtensionServiceResponse <IndexResponse> serviceResponse = new GenericStorageExtensionServiceResponse <IndexResponse>();

            try
            {
                string        language = query.ServicePayload.LanguageInRequest;
                IndexResponse resultValue;

                SolrIndexManager indexManager = new SolrIndexManager(language);
                resultValue = indexManager.AddDocument(query.ServicePayload);
                GenericStorageExtensionLogger.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";
                GenericStorageExtensionLogger.WriteLog(ELogLevel.INFO, "AddDocumnet is not called ispublish is false" + ex.Message);
            }
            return(serviceResponse);
        }
示例#3
0
        public Stream GetContentFromMongoDB(GenericStorageExtensionServiceRequest <SearchRequest> request)
        {
            string resultJSON = string.Empty;

            GenericStorageExtensionLogger.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(GenericStorageExtensionServicesConstants.Search_URL);
                    var    client           = new MongoClient(connectionString);
                    var    server           = client.GetServer();
                    var    database         = server.GetDatabase(propConfiguration.GetString(GenericStorageExtensionServicesConstants.dbName));
                    var    collection       = database.GetCollection <MongoDBModelSearch>(propConfiguration.GetString(GenericStorageExtensionServicesConstants.tableName));

                    var andList = new List <IMongoQuery>();
                    foreach (DictionaryEntry entry in request.ServicePayload.Filters)
                    {
                        GenericStorageExtensionLogger.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);
                    GenericStorageExtensionLogger.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 };" +
                        "}";
                    MapReduceArgs n = new MapReduceArgs();
                    n.MapFunction    = map;
                    n.ReduceFunction = reduce;
                    var mr = collection.MapReduce(n);
                    foreach (var document in mr.GetResults())
                    {
                        document.ToJson();
                    }

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

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