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)); }
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); }
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)); }
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); }
public void ShouldQuoteValues() { var q = new SolrQueryInList("id", new[] { "one", "two thousand" }); Assert.AreEqual("((id:one) OR (id:\"two thousand\"))", Serialize(q)); }
public void EmptyList_should_be_null_query() { var q = new SolrQueryInList("id", new string[0]); Assert.IsNull(Serialize(q)); }
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)); }
public void ShouldQuoteEmptyValues() { var q = new SolrQueryInList("id", new[] { "", "two thousand" }); Assert.AreEqual("(id:(\"\") OR id:(\"two thousand\"))", Serialize(q)); }
public void ShouldQuoteValues() { var q = new SolrQueryInList("id", new[] {"one", "two thousand"}); Assert.AreEqual("(id:(one) OR id:(\"two thousand\"))", Serialize(q)); }
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)); }
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)); }
public void ShouldQuoteValues() { var q = new SolrQueryInList("id", new[] {"one", "two thousand"}); Assert.AreEqual("(id:one OR id:\"two thousand\")", q.Query); }
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 }) }) }); }
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); }
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)); }
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)); }
public void ShouldQuoteEmptyValues() { var q = new SolrQueryInList("id", new[] { "", "two thousand" }); Assert.AreEqual("(id:((\"\") OR (\"two thousand\")))", Serialize(q)); }