示例#1
0
        public async Task <List <Product> > GetSolrProduct(string query)
        {
            using (new TimeMeasure("GetSolrProduct"))
            {
                try
                {
                    SolrQueryBuilder    builder  = new SolrQueryBuilder();
                    HttpResponseMessage response = null;
                    String   strPath             = HttpContext.Request.Url.PathAndQuery;
                    string[] test  = query.Split(new[] { "&rows=" }, StringSplitOptions.None);
                    var      count = test[0].Count(x => x == '&');

                    if (strPath.EndsWith("/") == false && query.Contains("TO") == false)
                    {
                        string[] splitting = query.Split(new[] { "&rows=" }, StringSplitOptions.None);
                        string   a         = Server.UrlEncode(splitting[0]);
                        string   b         = "&rows=" + splitting[1];
                        query = a + b;
                    }
                    else if (test[0].Contains("&") == true && count > 1)
                    {
                        string[] split1    = query.Split(new[] { "&rows=" }, StringSplitOptions.None);
                        string[] split2    = split1[0].Split(new[] { "q=" }, StringSplitOptions.None);
                        string   sanitize  = Server.UrlEncode(split2[1]);
                        string   old_split = "&rows=" + split1[1];
                        query = split2[0] + "q=" + sanitize + old_split;
                    }

                    if (Request.Url.AbsoluteUri.Contains("/butik/") && query.Contains("TO").Equals(true))
                    {
                        response = await client.GetAsync(builder.BuildDanishFquery(query));
                    }
                    else if (Request.Url.AbsoluteUri.Contains("/butik/") && query.Contains("TO").Equals(false))
                    {
                        response = await client.GetAsync(builder.BuildDanishQuery(query));
                    }
                    else if (Request.Url.AbsoluteUri.Contains("/shop/") && query.Contains("TO").Equals(true))
                    {
                        response = await client.GetAsync(builder.BuildFquery(query));
                    }
                    else if (Request.Url.AbsoluteUri.Contains("/shop/") && query.Contains("TO").Equals(false))
                    {
                        response = await client.GetAsync(builder.BuildQuery(query));
                    }
                    JObject responseJson = JObject.Parse(await response.Content.ReadAsStringAsync());
                    JArray  jProducts    = (JArray)responseJson["response"]["docs"];
                    NumberOfSearchResults = (int)responseJson["response"]["numFound"];
                    List <Product> result = jProducts.Select(p => Converter(p)).ToList();
                    return(result);
                }
                catch (Exception e)
                {
                    throw e;
                }
            }
        }
        public void SearchParameters_With_No_SelectedFilters_Return_Only_Actives_And_Visibles()
        {
            var searchParameterMock = new DynamicMock(typeof(ISearchParameters<Publication>));
            searchParameterMock.SetReturnValue("get_SelectedFilters", null);

            var solrQueryBuilder = new SolrQueryBuilder<Publication>((ISearchParameters<Publication>)searchParameterMock.MockInstance);
            var query = solrQueryBuilder.BuildQuery();

            Assert.IsTrue(query.Query.Equals("publication_state_id:Active AND publication_visible:true"));
        }
        public void SearchParameters_With__SelectedFilters_With_NoName_Return_SelectedFilterException()
        {
            var selectedFilters = new List<SelectedFilter>
                                      {
                                          new SelectedFilter(string.Empty, "val1", true, 1)
                                      };

            var searchParameterMock = new DynamicMock(typeof(ISearchParameters<Publication>));
            searchParameterMock.SetReturnValue("get_SelectedFilters", selectedFilters);

            var solrQueryBuilder = new SolrQueryBuilder<Publication>((ISearchParameters<Publication>)searchParameterMock.MockInstance);
            solrQueryBuilder.BuildQuery();
        }
        public void SimpleFilters_And_EmptyRangeFilter_Should_Not_Throw_SelectedFilterException()
        {
            var selectedFilters = new List<SelectedFilter>
                                      {
                                          new SelectedFilter("sl1", "val1", true, 1),
                                          new SelectedFilter("sl2", "val2", true, 1),
                                          new SelectedFilter("sl3", "-", true, 1)
                                      };

            var searchParameterMock = new DynamicMock(typeof(ISearchParameters<Publication>));
            searchParameterMock.SetReturnValue("get_SelectedFilters", selectedFilters);

            var solrQueryBuilder = new SolrQueryBuilder<Publication>((ISearchParameters<Publication>)searchParameterMock.MockInstance);
            solrQueryBuilder.BuildQuery();
        }
示例#5
0
文件: Tests.cs 项目: ruanzx/mausch
        public void Query()
        {
            var solrSearcher = new SolrSearcher("http://localhost:8983/solr/", Mode.ReadWrite);
            ISolrSearcher searcher = new SolrSearcherAdapter(solrSearcher);
            var updater = new SolrUpdater(solrSearcher);
            ISolrUpdater s = new SolrUpdaterAdapter(updater);
            ISolrQueryBuilder qb = new SolrQueryBuilder(searcher);

            qb.Query = new Query();
            var parameters = new List<QueryParameter>();
            parameters.Add(new QueryParameter("price", "[500 TO 1000]"));
            var qp = new QueryParameterCollection("q", parameters);
            qb.Query.AddQueryParameters(qp, ParameterJoin.AND);
            var results = new SolrSearchResults(qb);
            Console.WriteLine(results.TotalResults);
        }
        public void SimpleFilters_And_RangeFilter_Return_SolrQuery_WithRangeQuery()
        {
            var selectedFilters = new List<SelectedFilter>
                                      {
                                          new SelectedFilter("sl1", "val1", true, 1),
                                          new SelectedFilter("sl2", "val2", true, 1),
                                          new SelectedFilter("sl3", "from-to", true, 1)
                                      };

            var searchParameterMock = new DynamicMock(typeof(ISearchParameters<Publication>));
            searchParameterMock.SetReturnValue("get_SelectedFilters", selectedFilters);

            var solrQueryBuilder = new SolrQueryBuilder<Publication>((ISearchParameters<Publication>)searchParameterMock.MockInstance);
            var query = solrQueryBuilder.BuildQuery();

            Assert.IsTrue(query.Query == "publication_state_id:Active AND publication_visible:true AND sl1:val1 AND sl2:val2 AND sl3:[from TO to]");
        }