Пример #1
0
        private void UpdateRelevance(List <string> pages, Dictionary <string, string> url2id, Dictionary <string, int> url2idx, double[] values, double min, double max)
        {
            CCIndex      index  = CC.Current.Indexes[indexname];
            EngineClient client = null;

            try
            {
                client = EngineClientsPool.FromPool(index);

                foreach (string page in pages)
                {
                    int    idx   = url2idx[page];
                    string id    = url2id[page];
                    double value = 0.50 * Math.Sqrt((values[idx] - min) / (max - min));  // Value will be between 0 and 50%

                    String sqlquery = String.Format("UPDATE {3} SET {2} = '{0}' WHERE id = '{1}';", value, id.Replace("'", "''"), column_score, indexname);

                    //Sys.Log("processing query for ", sqlquery);

                    client.Exec(sqlquery);
                }
            }
            finally
            {
                EngineClientsPool.ToPool(client);
            }
        }
Пример #2
0
        public void GetPages(List <string> pages, Dictionary <string, string> url2id, Dictionary <string, int> url2idx)
        {
            CCIndex      index  = CC.Current.Indexes[indexname];
            EngineClient client = null;

            try
            {
                client = EngineClientsPool.FromPool(index);

                String sqlquery = Str.And("select id,", column_id, " from ", indexname, " where collection = '", collection, "' and ", column_id, "<> ''");

                Sys.Log("processing query for ", sqlquery);

                Cursor cursor = client.ExecCursor(sqlquery);

                if (cursor != null)
                {
                    Sys.Log("Number of rows: ", cursor.CursorRowCount);

                    int duplicates = 0;

                    for (int i = 0; i < cursor.CursorRowCount; i++)
                    {
                        //Sys.Log("doc " + i);
                        string docid      = cursor.GetColumn("id");
                        string pagerankid = cursor.GetColumn(column_id);

                        if (!url2id.ContainsKey(pagerankid))    // Duplicates id are possible...
                        {
                            pages.Add(pagerankid);
                            url2id[pagerankid]  = docid;
                            url2idx[pagerankid] = i - duplicates;
                        }
                        else
                        {
                            duplicates++;
                        }

                        //Sys.Log("Added doc " + doc.Id);
                        cursor.MoveNext();
                    }
                }
                else
                {
                    Sys.Log("No doc");
                }
            }
            finally
            {
                EngineClientsPool.ToPool(client);
            }
        }
Пример #3
0
        public void GetLinks(Dictionary <string, int> url2idx, ArrayList matrix)
        {
            CCIndex      index  = CC.Current.Indexes[indexname];
            EngineClient client = null;

            try
            {
                client = EngineClientsPool.FromPool(index);

                String sqlquery = Str.And("select ", column_id, ",", column_links, " from ", indexname, " where collection = '", collection, "' and ", column_id, "<> ''");

                Sys.Log("processing query for ", sqlquery);

                Cursor cursor = client.ExecCursor(sqlquery);

                if (cursor != null)
                {
                    Sys.Log("Number of rows: ", cursor.CursorRowCount);

                    for (int i = 0; i < cursor.CursorRowCount; i++)
                    {
                        string pagerankid = cursor.GetColumn(column_id);
                        string links      = cursor.GetColumn(column_links);
                        //Sys.Log("doc ", i, " ", pagerankid, " ", url2idx[pagerankid]);

                        List <int> doc = matrix[url2idx[pagerankid]] as List <int>;
                        if (links != null && Str.NEQ(links, ""))
                        {
                            foreach (string link in links.Split(';'))
                            {
                                if (url2idx.ContainsKey(link))
                                {
                                    doc.Add(url2idx[link]);
                                }
                            }
                        }

                        //Sys.Log("Added doc " + url2idx[pagerankid]);
                        cursor.MoveNext();
                    }
                }
                else
                {
                    Sys.Log("No doc");
                }
            }
            finally
            {
                EngineClientsPool.ToPool(client);
            }
        }
Пример #4
0
        public bool LoadConfig()
        {
            string value   = Str.Empty;
            string dataTag = Str.Empty;

            Sys.Log2(20, "----------------------------------------------------");
            Sys.Log2(20, "Load configuration");
            Sys.Log2(20, "----------------------------------------------------");

            if (_XMLConf == null)
            {
                Sys.LogError("Cannot read configuration");
                return(false);
            }

            //index list
            dataTag = "CMD_INDEX_LIST";
            if (!DatatagExist(dataTag))
            {
                return(false);
            }
            listIndexes = CC.Current.Indexes.CleanAliasList(_XMLConf.Value(dataTag, Str.Empty));
            if (String.IsNullOrEmpty(listIndexes))
            {
                Sys.LogError("Invalid configuration property: index list is empty");
                return(false);
            }

            //list columns
            dataTag = "CMD_SELECT";
            if (!DatatagExist(dataTag))
            {
                return(false);
            }
            value = _XMLConf.Value(dataTag, "*");

            //if only one index and index type is audit => do not resolve column aliases
            CCIndex idx = CC.Current.Indexes.Get(listIndexes);

            isAuditIndex = idx != null && (idx.IndexType == CCIndexType.Audit || idx.IndexType == CCIndexType.AuditReplicated) ? true : false;
            ListStr lcolunmOrColumnAlias = ListStr.ListFromStr(value, ',');

            foreach (string s in lcolunmOrColumnAlias)
            {
                string colunmOrColumnAlias = s.Trim();
                if (!isAuditIndex)
                {
                    dColumnColumnAlias.Add(colunmOrColumnAlias, CC.Current.Global.ResolveColumn(colunmOrColumnAlias));
                }
                else
                {
                    dColumnColumnAlias.Add(colunmOrColumnAlias, colunmOrColumnAlias);
                }
            }

            //where clause
            dataTag = "CMD_WHERE";
            if (!DatatagExist(dataTag))
            {
                return(false);
            }
            whereCluase = _XMLConf.Value(dataTag, "");
            whereCluase = IDocHelper.GetValuePattern(_ctxt, whereCluase);

            //group by
            dataTag = "CMD_GROUPBY";
            if (!DatatagExist(dataTag))
            {
                return(false);
            }
            grouBy = _XMLConf.Value(dataTag, "");

            //order by
            dataTag = "CMD_ORDERBY";
            if (!DatatagExist(dataTag))
            {
                return(false);
            }
            orderBy = _XMLConf.Value(dataTag, "");

            //count
            dataTag = "CMD_COUNT";
            if (!DatatagExist(dataTag))
            {
                return(false);
            }
            count = _XMLConf.ValueInt(dataTag, -1);

            //Engine
            dataTag = "CMD_ENGINE";
            if (!DatatagExist(dataTag))
            {
                return(false);
            }
            engine = CC.Current.Engines.CleanAlias(_XMLConf.Value(dataTag, ""));

            //add headers
            dataTag = "CMD_HEADERS";
            if (!DatatagExist(dataTag))
            {
                return(false);
            }
            addHeaders = _XMLConf.ValueBoo(dataTag, false);

            //Field separator
            dataTag = "CMD_SEPARATOR";
            if (!DatatagExist(dataTag))
            {
                return(false);
            }
            separator = _XMLConf.ValueChar(dataTag, ',');

            //override headers
            dataTag = "CMD_HEADERS_OVERRIDE";
            if (!DatatagExist(dataTag))
            {
                return(false);
            }
            overrideHeaders = _XMLConf.ValueBoo(dataTag, false);

            //custom headers
            dataTag = "CMD_HEADERS_CUSTOM";
            if (!DatatagExist(dataTag))
            {
                return(false);
            }
            string sCustomHeaders = _XMLConf.Value(dataTag, "");

            if (addHeaders && overrideHeaders) //check override header has same number of elements than select statement
            {
                lCustomHeaders = ListStr.ListFromStr2(sCustomHeaders, separator);
                if (lCustomHeaders.Count != dColumnColumnAlias.Count)
                {
                    Sys.LogError("Override headers does not have the same number of elements as select statement");
                    return(false);
                }
            }

            //use replace separator
            dataTag = "CMD_USE_REPLACE";
            if (!DatatagExist(dataTag))
            {
                return(false);
            }
            useReplaceSeparator = _XMLConf.ValueBoo(dataTag, false);

            //Replace separator in values
            dataTag = "CMD_SEPARATOR_REPLACE";
            if (!DatatagExist(dataTag))
            {
                return(false);
            }
            replaceSeparator = _XMLConf.ValueChar(dataTag, '/');

            //Enclose fields in double quote
            dataTag = "CMD_DBL_QUOTES";
            if (!DatatagExist(dataTag))
            {
                return(false);
            }
            useDblQuote = _XMLConf.ValueBoo(dataTag, false);

            //Destination file path
            dataTag = "CMD_FILE_PATH";
            if (!DatatagExist(dataTag))
            {
                return(false);
            }
            destinationFilePath = CC.Current.EnvVars.Resolve(_XMLConf.Value(dataTag, ""));
            destinationFilePath = IDocHelper.GetValuePattern(_ctxt, destinationFilePath);
            if (Str.IsEmpty(destinationFilePath))
            {
                Sys.LogError("Export file path is empty");
                return(false);
            }

            //Remove duplicate lines
            dataTag = "CMD_DEDUPLICATE";
            if (!DatatagExist(dataTag))
            {
                return(false);
            }
            removeDuplicates = _XMLConf.ValueBoo(dataTag, false);

            //Remove empty lines
            dataTag = "CMD_REMOVE_EMPTY_LINES";
            if (!DatatagExist(dataTag))
            {
                return(false);
            }
            removeEmptyLines = _XMLConf.ValueBoo(dataTag, false);

            //Enable simulate mode
            dataTag = "CMD_SIMULATE";
            if (!DatatagExist(dataTag))
            {
                return(false);
            }
            simulate = _XMLConf.ValueBoo(dataTag, false);

            //Simulate count
            dataTag = "CMD_NB_LINE_SIMULATE";
            if (!DatatagExist(dataTag))
            {
                return(false);
            }
            simulateCount = _XMLConf.ValueInt(dataTag, 1000);

            //Mapping Grid - do not check if DatatagExist - grid is optionnal
            dataTag = "CMD_MAPPING";
            ListOf <XDoc> mappingGridElts = _XMLConf.EltList("CMD_MAPPING");

            for (int i = 0; i < mappingGridElts.Count; i++)
            {
                XDoc   mappingElt          = mappingGridElts.Get(i);
                string columnOrAliasColumn = mappingElt.Value("Column");
                if (String.IsNullOrEmpty(columnOrAliasColumn) || String.IsNullOrWhiteSpace(columnOrAliasColumn))
                {
                    Sys.LogError("Column Mapping - Column cannot be empty");
                    return(false);
                }

                string val = mappingElt.Value("Value");
                if (String.IsNullOrEmpty(val) || String.IsNullOrWhiteSpace(val))
                {
                    Sys.LogError("Column Mapping - Value Pattern cannot be empty for column [" + columnOrAliasColumn + "]");
                    return(false);
                }

                string         squery         = mappingElt.Value("SelectionQuery");
                SelectionQuery selectionQuery = SelectionQuery.FromStr(squery, out string errorMessage);
                if (!Str.IsEmpty(errorMessage))
                {
                    Sys.LogError("Column Mapping - Invalid selection query [" + squery + "] for column [" + columnOrAliasColumn + "] - ", errorMessage);
                    return(false);
                }

                if (!dColumnColumnAlias.TryGetValue(columnOrAliasColumn, out string columnName))
                {
                    columnName = null;
                }
                ColumnMapping columnMapping = new ColumnMapping(columnName, columnOrAliasColumn, val, selectionQuery);
                lColumnMapping.AddUnique(columnMapping);
            }

            Sys.Log2(20, "Load configuration OK");
            LogConfig();

            return(true);
        }
Пример #5
0
        /// <summary>
        /// Main entry point of the web service. This method simply retrieves the "action"
        /// input from the request, and calls the corresponding method accordingly (among which
        /// Create(), Read(), Update(), Delete(), Like()).
        /// </summary>
        public override void OnPluginMethod()
        {
            //Sys.Log("Comments Web Service Plugin Start");

            string action = ensureStrInput("action");
            string docid  = ensureStrInput("docid");

            if (docid == null || action == null)
            {
                return;
            }

            if (!Method.Session.HasAccessToDocId(docid))
            {
                SetError(403, "You do not have access to this document");
                return;
            }

            CCIndex      index  = CC.Current.Indexes[indexname];
            EngineClient client = null;

            try
            {
                client = EngineClientsPool.FromPool(index);

                switch (action.ToLower())
                {
                case "create":
                    Create(client, docid);
                    break;

                case "read":
                    Read(client, docid);
                    break;

                case "update":
                    Update(client, docid);
                    break;

                case "delete":
                    Delete(client, docid);
                    break;

                case "like":
                    Like(client, docid);
                    break;

                default:
                    SetError(400, "Invalid 'action' input. Possible actions: 'create','read','update','delete','like'");
                    break;
                }
            }
            catch (Exception ex)
            {
                JsonResponse.SetValue("error", ex.StackTrace);
                SetError(400, ex.Message);
            }
            finally
            {
                EngineClientsPool.ToPool(client);
            }

            //Sys.Log("Comments Web Service Plugin End");
        }