Esempio n. 1
0
 public void SetUp()
 {
     _cloudSearchSettings = new CloudSearchSettings()
     {
         ApiVersion = string.Empty, CloudSearchId = string.Empty
     };
     _cloudSearch = new CloudSearch <Movie>(_cloudSearchSettings);
 }
Esempio n. 2
0
 public void SetUp()
 {
     _cloudSearchSettings = new CloudSearchSettings()
     {
         ApiVersion = string.Empty, CloudSearchId = string.Empty
     };
     _cloudSearch = new CloudSearch <Movie>(_cloudSearchSettings);
     _cloudSearch.AddPresistantCondition(new StringBooleanCondition("fooTenant", "fooParameterName"));
 }
Esempio n. 3
0
        public void SearchTest()
        {
            // TODO: add unit test for the method 'Search'
            string      appId     = null; // TODO: replace null with proper value
            string      tableName = null; // TODO: replace null with proper value
            CloudSearch body      = null; // TODO: replace null with proper value

            var response = instance.Search(appId, tableName, body);

            Assert.IsInstanceOf <List <CloudObject> > (response, "response is List<CloudObject>");
        }
Esempio n. 4
0
        public void RemoveDocuments(string indexName, IEnumerable <IDocument> documents)
        {
            var amazonSearchParameters          = this.GetAmazonParams();
            CloudSearch <AmazonDoc> cloudSearch = new CloudSearch <AmazonDoc>(amazonSearchParameters[DocumentEndPoint], amazonSearchParameters[ApiVersion]);
            var result = cloudSearch.Delete(documents.Select(d => new AmazonDoc(d)).ToList());

            if (result.IsError)
            {
                Log.Write(string.Format("Failed to remove documents from search index '{0}'. Errors: {1}", indexName, this.GenerateErrorMessage(result)), ConfigurationPolicy.ErrorLog);
            }
        }
Esempio n. 5
0
        public void UpdateIndex(string name, IEnumerable <IDocument> documents)
        {
            var amazonParams = this.GetAmazonParams();
            CloudSearch <AmazonDoc> cloudSearch = new CloudSearch <AmazonDoc>(amazonParams[DocumentEndPoint], amazonParams[ApiVersion]);

            // You can use the result to handle errors
            var result = cloudSearch.Update(documents.Select(d => new AmazonDoc(d)).ToList());

            if (result.IsError)
            {
                Log.Write(string.Format("Failed to update search index '{0}'. Errors: {1}", name, this.GenerateErrorMessage(result)), ConfigurationPolicy.ErrorLog);
            }
        }
Esempio n. 6
0
        public void TestSearch()
        {
            var cloudSearch = new CloudSearch <Movie>("YOU_AMAZON_CLOUD_SEARCH_KEY", "2011-02-01");

            //build facet
            var genreFacetContraint = new StringFacetConstraints();

            genreFacetContraint.AddContraint("Sci-Fi");
            genreFacetContraint.AddContraint("Adventure");
            var genreFacet = new Facet {
                Name = "genre", TopResult = 2
            };

            var yearFacetContraint = new IntFacetContraints();

            yearFacetContraint.AddFrom(1950);
            yearFacetContraint.AddInterval(1980, 2012);
            var yearFacet = new Facet {
                Name = "year", FacetContraint = yearFacetContraint
            };

            var liFacet = new List <Facet> {
                genreFacet, yearFacet
            };


            //build boolean query
            var bQuery     = new BooleanQuery();
            var gCondition = new StringBooleanCondition("genre", "Sci-Fi");
            var yCondition = new IntBooleanCondition("year");

            yCondition.SetInterval(1970, 2013);
            bQuery.Conditions.Add(gCondition);
            bQuery.Conditions.Add(yCondition);

            //build search
            var searchQuery = new SearchQuery <Movie> {
                Keyword = "star wars", Facets = liFacet, Size = 20, Start = 0, BooleanQuery = bQuery
            };

            //search
            var found = cloudSearch.Search(searchQuery);

            Assert.IsTrue(!found.IsError);

            Assert.IsTrue(found.hits.found > 0);

            Assert.IsTrue(found.facetsResults.Count > 0);

            Assert.AreEqual(found.facetsResults.Count, 2, "We request only the top 2 facet");
        }
        public void TestCRUD()
        {
            var cloudSearch = new CloudSearch<Movie>("YOU_AMAZON_CLOUD_SEARCH_KEY", "2011-02-01");

            var movie = new Movie { id = "fjuhewdijsdjoi", title = "simple title", year = 2012, mydate = DateTime.Now, actor = new List<string> { "good actor1", "good actor2" }, director = "martin magakian" };

            cloudSearch.Add(movie);

            Thread.Sleep(1000);

            movie.title = "In the skin of Amazon cloud search";
            cloudSearch.Update(movie);

            Thread.Sleep(1000);

            cloudSearch.Delete(movie);
        }
Esempio n. 8
0
        public void TestCRUD()
        {
            var cloudSearch = new CloudSearch <Movie>("YOU_AMAZON_CLOUD_SEARCH_KEY", "2011-02-01");

            var movie = new Movie {
                id = "fjuhewdijsdjoi", title = "simple title", year = 2012, mydate = DateTime.Now, actor = new List <string> {
                    "good actor1", "good actor2"
                }, director = "martin magakian"
            };

            cloudSearch.Add(movie);

            Thread.Sleep(1000);

            movie.title = "In the skin of Amazon cloud search";
            cloudSearch.Update(movie);

            Thread.Sleep(1000);

            cloudSearch.Delete(movie);
        }
Esempio n. 9
0
        public void TestSearch()
        {
            var cloudSearch = new CloudSearch<Movie>("YOU_AMAZON_CLOUD_SEARCH_KEY", "2011-02-01");

            //build facet
            var genreFacetContraint = new StringFacetConstraints();
            genreFacetContraint.AddContraint("Sci-Fi");
            genreFacetContraint.AddContraint("Fantasy");
            genreFacetContraint.AddContraint("Action");
            var genreFacet = new Facet { Name = "genre", TopResult = 2};

            var yearFacetContraint = new IntFacetContraints();
            yearFacetContraint.AddFrom(1950);
            yearFacetContraint.AddInterval(1980, 2012);
            var yearFacet = new Facet { Name = "year", FacetContraint = yearFacetContraint };

            var liFacet = new List<Facet> { genreFacet, yearFacet };

            //build boolean query
            var bQuery = new BooleanQuery();
            var gCondition = new StringBooleanCondition("genre", "Sci-Fi");
            var yCondition = new IntBooleanCondition("year");
            yCondition.SetInterval(2000,2004);
            bQuery.Conditions.Add(gCondition);
            bQuery.Conditions.Add(yCondition);

            //build search
            var searchQuery = new SearchQuery<Movie> {Keyword = "star wars", Facets = liFacet, Size = 20, Start = 40, BooleanQuery = bQuery};

            //search
            var found = cloudSearch.Search(searchQuery);

            Assert.IsTrue(!found.IsError);

            Assert.IsTrue(found.hits.found > 0);

            Assert.IsTrue(found.facetsResults.Count > 0);

            Assert.AreEqual(found.facetsResults.Count, 2, "We request only the top 2 facet");
        }
Esempio n. 10
0
 public void Init()
 {
     instance = new CloudSearch();
 }
Esempio n. 11
0
        /// <summary>
        /// search for cloudobjects following the criteria defined herein
        /// </summary>
        /// <exception cref="IO.Swagger.Client.ApiException">Thrown when fails to make API call</exception>
        /// <param name="appId">CloudApp id</param>
        /// <param name="tableName">cloud table name</param>
        /// <param name="body">query body</param>
        /// <returns>Task of ApiResponse (List&lt;CloudObject&gt;)</returns>
        public async System.Threading.Tasks.Task <ApiResponse <List <CloudObject> > > SearchAsyncWithHttpInfo(string appId, string tableName, CloudSearch body)
        {
            // verify the required parameter 'appId' is set
            if (appId == null)
            {
                throw new ApiException(400, "Missing required parameter 'appId' when calling Search");
            }
            // verify the required parameter 'tableName' is set
            if (tableName == null)
            {
                throw new ApiException(400, "Missing required parameter 'tableName' when calling Search");
            }
            // verify the required parameter 'body' is set
            if (body == null)
            {
                throw new ApiException(400, "Missing required parameter 'body' when calling Search");
            }


            var localVarPath = "data/{app_id}/{table_name}/search";

            var    localVarPathParams   = new Dictionary <String, String>();
            var    localVarQueryParams  = new Dictionary <String, String>();
            var    localVarHeaderParams = new Dictionary <String, String>(Configuration.DefaultHeader);
            var    localVarFormParams   = new Dictionary <String, String>();
            var    localVarFileParams   = new Dictionary <String, FileParameter>();
            Object localVarPostBody     = null;

            // to determine the Content-Type header
            String[] localVarHttpContentTypes = new String[] {
                "application/json"
            };
            String localVarHttpContentType = Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes);

            // to determine the Accept header
            String[] localVarHttpHeaderAccepts = new String[] {
                "application/json"
            };
            String localVarHttpHeaderAccept = Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts);

            if (localVarHttpHeaderAccept != null)
            {
                localVarHeaderParams.Add("Accept", localVarHttpHeaderAccept);
            }

            // set "format" to json by default
            // e.g. /pet/{petId}.{format} becomes /pet/{petId}.json
            localVarPathParams.Add("format", "json");
            if (appId != null)
            {
                localVarPathParams.Add("app_id", Configuration.ApiClient.ParameterToString(appId));                // path parameter
            }
            if (tableName != null)
            {
                localVarPathParams.Add("table_name", Configuration.ApiClient.ParameterToString(tableName));                    // path parameter
            }
            if (body.GetType() != typeof(byte[]))
            {
                localVarPostBody = Configuration.ApiClient.Serialize(body); // http body (model) parameter
            }
            else
            {
                localVarPostBody = body; // byte array
            }



            // make the HTTP request
            IRestResponse localVarResponse = (IRestResponse)await Configuration.ApiClient.CallApiAsync(localVarPath,
                                                                                                       Method.POST, localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarFileParams,
                                                                                                       localVarPathParams, localVarHttpContentType);

            int localVarStatusCode = (int)localVarResponse.StatusCode;

            if (localVarStatusCode >= 400)
            {
                throw new ApiException(localVarStatusCode, "Error calling Search: " + localVarResponse.Content, localVarResponse.Content);
            }
            else if (localVarStatusCode == 0)
            {
                throw new ApiException(localVarStatusCode, "Error calling Search: " + localVarResponse.ErrorMessage, localVarResponse.ErrorMessage);
            }

            return(new ApiResponse <List <CloudObject> >(localVarStatusCode,
                                                         localVarResponse.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()),
                                                         (List <CloudObject>)Configuration.ApiClient.Deserialize(localVarResponse, typeof(List <CloudObject>))));
        }
 public void UpdateIndex(string name, IEnumerable<IDocument> documents)
 {
     CloudSearch<AmazonDoc> cloudSearch = new CloudSearch<AmazonDoc>("index2-cdduimbipgk3rpnfgny6posyzy.eu-west-1.cloudsearch.amazonaws.com", "2013-01-01");
     cloudSearch.Update(documents.Select(d => new AmazonDoc(d)).ToList());
 }
Esempio n. 13
0
        /// <summary>
        /// search for cloudobjects following the criteria defined herein 
        /// </summary>
        /// <exception cref="IO.Swagger.Client.ApiException">Thrown when fails to make API call</exception>
        /// <param name="appId">CloudApp id</param>
        /// <param name="tableName">cloud table name</param>
        /// <param name="body">query body</param>
        /// <returns>Task of ApiResponse (List&lt;CloudObject&gt;)</returns>
        public async System.Threading.Tasks.Task<ApiResponse<List<CloudObject>>> SearchAsyncWithHttpInfo (string appId, string tableName, CloudSearch body)
        {
            // verify the required parameter 'appId' is set
            if (appId == null) throw new ApiException(400, "Missing required parameter 'appId' when calling Search");
            // verify the required parameter 'tableName' is set
            if (tableName == null) throw new ApiException(400, "Missing required parameter 'tableName' when calling Search");
            // verify the required parameter 'body' is set
            if (body == null) throw new ApiException(400, "Missing required parameter 'body' when calling Search");
            
    
            var localVarPath = "data/{app_id}/{table_name}/search";
    
            var localVarPathParams = new Dictionary<String, String>();
            var localVarQueryParams = new Dictionary<String, String>();
            var localVarHeaderParams = new Dictionary<String, String>(Configuration.DefaultHeader);
            var localVarFormParams = new Dictionary<String, String>();
            var localVarFileParams = new Dictionary<String, FileParameter>();
            Object localVarPostBody = null;

            // to determine the Content-Type header
            String[] localVarHttpContentTypes = new String[] {
                "application/json"
            };
            String localVarHttpContentType = Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes);

            // to determine the Accept header
            String[] localVarHttpHeaderAccepts = new String[] {
                "application/json"
            };
            String localVarHttpHeaderAccept = Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts);
            if (localVarHttpHeaderAccept != null)
                localVarHeaderParams.Add("Accept", localVarHttpHeaderAccept);

            // set "format" to json by default
            // e.g. /pet/{petId}.{format} becomes /pet/{petId}.json
            localVarPathParams.Add("format", "json");
            if (appId != null) localVarPathParams.Add("app_id", Configuration.ApiClient.ParameterToString(appId)); // path parameter
            if (tableName != null) localVarPathParams.Add("table_name", Configuration.ApiClient.ParameterToString(tableName)); // path parameter
            
            
            
            
            if (body.GetType() != typeof(byte[]))
            {
                localVarPostBody = Configuration.ApiClient.Serialize(body); // http body (model) parameter
            }
            else
            {
                localVarPostBody = body; // byte array
            }

            

            // make the HTTP request
            IRestResponse localVarResponse = (IRestResponse) await Configuration.ApiClient.CallApiAsync(localVarPath, 
                Method.POST, localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarFileParams, 
                localVarPathParams, localVarHttpContentType);

            int localVarStatusCode = (int) localVarResponse.StatusCode;
 
            if (localVarStatusCode >= 400)
                throw new ApiException (localVarStatusCode, "Error calling Search: " + localVarResponse.Content, localVarResponse.Content);
            else if (localVarStatusCode == 0)
                throw new ApiException (localVarStatusCode, "Error calling Search: " + localVarResponse.ErrorMessage, localVarResponse.ErrorMessage);

            return new ApiResponse<List<CloudObject>>(localVarStatusCode,
                localVarResponse.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()),
                (List<CloudObject>) Configuration.ApiClient.Deserialize(localVarResponse, typeof(List<CloudObject>)));
            
        }
Esempio n. 14
0
        /// <summary>
        /// search for cloudobjects following the criteria defined herein 
        /// </summary>
        /// <exception cref="IO.Swagger.Client.ApiException">Thrown when fails to make API call</exception>
        /// <param name="appId">CloudApp id</param>
        /// <param name="tableName">cloud table name</param>
        /// <param name="body">query body</param>
        /// <returns>Task of List&lt;CloudObject&gt;</returns>
        public async System.Threading.Tasks.Task<List<CloudObject>> SearchAsync (string appId, string tableName, CloudSearch body)
        {
             ApiResponse<List<CloudObject>> localVarResponse = await SearchAsyncWithHttpInfo(appId, tableName, body);
             return localVarResponse.Data;

        }
Esempio n. 15
0
 /// <summary>
 /// search for cloudobjects following the criteria defined herein 
 /// </summary>
 /// <exception cref="IO.Swagger.Client.ApiException">Thrown when fails to make API call</exception>
 /// <param name="appId">CloudApp id</param> 
 /// <param name="tableName">cloud table name</param> 
 /// <param name="body">query body</param> 
 /// <returns>List&lt;CloudObject&gt;</returns>
 public List<CloudObject> Search (string appId, string tableName, CloudSearch body)
 {
      ApiResponse<List<CloudObject>> localVarResponse = SearchWithHttpInfo(appId, tableName, body);
      return localVarResponse.Data;
 }
Esempio n. 16
0
        /// <summary>
        /// search for cloudobjects following the criteria defined herein
        /// </summary>
        /// <exception cref="IO.Swagger.Client.ApiException">Thrown when fails to make API call</exception>
        /// <param name="appId">CloudApp id</param>
        /// <param name="tableName">cloud table name</param>
        /// <param name="body">query body</param>
        /// <returns>List&lt;CloudObject&gt;</returns>
        public List <CloudObject> Search(string appId, string tableName, CloudSearch body)
        {
            ApiResponse <List <CloudObject> > localVarResponse = SearchWithHttpInfo(appId, tableName, body);

            return(localVarResponse.Data);
        }
Esempio n. 17
0
        /// <summary>
        /// search for cloudobjects following the criteria defined herein
        /// </summary>
        /// <exception cref="IO.Swagger.Client.ApiException">Thrown when fails to make API call</exception>
        /// <param name="appId">CloudApp id</param>
        /// <param name="tableName">cloud table name</param>
        /// <param name="body">query body</param>
        /// <returns>Task of List&lt;CloudObject&gt;</returns>
        public async System.Threading.Tasks.Task <List <CloudObject> > SearchAsync(string appId, string tableName, CloudSearch body)
        {
            ApiResponse <List <CloudObject> > localVarResponse = await SearchAsyncWithHttpInfo(appId, tableName, body);

            return(localVarResponse.Data);
        }
 public AmazonCloudSearch()
 {
     _cloudSearch = new CloudSearch<SearchDocument>(ApiEndpoint, ApiVersion);
 }
Esempio n. 19
0
 public void Init()
 {
     instance = new CloudSearch();
 }