Esempio n. 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);
            }
        }
Esempio n. 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);
            }
        }
Esempio n. 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);
            }
        }
Esempio n. 4
0
        //Get engine client
        //please make sure client is return to the pool
        public static EngineClient EngineClientFromPool(string engineName)
        {
            EngineClient client = null;

            try
            {
                client = EngineClientsPool.FromPool(engineName);
            }
            catch (Exception ex)
            {
                Sys.LogError($"Cannot get EngineClient for engine [{engineName}]");
                Sys.LogError(ex);

                //exit execution, return client to pool
                EngineClientToPool(client);
                return(null);
            }
            return(client);
        }
Esempio n. 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");
        }