Esempio n. 1
0
        public static OpenSearchDescription GetDefaultOpenSearchDescription(IOpenSearchableElasticType type)
        {
            OpenSearchDescription osd = new OpenSearchDescription();

            osd.ShortName        = "Terradue Catalogue";
            osd.Attribution      = "Terradue";
            osd.Contact          = "*****@*****.**";
            osd.Developer        = "Terradue GeoSpatial Development Team";
            osd.SyndicationRight = "open";
            osd.AdultContent     = "false";
            osd.Language         = "en-us";
            osd.OutputEncoding   = "UTF-8";
            osd.InputEncoding    = "UTF-8";
            osd.Description      = string.Format("This Search Service performs queries in the index {0}. There are several URL templates that return the results in different formats." +
                                                 "This search service is in accordance with the OGC 10-032r3 specification.", type.Index.Name);

            OpenSearchEngine ose = type.GetOpenSearchEngine(new NameValueCollection());

            var searchExtensions = ose.Extensions;
            List <OpenSearchDescriptionUrl> urls = new List <OpenSearchDescriptionUrl>();

            NameValueCollection parameters = type.GetOpenSearchParameters(type.DefaultMimeType);

            UriBuilder          searchUrl   = new UriBuilder(string.Format("{0}/catalogue/{1}/{2}/search", Settings.BaseUrl, type.Index.Name, type.Type.Name));
            NameValueCollection queryString = HttpUtility.ParseQueryString("?format=format");

            parameters.AllKeys.FirstOrDefault(k => {
                queryString.Add(k, parameters[k]);
                return(false);
            });

            foreach (int code in searchExtensions.Keys)
            {
                queryString.Set("format", searchExtensions[code].Identifier);
                string[] queryStrings = Array.ConvertAll(queryString.AllKeys, key => string.Format("{0}={1}", key, queryString[key]));
                searchUrl.Query = string.Join("&", queryStrings);
                urls.Add(new OpenSearchDescriptionUrl(searchExtensions[code].DiscoveryContentType,
                                                      searchUrl.ToString(),
                                                      "results"));
            }
            searchUrl = new UriBuilder(string.Format("{0}/catalogue/{1}/{2}/description", Settings.BaseUrl, type.Index.Name, type.Type.Name));
            urls.Add(new OpenSearchDescriptionUrl("application/opensearchdescription+xml",
                                                  searchUrl.ToString(),
                                                  "self"));
            osd.Url = urls.ToArray();

            return(osd);
        }
Esempio n. 2
0
        public BulkOperationsResponse Ingest(IOpenSearchableElasticType type, IHttpRequest request)
        {
            OpenSearchEngine ose = type.GetOpenSearchEngine(new NameValueCollection());

            IOpenSearchEngineExtension osee = ose.GetExtensionByContentTypeAbility(request.ContentType);

            if (osee == null)
            {
                throw new NotImplementedException(string.Format("No OpenSearch extension found for reading {0}", Request.ContentType));
            }

            MemoryOpenSearchResponse payload = new MemoryOpenSearchResponse(request.GetRawBody(), request.ContentType);

            IOpenSearchResultCollection results = osee.ReadNative(payload);

            return(Ingest(type, results));
        }
        public static IOpenSearchResultCollection QueryResult(IOpenSearchableElasticType type, NameValueCollection parameters, Type resultType = null)
        {
            OpenSearchEngine ose = type.GetOpenSearchEngine(parameters);

            if ( resultType == null )
                resultType = OpenSearchFactory.ResolveTypeFromRequest(HttpContext.Current.Request, ose);

            if ( resultType == typeof(ParametersResult) ){
                return type.DescribeParameters();
            }

            var result = ose.Query(type, parameters, resultType );

            OpenSearchFactory.ReplaceSelfLinks(type, parameters, result, type.EntrySelfLinkTemplate, result.ContentType);
            OpenSearchFactory.ReplaceOpenSearchDescriptionLinks(type, result);

            result.Title = new TextSyndicationContent(string.Format("Result for OpenSearch query over type {0} in index {1}", type.Type.Name, type.Index.Name));

            return result;
        }
        public static IOpenSearchResultCollection QueryResult(IOpenSearchableElasticType type, NameValueCollection parameters, Type resultType = null)
        {
            OpenSearchEngine ose = type.GetOpenSearchEngine(parameters);

            if (resultType == null)
            {
                resultType = OpenSearchFactory.ResolveTypeFromRequest(HttpContext.Current.Request, ose);
            }

            if (resultType == typeof(ParametersResult))
            {
                return(type.DescribeParameters());
            }

            var result = ose.Query(type, parameters, resultType);

            OpenSearchFactory.ReplaceSelfLinks(type, parameters, result, type.EntrySelfLinkTemplate, result.ContentType);
            OpenSearchFactory.ReplaceOpenSearchDescriptionLinks(type, result);

            result.Title = new TextSyndicationContent(string.Format("Result for OpenSearch query over type {0} in index {1}", type.Type.Name, type.Index.Name));

            return(result);
        }
Esempio n. 5
0
        public BulkOperationsResponse Ingest(IOpenSearchableElasticType type, IHttpRequest request)
        {
            OpenSearchEngine ose = type.GetOpenSearchEngine(new NameValueCollection());

            IOpenSearchEngineExtension osee = ose.GetExtensionByContentTypeAbility(request.ContentType);
            if (osee == null)
                throw new NotImplementedException(string.Format("No OpenSearch extension found for reading {0}", Request.ContentType));

            MemoryOpenSearchResponse payload = new MemoryOpenSearchResponse(request.GetRawBody(), request.ContentType);

            IOpenSearchResultCollection results = osee.ReadNative(payload);

            return Ingest(type, results);
        }
        public static OpenSearchDescription GetDefaultOpenSearchDescription(IOpenSearchableElasticType type)
        {
            OpenSearchDescription osd = new OpenSearchDescription();

            osd.ShortName = "Terradue Catalogue";
            osd.Attribution = "Terradue";
            osd.Contact = "*****@*****.**";
            osd.Developer = "Terradue GeoSpatial Development Team";
            osd.SyndicationRight = "open";
            osd.AdultContent = "false";
            osd.Language = "en-us";
            osd.OutputEncoding = "UTF-8";
            osd.InputEncoding = "UTF-8";
            osd.Description = string.Format("This Search Service performs queries in the index {0}. There are several URL templates that return the results in different formats." +
            "This search service is in accordance with the OGC 10-032r3 specification.", type.Index.Name);

            OpenSearchEngine ose = type.GetOpenSearchEngine(new NameValueCollection());

            var searchExtensions = ose.Extensions;
            List<OpenSearchDescriptionUrl> urls = new List<OpenSearchDescriptionUrl>();

            NameValueCollection parameters = type.GetOpenSearchParameters(type.DefaultMimeType);

            UriBuilder searchUrl = new UriBuilder(string.Format("{0}/catalogue/{1}/{2}/search", Settings.BaseUrl, type.Index.Name, type.Type.Name));
            NameValueCollection queryString = HttpUtility.ParseQueryString("?format=format");
            parameters.AllKeys.FirstOrDefault(k => {
                queryString.Add(k, parameters[k]);
                return false;
            });

            foreach (int code in searchExtensions.Keys) {

                queryString.Set("format", searchExtensions[code].Identifier);
                string[] queryStrings = Array.ConvertAll(queryString.AllKeys, key => string.Format("{0}={1}", key, queryString[key]));
                searchUrl.Query = string.Join("&", queryStrings);
                urls.Add(new OpenSearchDescriptionUrl(searchExtensions[code].DiscoveryContentType,
                                                      searchUrl.ToString(),
                                                      "results"));

            }
            searchUrl = new UriBuilder(string.Format("{0}/catalogue/{1}/{2}/description", Settings.BaseUrl, type.Index.Name, type.Type.Name));
            urls.Add(new OpenSearchDescriptionUrl("application/opensearchdescription+xml",
                                                  searchUrl.ToString(),
                                                  "self"));
            osd.Url = urls.ToArray();

            return osd;
        }