public static GenericJsonCollection TransformElasticSearchResponseToGenericJsonCollection(OpenSearchResponse <ISearchResponse <GenericJsonItem> > response)
        {
            ISearchResponse <GenericJsonItem> results = null;

            results = (ISearchResponse <GenericJsonItem>)response.GetResponseObject();

            if (results == null)
            {
                throw new NotImplementedException("GenericCollection only transforms from an ElasticOpenSearchResponse");
            }

            GenericJsonCollection collection = new GenericJsonCollection();

            collection.items = new List <GenericJsonItem>();

            foreach (var doc in results.Documents)
            {
                if (doc is GenericJsonItem)
                {
                    collection.items.Add(doc);
                }
                else
                {
                    throw new InvalidDataException("Result is not a GenericJson document.");
                }
            }
            collection.ShowNamespaces = true;
            collection.Date           = DateTime.UtcNow;
            collection.ElementExtensions.Add(new XElement(XName.Get("totalResults", "http://a9.com/-/spec/opensearch/1.1/"), results.Total).CreateReader());

            return(collection);
        }
Example #2
0
 public static GenericJsonCollection TransformJsonResponseToGenericJsonCollection(OpenSearchResponse <byte[]> response)
 {
     return((GenericJsonCollection)GenericJsonCollection.DeserializeFromStream(new MemoryStream((byte[])response.GetResponseObject())));
 }
        public static GenericJsonCollection TransformElasticSearchResponseToGenericJsonCollection(OpenSearchResponse<ISearchResponse<GenericJsonItem>> response)
        {
            ISearchResponse<GenericJsonItem> results = null;

            results = (ISearchResponse<GenericJsonItem>)response.GetResponseObject();

            if (results == null) {
                throw new NotImplementedException("GenericCollection only transforms from an ElasticOpenSearchResponse");
            }

            GenericJsonCollection collection = new GenericJsonCollection();
            collection.items = new List<GenericJsonItem>();

            foreach (var doc in results.Documents) {
                if (doc is GenericJsonItem) {
                    collection.items.Add(doc);
                } else
                    throw new InvalidDataException("Result is not a GenericJson document.");
            }
            collection.ShowNamespaces = true;
            collection.Date = DateTime.UtcNow;
            collection.ElementExtensions.Add(new XElement(XName.Get("totalResults", "http://a9.com/-/spec/opensearch/1.1/"), results.Total).CreateReader());

            return collection;
        }