Esempio n. 1
0
        public static SearchResponse.SearchResult Search(IAliyunIndexer indexer, QueryBuilder query, string qp, ISummary summary = null, string formula_name = null, string[] fields = null)
        {
            var baseQuerys    = new AliyunBaseQuerys();
            var queryString   = query.ToString();
            var summaryString = summary == null ? String.Empty : summary.ToString();

            formula_name = (formula_name ?? String.Empty).Trim();
            var fetch_fields = fields == null || fields.Length == 0 ? String.Empty : String.Join(";", fields);
            var otherQuerys  = new Dictionary <string, string>
            {
                { "query", queryString },
                { "index_name", indexer.AliyunAppName },
                { "fetch_fields", fetch_fields },
                { "qp", qp },
                { "disable", String.Empty },
                { "first_formula_name", String.Empty },
                { "formula_name", formula_name ?? String.Empty },
                { "summary", summaryString },
            };
            var sign = baseQuerys.GetSignature(AliyunAccessKey.AccessKeyId, AliyunAccessKey.AccessKeySecret, "get", otherQuerys);

            var response = _Http.Search(baseQuerys.Version, AliyunAccessKey.AccessKeyId, sign, baseQuerys.Signature.Method, baseQuerys.Signature.Version,
                                        baseQuerys.SignatureNonce, baseQuerys.Timestamp, queryString, indexer.AliyunAppName,
                                        fetch_fields, qp, String.Empty, String.Empty, formula_name, summaryString);

            if (!response.IsOk())
            {
                throw new Exception(String.Format("系统错误,response:{0};Query:{1}",
                                                  Newtonsoft.Json.JsonConvert.SerializeObject(response),
                                                  Newtonsoft.Json.JsonConvert.SerializeObject(otherQuerys)));
            }
            return(response.Result);
        }
Esempio n. 2
0
        public static void DeleteIndexDoc(IAliyunIndexer indexer, string idKey, string[] ids)
        {
            var baseQuerys = new AliyunBaseQuerys();
            var action     = "push";
            var itemsJson  = Newtonsoft.Json.JsonConvert.SerializeObject(ids.Select(i => new
            {
                cmd    = "delete",
                fields = new Dictionary <string, string> {
                    { idKey, i }
                }
            }));
            var otherQuerys = new Dictionary <string, string>
            {
                { "action", action },
                { "table_name", indexer.AliyunTableName },
                { "items", itemsJson }
            };
            var signature = baseQuerys.GetSignature(AliyunAccessKey.AccessKeyId, AliyunAccessKey.AccessKeySecret, "post", otherQuerys);

            var response = _Http.IndexDoc(baseQuerys.Version,
                                          AliyunAccessKey.AccessKeyId,
                                          signature,
                                          baseQuerys.Signature.Method,
                                          baseQuerys.Signature.Version,
                                          baseQuerys.SignatureNonce,
                                          baseQuerys.Timestamp,
                                          indexer.AliyunAppName,
                                          action,
                                          indexer.AliyunTableName,
                                          itemsJson);

            if (!response.IsOk())
            {
                throw new Exception(String.Format("系统错误,response:{0};Query:{1}",
                                                  Newtonsoft.Json.JsonConvert.SerializeObject(response),
                                                  Newtonsoft.Json.JsonConvert.SerializeObject(otherQuerys)));
            }
        }