コード例 #1
0
        public void QueryInList()
        {
            var q    = new SolrQueryInList("desc", "samsung", "hitachi", "fujitsu");
            var notq = new SolrNotQuery(q);

            Assert.AreEqual("-(desc:((samsung) OR (hitachi) OR (fujitsu)))", Serialize(notq));
        }
コード例 #2
0
        public static ICollection <ISolrQuery> GetSolrNetFilters(Query query, out string facetExclusion)
        {
            facetExclusion = null;
            if (query.Filters != null && query.Filters.Any())
            {
                var filters = new List <ISolrQuery>();
                for (int i = 0; i < query.Filters.Count(); i++)
                {
                    var        filter    = query.Filters.ElementAt(i);
                    ISolrQuery solrQuery = new SolrQueryInList(filter.Name, filter.Values);

                    if (i == query.Filters.Count() - 1)
                    {
                        var localParams = new LocalParams(new Dictionary <string, string> {
                            {
                                "tag",
                                DefaultSettings.DefaultExcludePrefix + filter.Name
                            }
                        });
                        solrQuery      = new LocalParams.LocalParamsQuery(solrQuery, localParams);
                        facetExclusion = filter.Name;
                    }

                    filters.Add(solrQuery);
                }

                return(filters);
            }

            return(null);
        }
コード例 #3
0
        public void QueryInList()
        {
            var q         = new SolrQueryInList("desc", "samsung", "hitachi", "fujitsu");
            var requiredq = new SolrRequiredQuery(q);

            Assert.AreEqual("+(desc:((samsung) OR (hitachi) OR (fujitsu)))", Serialize(requiredq));
        }
コード例 #4
0
        public async Task <List <BasicSongSearchResult> > Search(string artist, string songName)
        {
            if (string.IsNullOrWhiteSpace(artist) && string.IsNullOrWhiteSpace(songName))
            {
                return(null);
            }

            var songTerms   = GetStringFuzzySearchTerms(songName);
            var artistTerms = GetStringFuzzySearchTerms(artist);

            var songQuery = new SolrQueryInList(SolrSearchConstants.SongName, songTerms)
            {
                Quoted = false
            };
            var artistQuery = new SolrQueryInList(SolrSearchConstants.ArtistName, artistTerms)
            {
                Quoted = false
            };
            AbstractSolrQuery query;

            if (songTerms != null && artistTerms != null)
            {
                query = songQuery && artistQuery;
            }
            else if (songTerms != null && artistTerms == null)
            {
                query = songQuery;
            }
            else
            {
                query = artistQuery;
            }

            var result = await _songSearchOperations.QueryAsync(query);

            var resultList = result.ToList();

            var getBasicSongSearchResults = _getSongsFromSearchResultsQuery.Get(resultList);

            return(getBasicSongSearchResults);
        }
コード例 #5
0
        public void ShouldQuoteValues()
        {
            var q = new SolrQueryInList("id", new[] { "one", "two thousand" });

            Assert.AreEqual("((id:one) OR (id:\"two thousand\"))", Serialize(q));
        }
コード例 #6
0
        public void EmptyList_should_be_null_query()
        {
            var q = new SolrQueryInList("id", new string[0]);

            Assert.IsNull(Serialize(q));
        }
コード例 #7
0
 public void QueryInList() {
     var q = new SolrQueryInList("desc", "samsung", "hitachi", "fujitsu");
     var requiredq = new SolrRequiredQuery(q);
     Assert.AreEqual("+(desc:((samsung) OR (hitachi) OR (fujitsu)))", Serialize(requiredq));
 }
コード例 #8
0
        public void ShouldQuoteValues()
        {
            var q = new SolrQueryInList("id", new[] { "one", "two thousand", "three/hundred" });

            Assert.AreEqual("(id:(one) OR id:(\"two thousand\") OR id:(three\\/hundred))", Serialize(q));
        }
コード例 #9
0
        public void ShouldQuoteEmptyValues()
        {
            var q = new SolrQueryInList("id", new[] { "", "two thousand" });

            Assert.AreEqual("(id:(\"\") OR id:(\"two thousand\"))", Serialize(q));
        }
コード例 #10
0
 public void ShouldQuoteValues()
 {
     var q = new SolrQueryInList("id", new[] {"one", "two thousand"});
     Assert.AreEqual("(id:(one) OR id:(\"two thousand\"))", Serialize(q));
 }
コード例 #11
0
        public void ListOfInt()
        {
            var q = new SolrQueryInList("id", new[] { 1, 2, 3, 4 }.Select(i => i.ToString()));

            Assert.AreEqual("(id:(1) OR id:(2) OR id:(3) OR id:(4))", Serialize(q));
        }
コード例 #12
0
 public void EmptyList_should_be_null_query()
 {
     var q = new SolrQueryInList("id", new string[0]);
     Assert.IsNull(Serialize(q));
 }
コード例 #13
0
 public void ListOfInt()
 {
     var q = new SolrQueryInList("id", new[] {1, 2, 3, 4}.Select(i => i.ToString()));
     Assert.AreEqual("(id:(1) OR id:(2) OR id:(3) OR id:(4))", Serialize(q));
 }
コード例 #14
0
 public void ShouldQuoteValues()
 {
     var q = new SolrQueryInList("id", new[] {"one", "two thousand"});
     Assert.AreEqual("(id:one OR id:\"two thousand\")", q.Query);
 }
コード例 #15
0
        public SearchResult <Product> Handle(SearchQuery query)
        {
            var solr = Microsoft.Practices.ServiceLocation.ServiceLocator.Current.GetInstance <ISolrOperations <ProductSearchResultItem> >();

            //Text search
            AbstractSolrQuery solrQuery = string.IsNullOrEmpty(query.SearchText) ? SolrQuery.All :
                                          new SolrQueryBoost(new SolrQueryByField("product_title_t", query.SearchText), 2.0) ||
                                          new SolrQueryByField("product_description_t", query.SearchText);

            //Default filters that is always applied
            var filters = new List <ISolrQuery>
            {
                new SolrQueryByField("_language", query.Language),
                new SolrQueryByField("_templatename", query.TemplateName),
                new SolrNotQuery(new SolrQueryByField("_name", "__Standard Values"))
            };

            string keepFacetName = null;

            //User applied filters
            if (query.Filters.Any())
            {
                var index = 0;
                query.Filters.ForEach(filter =>
                {
                    ISolrQuery t = new SolrQueryInList(filter.Key, filter.Value);

                    if (++index == query.Filters.Count())
                    {
                        keepFacetName = filter.Key;
                        t             = new LocalParams.LocalParamsQuery(t, new LocalParams(new Dictionary <string, string> {
                            { "tag", "keepfacet" }
                        }));
                    }

                    filters.Add(t);
                });
            }

            var options = new QueryOptions();

            options.FilterQueries = filters;

            //Selected facets
            if (query.Facets != null && query.Facets.Any())
            {
                var facets = new List <ISolrFacetQuery>();
                query.Facets.ForEach(facet =>
                {
                    var facetPrefix = keepFacetName != null && keepFacetName == facet.Key ? "{!ex=keepfacet}" : string.Empty;
                    facets.Add(new SolrFacetFieldQuery(facetPrefix + facet.Key)
                    {
                        MinCount = facet.Value
                    });
                });
                options.AddFacets(facets.ToArray());
            }

            var results = solr.Query(solrQuery, options);

            return(new SearchResult <Product>
            {
                Hits = results.NumFound,
                Results = results.Select(result => new Product
                {
                    Id = result.ProductId,
                    Title = result.Title.First(),
                    Description = result.Description.First(),
                    Type = result.Type,
                    Category = result.Category,
                    Price = result.Price,
                    Rating = result.Rating,
                    IntroDate = result.IntroDate
                }),
                FacetResults = results.FacetFields.Select(facet => new Facet
                {
                    Key = facet.Key,
                    Values = facet.Value.Select(facetValue => new FacetValue
                    {
                        Key = facetValue.Key,
                        Count = facetValue.Value
                    })
                })
            });
        }
コード例 #16
0
 public void ListOfInt()
 {
     var q = new SolrQueryInList("id", new[] {1, 2, 3, 4}.Select(i => i.ToString()));
     Assert.AreEqual("(id:1 OR id:2 OR id:3 OR id:4)", q.Query);
 }
コード例 #17
0
        public void Fieldname_with_spaces()
        {
            var q = new SolrQueryInList("i have spaces", new[] { "one", "two thousand" });

            Assert.AreEqual("(i\\ have\\ spaces:((one) OR (\"two thousand\")))", Serialize(q));
        }
コード例 #18
0
ファイル: SolrNotQueryTests.cs プロジェクト: emargee/SolrNet
 public void QueryInList()
 {
     var q = new SolrQueryInList("desc", "samsung", "hitachi", "fujitsu");
     var notq = new SolrNotQuery(q);
     Assert.AreEqual("-(desc:samsung OR desc:hitachi OR desc:fujitsu)", Serialize(notq));
 }
コード例 #19
0
 public void ShouldQuoteEmptyValues()
 {
     var q = new SolrQueryInList("id", new[] { "", "two thousand" });
     Assert.AreEqual("(id:((\"\") OR (\"two thousand\")))", Serialize(q));
 }
コード例 #20
0
 public void Fieldname_with_spaces()
 {
     var q = new SolrQueryInList("i have spaces", new[] { "one", "two thousand" });
     Assert.AreEqual("(i\\ have\\ spaces:((one) OR (\"two thousand\")))", Serialize(q));
 }