Exemplo n.º 1
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");
        }
 public void ShouldUrlEscapeAColonAfterTheField()
 {
     var stringBooleanCondition = new StringBooleanCondition(_field, _condition);
     var output = stringBooleanCondition.GetConditionParam();
     output.ShouldStartWith(string.Format("{0}{1}", _field, Uri.EscapeDataString(":")));
 }
 public void ShouldStartWithTheFieldName()
 {
     var stringBooleanCondition = new StringBooleanCondition(_field, _condition);
     var output = stringBooleanCondition.GetConditionParam();
     output.ShouldStartWith(_field);
 }
 public void ShouldEncloseTheConditionInQuotes()
 {
     var stringBooleanCondition = new StringBooleanCondition(_field, _condition);
     var output = stringBooleanCondition.GetConditionParam();
     output.ShouldEndWith(string.Format("'{0}'", _condition));
 }
 public void FormatShouldBeFieldColonQuoteConditionQuote()
 {
     var stringBooleanCondition = new StringBooleanCondition(_field, _condition);
     var output = stringBooleanCondition.GetConditionParam();
     output.ShouldEndWith(string.Format("{0}{1}'{2}'", _field, Uri.EscapeDataString(":"), _condition));
 }