예제 #1
0
            public BulkDeleteResults DeleteDocuments(IEnumerable<string> documentIds)
            {
                if (null == documentIds)
                    throw new ArgumentNullException("documentIds");

                var parameters = new ParameterMap();
                parameters.AddAll("docid", documentIds);

                try
                {
                    var results = CallApi<List<Dictionary<string, Object>>>(DELETE_METHOD, indexUrl + DOCS_URL,
                                                                            parameters, PrivatePass);

                    var deleted = new List<bool>(results.Count);
                    var errors = new List<string>(results.Count);
                    bool hasErrors = false;

                    for (int i = 0; i < results.Count; i++)
                    {
                        Dictionary<string, Object> result = results[i];
                        var wasDeleted = (bool)result["deleted"];

                        deleted.Insert(i, wasDeleted);

                        if (!wasDeleted)
                        {
                            hasErrors = true;
                            errors.Insert(i, (string)result["error"]);
                        }
                    }

                    var docidList = documentIds.ToList();

                    return new BulkDeleteResults(deleted, errors, docidList, hasErrors);
                }
                catch (HttpCodeException e)
                {
                    if (e.GetHttpCode() == 404)
                    {
                        throw new IndexDoesNotExistException(e);
                    }
                    throw new UnexpectedCodeException(e);
                }
            }
예제 #2
0
        public ParameterMap ToParameterMap()
        {
            ParameterMap parameters = new ParameterMap();

            parameters.Put("start", start.ToString());
            parameters.Put("len", length.ToString());
            parameters.Put("function", scoringFunction.ToString());

            if (snippetFields != null)
                parameters.Put("snippet", Join(snippetFields, ","));
            if (fetchFields != null)
                parameters.Put("fetch", Join(fetchFields, ","));
            if (categoryFilters != null)
                parameters.Put("category_filters", categoryFilters.ToJsonString());

            if (documentVariableFilters != null)
            {
                foreach (Range range in documentVariableFilters)
                {
                    string key = "filter_docvar" + range.Id;
                    string value = (range.Floor == Double.NegativeInfinity ? "*"
                            : (range.Floor).ToString())
                            + ":"
                            + (range.Ceil == Double.PositiveInfinity ? "*"
                                    : (range.Ceil).ToString());
                    string param = parameters.GetFirst(key);
                    if (param == null)
                    {
                        parameters.Add(key, value);
                    }
                    else
                    {
                        parameters.Add(key, param + "," + value);
                    }
                }
            }

            if (functionFilters != null)
            {
                foreach (Range range in functionFilters)
                {
                    string key = "filter_function" + range.Id;
                    string value = (range.Floor == Double.NegativeInfinity ? "*"
                            : (range.Floor).ToString())
                            + ":"
                            + (range.Ceil == Double.PositiveInfinity ? "*"
                                    : (range.Ceil).ToString());
                    string param = parameters.GetFirst(key);
                    if (param == null)
                    {
                        parameters.Add(key, value);
                    }
                    else
                    {
                        parameters.Add(key, param + "," + value);
                    }
                }
            }

            if (queryVariables != null)
            {
                foreach (var entry in queryVariables)
                {
                    parameters.Add("var" + entry.Key, entry.Value.ToString());
                }
            }

            parameters.Put("q", querystring);

            return parameters;
        }
예제 #3
0
            public void DeleteDocument(string documentId)
            {
                if (null == documentId)
                    throw new ArgumentNullException("documentId");

                var parameters = new ParameterMap();
                parameters.Add("docid", documentId);

                try
                {
                    CallApi<Dictionary<string, Object>>(DELETE_METHOD, indexUrl + DOCS_URL, parameters, PrivatePass);
                }
                catch (HttpCodeException e)
                {
                    if (e.GetHttpCode() == 404)
                    {
                        throw new IndexDoesNotExistException(e);
                    }
                    throw new UnexpectedCodeException(e);
                }
            }