Download presentation
Presentation is loading. Please wait.
Published byJadyn Archer Modified over 10 years ago
1
Zoeken met Sitecore 7 Egbert Wietses pionect.nl
2
Waar komen we vandaan?
3
Item buckets Niet zichtbaar (standaard)
Theoretisch ongelimiteerd aantal subitems Geen parent child relatie
4
Handig om te weten <setting name="BucketConfiguration.BucketFolderPath" value=„yyyy\/MM\/dd\/HH\/mm”/> <field fieldName="group" storageType="YES" indexType="TOKENIZED" vectorType="NO" boost="1f" type="System.GUID" settingType="Sitecore.ContentSearch.LuceneProvider.LuceneSearchFieldConfiguration, Sitecore.ContentSearch.LuceneProvider”> Luke = your friend
5
Zoeken using (var context = ContentSearchManager.GetIndex(bucketItem as IIndexable).CreateSearchContext()) { var querySearch = context.GetQueryable<Models.Product>(); 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<Facet> GetFacets(IQueryable<Product> query, string[] facets) { var facetGroups = new List<Facet>(); 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<Product>().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<TSource> FacetOn<TSource, TKey>(this IQueryable<TSource> source, Expression<Func<TSource, TKey>> keySelector); public static IQueryable<TSource> FacetOn<TSource, TKey>(this IQueryable<TSource> source, Expression<Func<TSource, TKey>> keySelector, int minimumResultCount); public static IQueryable<TSource> FacetOn<TSource, TKey>(this IQueryable<TSource> source, Expression<Func<TSource, TKey>> keySelector, int minimumResultCount, IEnumerable<object> filterValues); public static IQueryable<TSource> FacetPivotOn<TSource>(this IQueryable<TSource> source, Expression<Func<FacetPivotQuery<TSource>, FacetPivotQuery<TSource>>> keySelector); public static IQueryable<TSource> FacetPivotOn<TSource>(this IQueryable<TSource> source, Expression<Func<FacetPivotQuery<TSource>, FacetPivotQuery<TSource>>> keySelector, int minimumResultCount); public static IQueryable<TSource> Filter<TSource>(this IQueryable<TSource> source, Expression<Func<TSource, bool>> predicate); public static FacetResults GetFacets<TSource>(this IQueryable<TSource> source); public static SearchResults<TSource> GetResults<TSource>(this IQueryable<TSource> source); public static SearchResults<TSource> GetResults<TSource>(this IQueryable<TSource> source, GetResultsOptions options); public static IQueryable<TSource> Page<TSource>(this IQueryable<TSource> 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.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 Developers guide to item buckets and search Developers%20Guide%20to%20Item%20Bucket s%20and%20Search.aspx
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.