Presentation is loading. Please wait.

Presentation is loading. Please wait.

Zoeken met Sitecore 7 Egbert Wietses pionect.nl. Waar komen we vandaan? _Buckets.aspx.

Similar presentations


Presentation on theme: "Zoeken met Sitecore 7 Egbert Wietses pionect.nl. Waar komen we vandaan? _Buckets.aspx."— Presentation transcript:

1 Zoeken met Sitecore 7 Egbert Wietses pionect.nl

2 Waar komen we vandaan? _Buckets.aspx

3 Item buckets Niet zichtbaar (standaard) Theoretisch ongelimiteerd aantal subitems Geen parent child relatie

4 Handig om te weten Luke = your friend https://code.google.com/p/luke/ https://code.google.com/p/luke/

5 Zoeken using (var context = ContentSearchManager.GetIndex(bucketItem as IIndexable).CreateSearchContext()) { var querySearch = context.GetQueryable (); querySearch = querySearch.Where(item => item._language.Equals("en")); querySearch = querySearch.Where(item => item._templatename.Equals(MasterProductPage.TEMPLATE_NAME)); querySearch = querySearch.Where(item => item.brand.Equals("TRUST")); var products = querySearch.ToList(); } public class Product : SearchResultItem { public string _group { get; set; } public string _name { get; set; } public string _language { get; set; } public string _templatename { get; set; } public string color { get; set; } public string device { get; set; } public string feature { get; set; } public string operatingSystem { get; set; } public string compatibility { get; set; } }

6 Facet Search

7 Coveo

8 Linq to Sitecore = gold All Any Between — with an extra overload for including or excluding the start and end ranges. Boost — makes this part of the query more important than the other parts. Cast — you can use this instead of Select. Contains Count ElementAt EndsWith Equal Facets — an extension that fetches the facets of predicates. First FirstOrDefault Last LastOrDefault Min Max Match — an extension for running regular expression queries. OrderBy OrderByDescending Select Single SingleOrDefault Skip Reverse Take ToList() ToLookUp() ToDictionary() Page — an extension that does Skip and Take automatically for you. StartsWith Union

9 Facet implementatie public static IQueryable GetFacets(IQueryable query, string[] facets) { var facetGroups = new List (); query = facets.Aggregate(query, (current, facetName) => current.FacetOn(c => c[facetName])); FacetResults facetResults = query.GetFacets(); foreach (FacetCategory category in facetResults.Categories) { var group = new Facet(key, friendlyName); foreach (Sitecore.ContentSearch.Linq.FacetValue facetValue in category.Values) { group.Values.Add(new Models.FacetValue(facetValue.Name, facetValue.Aggregate)); } facetGroups.Add(group); } return facetGroups.AsQueryable(); }

10 Verschillende queries, verschillende taken

11 1 Call using (var context = ContentSearchManager.GetIndex("sitecore_master_index").CreateSearchContext()) { var results = context.GetQueryable ().Where(prod => prod.Content.Contains("search box text").FacetOn(f => f.Color).FacetOn(f => f.Gender)).GetResults(); int totalHits = results.TotalHits; var searchResuls = results.Hits; var facets = results.Facets; }

12 namespace Sitecore.ContentSearch.Linq { public static class QueryableExtensions { public static IQueryable FacetOn (this IQueryable source, Expression > keySelector); public static IQueryable FacetOn (this IQueryable source, Expression > keySelector, int minimumResultCount); public static IQueryable FacetOn (this IQueryable source, Expression > keySelector, int minimumResultCount, IEnumerable filterValues); public static IQueryable FacetPivotOn (this IQueryable source, Expression, FacetPivotQuery >> keySelector); public static IQueryable FacetPivotOn (this IQueryable source, Expression, FacetPivotQuery >> keySelector, int minimumResultCount); public static IQueryable Filter (this IQueryable source, Expression > predicate); public static FacetResults GetFacets (this IQueryable source); public static SearchResults GetResults (this IQueryable source); public static SearchResults GetResults (this IQueryable source, GetResultsOptions options); public static IQueryable Page (this IQueryable source, int page, int pageSize); }

13 Linq voorbeeld resultsQuery = resultsQuery.Where(item => item.Path.StartsWith("/sitecore/content/sites/autohouse") && !item.ExcludeFromSearchResults && (item.TemplateName == ContentPage.TEMPLATE_NAME || item.TemplateName == NewsDetailPage.TEMPLATE_NAME || (item.TemplateName == MasterProductPage.TEMPLATE_NAME && item.brand.Equals("Brand X") && (item.useforsupport.Equals("1") || item.useforconsumerassortment.Equals("1"))) || (item.TemplateName == ColorProductPage.TEMPLATE_NAME && item.brand.Equals("Brand X") && (item.useforsupport.Equals("1") || item.useforconsumerassortment.Equals("1"))) ) && item.Language.StartsWith(lang)).OrderByDescending(x => x.itemno);

14 Predicate Builder = one to watch OR AND XOR Controleren tegen lijst van iD’s

15 In de praktijk Luke = your friend

16 Achtergrond informatie Sitecore 7 Autohaus project https://github.com/Sitecore/autohaus https://github.com/Sitecore/autohaus Developers guide to item buckets and search https://sdn.sitecore.net/Reference/Sitecore%207/ Developers%20Guide%20to%20Item%20Bucket s%20and%20Search.aspx https://sdn.sitecore.net/Reference/Sitecore%207/ Developers%20Guide%20to%20Item%20Bucket s%20and%20Search.aspx


Download ppt "Zoeken met Sitecore 7 Egbert Wietses pionect.nl. Waar komen we vandaan? _Buckets.aspx."

Similar presentations


Ads by Google