Exemple #1
0
 public bool doQuery(PropertyGrid grid)
 {
     input = (SearchRequest)grid.SelectedObject; ;
     this.res = bing.Search(input);
     grid.SelectedObject = this.res;
     return (this.res != null);
 }
		protected void TestDefaultAssertions(SearchResponse<ElasticsearchProject> queryResponse)
		{
			Assert.True(queryResponse.IsValid);
			Assert.NotNull(queryResponse.ConnectionStatus);
			Assert.Null(queryResponse.ConnectionStatus.OriginalException);
			Assert.True(queryResponse.Total > 0, "No hits");
			Assert.True(queryResponse.Documents.Any());
			Assert.True(queryResponse.Documents.Count() > 0);
			Assert.True(queryResponse.Shards.Total > 0);
			Assert.True(queryResponse.Shards.Successful == queryResponse.Shards.Total);
			Assert.True(queryResponse.Shards.Failed == 0);

		}
Exemple #3
0
 private void DisplayResults(SearchResponse result)
 {
     txtResult.Clear();
     foreach(var show in result.Results)
     {
         Write("Id: " + show.ShowId);
         Write("Name: " + show.Name);
         Write("Seasons: " + show.Seasons);
         Write("TVRage URL: " + show.Link);
         Write("Status: " + show.Status);
         WriteHR('-');
     }
 }
        public void Search_ReturnsPopulatedResults()
        {
            var sampleResponse = new SearchResponse
            {
                TotalResults = 1,
                Results = new[] {new SearchResult()}
            };
            string json = JsonConvert.SerializeObject(sampleResponse);
            MockResponse(json);

            var request = new SearchRequest {Query = "foobar"};
            SearchResponse response = _nutritionix.SearchItems(request);

            Assert.AreEqual(1, response.Results.Length);
        }
        public void Search_ReturnsEmptyResults_WhenResultsIsNull()
        {
            var sampleResponse = new SearchResponse
            {
                TotalResults = 0,
                Results = null
            };
            string json = JsonConvert.SerializeObject(sampleResponse);
            MockResponse(json);

            var request = new SearchRequest {Query = "foobar"};
            SearchResponse response = _nutritionix.SearchItems(request);

            Assert.IsNotNull(response.Results);
            Assert.AreEqual(0, response.Results.Length);
        }
Exemple #6
0
        public static ReadOnlyCollection <string> GetComputerDN(string computerName)
        {
            //searching against default domain controller and GC interface
            List <string> retVal = new List <string>();

            using (LdapConnection connGC = GetLdapConnection(ConnectionType.Gc))
            {
                ForestInfo    di           = GetForestRootDomain();
                SearchRequest rq           = new SearchRequest();
                string        searchString = string.Format(System.Globalization.CultureInfo.InvariantCulture, "(&(objectClass=computer)(cn={0}))", computerName);
                rq                   = new SearchRequest();
                rq.Filter            = searchString;
                rq.Scope             = SearchScope.Subtree;
                rq.DistinguishedName = di.RootDomain.Dn;
                SearchResponse rsp = (SearchResponse)connGC.SendRequest(rq);
                foreach (SearchResultEntry sr in rsp.Entries)
                {
                    retVal.Add(sr.DistinguishedName);
                }
            }
            return(new ReadOnlyCollection <string>(retVal));
        }
Exemple #7
0
        public static System.DirectoryServices.ActiveDirectorySecurity GetObjectSecurity(LdapConnection conn, string objectDN, System.DirectoryServices.Protocols.SecurityMasks securityMask)
        {
            if (conn == null)
            {
                throw new ArgumentNullException("Method does not accept null parameters");
            }
            System.DirectoryServices.ActiveDirectorySecurity retVal = new System.DirectoryServices.ActiveDirectorySecurity();

            //get securityDescriptor
            SearchRequest searchRq = new SearchRequest(objectDN, string.Format(System.Globalization.CultureInfo.InvariantCulture, "(distinguishedName={0})", objectDN), System.DirectoryServices.Protocols.SearchScope.Base, "ntSecurityDescriptor");

            searchRq.Controls.Add(new SecurityDescriptorFlagControl(securityMask));
            SearchResponse rsp = (SearchResponse)conn.SendRequest(searchRq);

            foreach (SearchResultEntry sr in rsp.Entries)
            {
                byte[] ntSecurityDescriptor = sr.Attributes["ntsecuritydescriptor"].GetValues(typeof(byte[]))[0] as byte[];
                retVal.SetSecurityDescriptorBinaryForm(ntSecurityDescriptor);
            }

            return(retVal);
        }
        public void Line25()
        {
            // tag::4e75503583efc222045e0be4430a2863[]
            var response0 = new SearchResponse <object>();

            // end::4e75503583efc222045e0be4430a2863[]

            response0.MatchesExample(@"PUT my_index
			{
			  ""mappings"": {
			    ""properties"": {
			      ""status_code"": { \<1>
			        ""type"":       ""keyword""
			      },
			      ""session_id"": { \<2>
			        ""type"":       ""keyword"",
			        ""doc_values"": false
			      }
			    }
			  }
			}"            );
        }
Exemple #9
0
        public void Line43()
        {
            // tag::134384b8c63cfbd8d762fb01757bb3f9[]
            var response0 = new SearchResponse <object>();

            var response1 = new SearchResponse <object>();

            // end::134384b8c63cfbd8d762fb01757bb3f9[]

            response0.MatchesExample(@"POST logs-debug/_doc
			{
			  ""date"": ""2019-12-12"",
			  ""message"": ""Starting up Elasticsearch"",
			  ""level"": ""debug""
			}"            );

            response1.MatchesExample(@"POST logs-debug/_doc
			{
			  ""date"": ""2019-12-12"",
			  ""message"": ""Starting up Elasticsearch""
			}"            );
        }
Exemple #10
0
        public void Line101()
        {
            // tag::9f7d8207b976f664badc27ef659c9706[]
            var response0 = new SearchResponse <object>();

            // end::9f7d8207b976f664badc27ef659c9706[]

            response0.MatchesExample(@"PUT /_index_template/logs_data_stream
			{
			  ""index_patterns"": [ ""logs*"" ],
			  ""data_stream"": { },
			  ""template"": {
			    ""mappings"": {
			      ""properties"": {
			        ""message"": {                              <1>
			          ""type"": ""text""
			        }
			      }
			    }
			  }
			}"            );
        }
        public override SearchResult Transform(SearchQuery searchQuery, SearchResponse searchResponse, bool includeScore = false)
        {
            return(new SearchResult
            {
                Items = new Lazy <IEnumerable <SearchResultItem> >(() =>
                {
                    IoC.Resolve <TargetGroupEngine>().Process(new SearchEvent
                    {
                        SearchText = searchQuery.Text,
                        TotalHits = searchResponse.TotalHitCount
                    });

                    var categories = searchResponse.Hits.Select(x => new Guid(x.Id).GetCategory());
                    return categories.Where(c => c != null).Select(x => new CategorySearchResult
                    {
                        Item = x,
                        Id = x.SystemId,
                        Name = x.Localizations.CurrentCulture.Name,
                        Url = _urlService.GetUrl(x),
                        Score = includeScore ? searchResponse.Hits.Where(z => z.Id == x.SystemId.ToString()).Select(z => z.Score).FirstOrDefault() : default
                    });
                }),
        public void Line397()
        {
            // tag::83b4a737514a047d31f12f110bed0b5e[]
            var response0 = new SearchResponse <object>();

            // end::83b4a737514a047d31f12f110bed0b5e[]

            response0.MatchesExample(@"PUT /_ingest/pipeline/postal_lookup
			{
			  ""description"": ""Enrich postal codes"",
			  ""processors"": [
			    {
			      ""enrich"": {
			        ""policy_name"": ""postal_policy"",
			        ""field"": ""geo_location"",
			        ""target_field"": ""geo_data"",
			        ""shape_relation"": ""INTERSECTS""
			      }
			    }
			  ]
			}"            );
        }
Exemple #13
0
        public void Line49()
        {
            // tag::f3b4ddce8ff21fc1a76a7c0d9c36650e[]
            var response0 = new SearchResponse <object>();

            // end::f3b4ddce8ff21fc1a76a7c0d9c36650e[]

            response0.MatchesExample(@"PUT _ilm/policy/my_policy
			{
			  ""policy"": {
			    ""phases"": {
			      ""warm"": {
			        ""actions"": {
			          ""shrink"" : {
			            ""number_of_shards"": 1
			          }
			        }
			      }
			    }
			  }
			}"            );
        }
        public void Line268()
        {
            // tag::829d345e5e15e371aeb820f4d62a1b2a[]
            var response0 = new SearchResponse <object>();

            // end::829d345e5e15e371aeb820f4d62a1b2a[]

            response0.MatchesExample(@"GET latency/_search
			{
			    ""size"": 0,
			    ""aggs"" : {
			        ""load_time_outlier"" : {
			            ""percentiles"" : {
			                ""field"" : ""load_time"",
			                ""tdigest"": {
			                  ""compression"" : 200 \<1>
			                }
			            }
			        }
			    }
			}"            );
        }
Exemple #15
0
        public void Line37()
        {
            // tag::eb5486d2fe4283475bf9e0e09280be16[]
            var response0 = new SearchResponse <object>();

            // end::eb5486d2fe4283475bf9e0e09280be16[]

            response0.MatchesExample(@"PUT _ilm/policy/my_policy
			{
			  ""policy"": {
			    ""phases"": {
			      ""warm"": {
			        ""actions"": {
			          ""forcemerge"" : {
			            ""max_num_segments"": 1
			          }
			        }
			      }
			    }
			  }
			}"            );
        }
Exemple #16
0
        public void Line17()
        {
            // tag::e50f9492af9e0174c7ecbe5ad7f09d74[]
            var response0 = new SearchResponse <object>();

            // end::e50f9492af9e0174c7ecbe5ad7f09d74[]

            response0.MatchesExample(@"POST /sales*/_async_search?size=0
			{
			    ""sort"" : [
			      { ""date"" : {""order"" : ""asc""} }
			    ],
			    ""aggs"" : {
			        ""sale_date"" : {
			             ""date_histogram"" : {
			                 ""field"" : ""date"",
			                 ""calendar_interval"": ""1d""
			             }
			         }
			    }
			}"            );
        }
        public void Line341()
        {
            // tag::a4eac3c0bac550247e8c7d3f9bcaac1c[]
            var response0 = new SearchResponse <object>();

            // end::a4eac3c0bac550247e8c7d3f9bcaac1c[]

            response0.MatchesExample(@"POST music/_search?pretty
			{
			    ""suggest"": {
			        ""song-suggest"" : {
			            ""prefix"" : ""nor"",
			            ""completion"" : {
			                ""field"" : ""suggest"",
			                ""fuzzy"" : {
			                    ""fuzziness"" : 2
			                }
			            }
			        }
			    }
			}"            );
        }
        /// <summary>
        /// Adavalidation method is used to Validate AD related Requiremnts.
        /// This method compares boolean type attribute values of the specified object
        /// </summary>
        /// <param name="GuidString">Distinguished Name</param>
        /// <param name="GuidClass">ladpFilter</param>
        /// <param name="refString">Attribute</param>
        /// <param name="comparreValue">ExprectedValue</param>
        /// <returns></returns>

        public bool AdValidation(String GuidString, string GuidClass, string refString, bool comparreValue)
        {
            if (GuidString == null)
            {
                return(false);
            }
            using (LdapConnection connection = new LdapConnection(ConfigStore.DomainDnsName))
            {
                connection.AuthType = AuthType.Basic;
                connection.Bind(new System.Net.NetworkCredential(ConfigStore.AdminName, ConfigStore.AdminPassword, ConfigStore.DomainNetbiosName));
                bool           flag     = false;
                SearchRequest  request  = new SearchRequest(GuidString, GuidClass, System.DirectoryServices.Protocols.SearchScope.Subtree, new string[] { refString });
                SearchResponse response = (SearchResponse)connection.SendRequest(request);
                Guid           guid     = Guid.Empty;
                foreach (SearchResultEntry entry in response.Entries)
                {
                    SearchResultAttributeCollection attributeCollection = entry.Attributes;
                    foreach (DirectoryAttribute attribute in attributeCollection.Values)
                    {
                        for (int j = 0; j < attribute.Count; j++)
                        {
                            if (attribute[j] is string)
                            {
                                bool attvalue = Convert.ToBoolean(attribute[j]);
                                if (attvalue == comparreValue)
                                {
                                    return(true);
                                }
                                else
                                {
                                    return(false);
                                }
                            }
                        }
                    }
                }
                return(flag);
            }
        }
        public void Line25()
        {
            // tag::0d7b0f40446e2001c63bef29f84530eb[]
            var response0 = new SearchResponse <object>();

            // end::0d7b0f40446e2001c63bef29f84530eb[]

            response0.MatchesExample(@"GET my_index/_search
			{
			  ""query"": {
			    ""term"": {
			      ""_type"": ""_doc""  <1>
			    }
			  },
			  ""aggs"": {
			    ""types"": {
			      ""terms"": {
			        ""field"": ""_type"", <2>
			        ""size"": 10
			      }
			    }
			  },
			  ""sort"": [
			    {
			      ""_type"": { <3>
			        ""order"": ""desc""
			      }
			    }
			  ],
			  ""script_fields"": {
			    ""type"": {
			      ""script"": {
			        ""lang"": ""painless"",
			        ""source"": ""doc['_type']"" <4>
			      }
			    }
			  }
			}"            );
        }
Exemple #20
0
        public void Line56()
        {
            // tag::e9fe3b53b5b6e1ff9566b5237c0fa513[]
            var response0 = new SearchResponse <object>();

            var response1 = new SearchResponse <object>();

            // end::e9fe3b53b5b6e1ff9566b5237c0fa513[]

            response0.MatchesExample(@"PUT child_example/_doc/2?routing=1
			{
			  ""join"": {
			    ""name"": ""answer"",
			    ""parent"": ""1""
			  },
			  ""owner"": {
			    ""location"": ""Norfolk, United Kingdom"",
			    ""display_name"": ""Sam"",
			    ""id"": 48
			  },
			  ""body"": ""\<p>Unfortunately you're pretty much limited to FTP..."",
			  ""creation_date"": ""2009-05-04T13:45:37.030""
			}"            );

            response1.MatchesExample(@"PUT child_example/_doc/3?routing=1&refresh
			{
			  ""join"": {
			    ""name"": ""answer"",
			    ""parent"": ""1""
			  },
			  ""owner"": {
			    ""location"": ""Norfolk, United Kingdom"",
			    ""display_name"": ""Troll"",
			    ""id"": 49
			  },
			  ""body"": ""\<p>Use Linux..."",
			  ""creation_date"": ""2009-05-05T13:45:37.030""
			}"            );
        }
        public void Line135()
        {
            // tag::432ab6ff7cfe06988dda436907218cc5[]
            var response0 = new SearchResponse <object>();

            // end::432ab6ff7cfe06988dda436907218cc5[]

            response0.MatchesExample(@"PUT /simple_example
			{
			  ""settings"": {
			    ""analysis"": {
			      ""analyzer"": {
			        ""rebuilt_simple"": {
			          ""tokenizer"": ""lowercase"",
			          ""filter"": [         \<1>
			          ]
			        }
			      }
			    }
			  }
			}"            );
        }
        public void Line325()
        {
            // tag::e0b414b45460d424ab838b5136492fa1[]
            var response0 = new SearchResponse <object>();

            // end::e0b414b45460d424ab838b5136492fa1[]

            response0.MatchesExample(@"PUT my_index
			{
			  ""mappings"": {
			    ""properties"": {
			      ""my_join_field"": {
			        ""type"": ""join"",
			        ""relations"": {
			           ""question"": ""answer""
			        },
			        ""eager_global_ordinals"": false
			      }
			    }
			  }
			}"            );
        }
        public void Line387()
        {
            // tag::1cc03b9715d9a3f876f7b7bb7fe66394[]
            var response0 = new SearchResponse <object>();

            // end::1cc03b9715d9a3f876f7b7bb7fe66394[]

            response0.MatchesExample(@"PUT my_index
			{
			  ""mappings"": {
			    ""properties"": {
			      ""my_join_field"": {
			        ""type"": ""join"",
			        ""relations"": {
			          ""question"": [""answer"", ""comment""],  \<1>
			          ""answer"": ""vote"" \<2>
			        }
			      }
			    }
			  }
			}"            );
        }
Exemple #24
0
        public void Line54()
        {
            // tag::1116c769f39f0c7fe86ec2a4871efcd5[]
            var response0 = new SearchResponse <object>();

            // end::1116c769f39f0c7fe86ec2a4871efcd5[]

            response0.MatchesExample(@"PUT _ilm/policy/my_policy
			{
			  ""policy"": {
			    ""phases"": {
			      ""warm"": {
			        ""actions"": {
			          ""allocate"" : {
			            ""number_of_replicas"" : 2
			          }
			        }
			      }
			    }
			  }
			}"            );
        }
Exemple #25
0
        public void Line90()
        {
            // tag::930f51600604a9cc3eae43d7fbbc633a[]
            var response0 = new SearchResponse <object>();

            var response1 = new SearchResponse <object>();

            var response2 = new SearchResponse <object>();

            // end::930f51600604a9cc3eae43d7fbbc633a[]

            response0.MatchesExample(@"PUT /places
			{
			    ""mappings"": {
			        ""properties"": {
			            ""geometry"": {
			                ""type"": ""geo_shape""
			            }
			        }
			    }
			}"            );

            response1.MatchesExample(@"POST /places/_bulk?refresh
			{""index"":{""_id"":1}}
			{""name"": ""NEMO Science Museum"", ""geometry"": ""POINT(4.912350 52.374081)"" }
			{""index"":{""_id"":2}}
			{""name"": ""Sportpark De Weeren"", ""geometry"": { ""type"": ""Polygon"", ""coordinates"": [ [ [ 4.965305328369141, 52.39347642069457 ], [ 4.966979026794433, 52.391721758934835 ], [ 4.969425201416015, 52.39238958618537 ], [ 4.967944622039794, 52.39420969150824 ], [ 4.965305328369141, 52.39347642069457 ] ] ] } }"            );

            response2.MatchesExample(@"POST /places/_search?size=0
			{
			    ""aggs"" : {
			        ""viewport"" : {
			            ""geo_bounds"" : {
			                ""field"" : ""geometry""
			            }
			        }
			    }
			}"            );
        }
Exemple #26
0
        public void Line612()
        {
            // tag::a5cc9a86f0f9525cd86564421c721d2f[]
            var response0 = new SearchResponse <object>();

            // end::a5cc9a86f0f9525cd86564421c721d2f[]

            response0.MatchesExample(@"GET _render/template
			{
			    ""source"" : {
			        ""query"" : {
			            ""term"": {
			                ""http_access_log"": ""{{#url}}{{host}}/{{page}}{{/url}}""
			            }
			        }
			    },
			    ""params"": {
			        ""host"": ""https://www.elastic.co/"",
			        ""page"": ""learn""
			    }
			}"            );
        }
Exemple #27
0
        public void Line73()
        {
            // tag::3cd2f7f9096a8e8180f27b6c30e71840[]
            var response0 = new SearchResponse <object>();

            // end::3cd2f7f9096a8e8180f27b6c30e71840[]

            response0.MatchesExample(@"GET logs/_search
			{
			  ""size"": 0,
			  ""aggs"" : {
			    ""messages"" : {
			      ""filters"" : {
			        ""filters"" : [
			          { ""match"" : { ""body"" : ""error""   }},
			          { ""match"" : { ""body"" : ""warning"" }}
			        ]
			      }
			    }
			  }
			}"            );
        }
Exemple #28
0
        public void Line141()
        {
            // tag::a61389da4033bd7b73a63ff2ee258125[]
            var response0 = new SearchResponse <object>();

            var response1 = new SearchResponse <object>();

            // end::a61389da4033bd7b73a63ff2ee258125[]

            response0.MatchesExample(@"PUT my_index
			{
			  ""settings"": {
			    ""analysis"": {
			      ""analyzer"": {
			        ""my_analyzer"": {
			          ""tokenizer"": ""my_tokenizer""
			        }
			      },
			      ""tokenizer"": {
			        ""my_tokenizer"": {
			          ""type"": ""edge_ngram"",
			          ""min_gram"": 2,
			          ""max_gram"": 10,
			          ""token_chars"": [
			            ""letter"",
			            ""digit""
			          ]
			        }
			      }
			    }
			  }
			}"            );

            response1.MatchesExample(@"POST my_index/_analyze
			{
			  ""analyzer"": ""my_analyzer"",
			  ""text"": ""2 Quick Foxes.""
			}"            );
        }
        public void Line551()
        {
            // tag::958b661d89b2beeb0cfefe8edbe3e408[]
            var response0 = new SearchResponse <object>();

            // end::958b661d89b2beeb0cfefe8edbe3e408[]

            response0.MatchesExample(@"PUT /_ingest/pipeline/user_lookup
			{
			  ""description"" : ""Enriching user details to messages"",
			  ""processors"" : [
			    {
			      ""enrich"" : {
			        ""policy_name"": ""users-policy"",
			        ""field"" : ""email"",
			        ""target_field"": ""user"",
			        ""max_matches"": ""1""
			      }
			    }
			  ]
			}"            );
        }
        public void Line252()
        {
            // tag::1b37488d0a79d3c950029851b7cd623e[]
            var response0 = new SearchResponse <object>();

            // end::1b37488d0a79d3c950029851b7cd623e[]

            response0.MatchesExample(@"GET /_mget?routing=key1
			{
			    ""docs"" : [
			        {
			            ""_index"" : ""test"",
			            ""_id"" : ""1"",
			            ""routing"" : ""key2""
			        },
			        {
			            ""_index"" : ""test"",
			            ""_id"" : ""2""
			        }
			    ]
			}"            );
        }
        public void Line128()
        {
            // tag::31aed390c30bd4f42a5c56253695e53f[]
            var response0 = new SearchResponse <object>();

            // end::31aed390c30bd4f42a5c56253695e53f[]

            response0.MatchesExample(@"PUT /whitespace_example
			{
			  ""settings"": {
			    ""analysis"": {
			      ""analyzer"": {
			        ""rebuilt_whitespace"": {
			          ""tokenizer"": ""whitespace"",
			          ""filter"": [         \<1>
			          ]
			        }
			      }
			    }
			  }
			}"            );
        }
        public void Line31()
        {
            // tag::a1849d3cb44fc24b58323ec97c5e9c5c[]
            var response0 = new SearchResponse <object>();

            // end::a1849d3cb44fc24b58323ec97c5e9c5c[]

            response0.MatchesExample(@"PUT /products/_doc/0
			{
			  ""name"": ""LED TV"", <1>
			  ""resellers"": [
			    {
			      ""reseller"": ""companyA"",
			      ""price"": 350
			    },
			    {
			      ""reseller"": ""companyB"",
			      ""price"": 500
			    }
			  ]
			}"            );
        }
        public void Line10()
        {
            // tag::60917d97013c4516c621c6c24c29748f[]
            var response0 = new SearchResponse <object>();

            // end::60917d97013c4516c621c6c24c29748f[]

            response0.MatchesExample(@"PUT /products
			{
			    ""mappings"": {
			        ""properties"" : {
			            ""resellers"" : { <1>
			                ""type"" : ""nested"",
			                ""properties"" : {
			                    ""reseller"" : { ""type"" : ""text"" },
			                    ""price"" : { ""type"" : ""double"" }
			                }
			            }
			        }
			    }
			}"            );
        }
Exemple #34
0
        public void Line102()
        {
            // tag::db8cbfa2afece5d21b3ca69ffee8f5c0[]
            var response0 = new SearchResponse <object>();

            // end::db8cbfa2afece5d21b3ca69ffee8f5c0[]

            response0.MatchesExample(@"PUT /my_index
			{
			    ""settings"": {
			        ""index"" : {
			            ""analysis"" : {
			                ""analyzer"" : {
			                    ""my_synonyms"" : {
			                        ""tokenizer"" : ""whitespace"",
			                        ""filter"" : [""synonym""]
			                    }
			                },
			                ""filter"" : {
			                    ""synonym"" : {
			                        ""type"" : ""synonym_graph"",
			                        ""synonyms_path"" : ""analysis/synonym.txt"", <1>
			                        ""updateable"" : true <2>
			                    }
			                }
			            }
			        }
			    },
			    ""mappings"": {
			        ""properties"": {
			            ""text"": {
			                ""type"": ""text"",
			                ""analyzer"" : ""standard"",
			                ""search_analyzer"": ""my_synonyms"" <3>
			            }
			        }
			    }
			}"            );
        }
Exemple #35
0
        public void Line57()
        {
            // tag::525ec32997125d401f9c128ca450cefa[]
            var response0 = new SearchResponse <object>();

            // end::525ec32997125d401f9c128ca450cefa[]

            response0.MatchesExample(@"GET twitter/_search
			{
			    ""size"": 10,
			    ""query"": {
			        ""match"" : {
			            ""title"" : ""elasticsearch""
			        }
			    },
			    ""search_after"": [1463538857, ""654323""],
			    ""sort"": [
			        {""date"": ""asc""},
			        {""tie_breaker_id"": ""asc""}
			    ]
			}"            );
        }
        /// <summary>
        /// Gets all the products under a specific category
        /// </summary>
        /// <param name="categoryId">The parent category id</param>
        /// <param name="searchOptions">The paging options for this query</param>
        /// <returns>A list of child products</returns>
        public static SearchResponse GetCategoryChildCategories(ID categoryId, CommerceSearchOptions searchOptions)
        {
            SearchResponse response = new SearchResponse();

            var searchManager = CommerceTypeLoader.CreateInstance<ICommerceSearchManager>();
            var searchIndex = searchManager.GetIndex();

            using (var context = searchIndex.CreateSearchContext())
            {
                var searchResults = context.GetQueryable<CommerceBaseCatalogSearchResultItem>()
                    .Where(item => item.CommerceSearchItemType == CommerceSearchResultItemType.Category)
                    .Where(item => item.Language == CurrentLanguageName)
                    .Where(item => item.ItemId == categoryId)
                    .Select(p => p);

                var list = searchResults.ToList();
                if (list.Count > 0)
                {
                    if (list[0].Fields.ContainsKey(StorefrontConstants.KnownIndexFields.ChildCategoriesSequence))
                    {
                        var childCategoryDelimitedString = list[0][StorefrontConstants.KnownIndexFields.ChildCategoriesSequence];

                        string[] categoryIdArray = childCategoryDelimitedString.Split('|');

                        foreach (var childCategoryId in categoryIdArray)
                        {
                            var childCategoryItem = Sitecore.Context.Database.GetItem(ID.Parse(childCategoryId));
                            if (childCategoryItem != null)
                            {
                                response.ResponseItems.Add(childCategoryItem);
                            }
                        }
                    }
                }
            }

            return response;
        }
 public ResultModel()
 {
     Results = new SearchResponse<EmployeeSkillsDocument>();
     InputQuery = "_all:*";
 }
Exemple #38
0
        private List<Page> GetPagesFromSearchResponse(SearchResponse response, Litium.Foundation.Modules.CMS.Security.PermissionManager permissionManager, SecurityToken token)
        {
            List<Page> pages = new List<Page>();

            if (response != null && response.Hits != null)
            {
                foreach (Hit hit in response.Hits)
                {
                    Guid pageId = new Guid(hit.Id);

                    // Verify that page exists and user has permission to view page
                    if (Page.ExistsPage(pageId) && permissionManager.UserHasPageReadPermission(token.UserID, pageId, true, true))
                    {
                        // Fetch page from database
                        Page page = Page.GetFromID(pageId, token);
                        pages.Add(page);
                    }
                }
            }

            return pages;
        }
Exemple #39
0
        private List<PageInfoCarrier> GetPageInfoCarriersFromSearchResponse(SearchResponse response, SiteMapCache siteMapCache)
        {
            var pages = (from hit in response.Hits
                         select new Guid(hit.Id) into pageID
                         where Page.ExistsPage(pageID)
                         select siteMapCache.GetPage(pageID)).ToList();

            return pages;
        }
 private void SearchRegionToItemsCollection(SearchResponse response)
 {
     if (response.ResultSets[0].SearchRegion.GeocodeLocation != null
         && response.ResultSets[0].SearchRegion.GeocodeLocation.Address != null
         && response.ResultSets[0].SearchRegion.GeocodeLocation.Locations.Count > 0)
     {
         foreach (Location location in response.ResultSets[0].SearchRegion.GeocodeLocation.Locations)
         {
             MapItem item = new MapItem()
             {
                 Title = response.ResultSets[0].SearchRegion.GeocodeLocation.Address.FormattedAddress,
                 Location = location
             };
             this.itemCollection.Add(item);
         }
     }
 }
 private void ShowBoundingArea(SearchResponse response)
 {
     if (response.ResultSets[0].SearchRegion.BoundingArea != null)
     {   
         MapShapeData boundingArea = response.ResultSets[0].SearchRegion.BoundingAreaData;
         boundingArea.ShapeFill = new MapShapeFill()
         {
             Stroke = new SolidColorBrush(Colors.Red),
             StrokeThickness = 1
         };
         this.regionLayer.Items.Add(boundingArea);
     }
 }
 private void SearchRosterEvent(SearchResponse response)
 {
     if (response != null && response.users != null)
     {
         this.AddUsersHandle(response.users);
     }
 }
 private void SetBestView(SearchResponse response)
 {
     if (response.ResultSets[0].SearchRegion.GeocodeLocation != null)
     {
         this.radMap.SetView(response.ResultSets[0].SearchRegion.GeocodeLocation.BestView);
     }
     else if (response.ResultSets[0].SearchRegion.BoundingArea != null)
     {
         this.radMap.SetView(response.ResultSets[0].SearchRegion.BoundingArea.GeographicalBounds);
     }
 }
/*        public void SearchAsync(string query)
        {
            
            AsyncManager.OutstandingOperations.Increment();
            AsyncManager.Parameters["query"] = query;
            if (string.IsNullOrEmpty(query))
                AsyncManager.OutstandingOperations.Decrement();

            SearchRequest request;
            var client = PrepareBingRequest(query, out request);

            client.BeginSearch(request, (result) =>
                                            {
                                                var serchResult = client.EndSearch(result);
                                                AsyncManager.Parameters["searchResponse"] = serchResult;
                                                AsyncManager.OutstandingOperations.Decrement();
                                            }, null);
        }

        private BingPortTypeClient PrepareBingRequest(string query, out SearchRequest request)
        {
            var client = new BingPortTypeClient();
            var keys = WebConfigurationManager.AppSettings["bing_search"].Split(',');

            request = new SearchRequest();
            request.AppId = keys[new Random().Next(keys.Length)];
            request.Options = new[] {SearchOption.EnableHighlighting, SearchOption.DisableLocationDetection};
            request.Adult = AdultOption.Off;
            request.Query = query+" site:"+Request.Url.Host;
            request.Sources = new[] {SourceType.Web, SourceType.Spell, SourceType.RelatedSearch};
            request.Web = new WebRequest();
            return client;
        }*/

        public ActionResult Search(string query, SearchResponse searchResponse)
        {
            ViewData["query"] = query ?? string.Empty;

/*            if (searchResponse!=null && searchResponse.Web!=null)
            {
                if (searchResponse.Web.Results!=null && searchResponse.Web.Results.Any())
                {
                    //Format results
                    try
                    {
                        var results = BingSearchHelper.CreateResults(searchResponse.Web.Results);
                        return View(results);
                    }
                    catch (Exception)
                    {
                        //Failed. fallback to our search
                    }
                }
            }*/
            return View(Documentation.Search(query ?? string.Empty));
        }
 private void AddResultsToItemsCollection(SearchResponse response)
 {
     if (response.ResultSets[0].Results.Count > 0)
     {
         foreach (SearchResultBase result in response.ResultSets[0].Results)
         {
             MapItem item = new MapItem()
             {
                 Title = result.Name,
                 Location = result.LocationData.Locations[0]
             };
             this.itemCollection.Add(item);
         }
     }
 }
 public void TestAllProperties(SearchResponse response)
 {
     Assert.IsNotNull(response.Count);
     Assert.IsNotNull(response.List);
     Assert.IsNotNull(response.List);
     Assert.IsNotNull(response.Mode);
 }