This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/"> | |
<sitecore> | |
<contentSearch> | |
<configuration> | |
<DefaultIndexConfiguration> | |
<fields hint="raw:AddComputedIndexField"> | |
<field fieldName="myCustomComputedIndexField" returnType="string"> | |
<!-- Fully qualified assembly path to the class --> | |
YourAssembly.ComputedFields.MyComputedIndexField,YourAssembly | |
</field> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MyComputedIndexField : IComputedIndexField | |
{ | |
public object ComputeFieldValue(IIndexable indexable) | |
{ | |
// Check that we have something to index | |
if (indexable == null) | |
return null; | |
// Check that it is a Sitecore indexable item | |
var indexableItem = indexable as SitecoreIndexableItem; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using Sitecore.ContentSearch; | |
using Sitecore.ContentSearch.ComputedFields; | |
using Sitecore.ContentSearch.Utilities; | |
using Sitecore.Data; | |
using Sitecore.Data.Items; | |
namespace Examples.ComputedIndexFields | |
{ | |
public class CombinedDateTime : IComputedIndexField |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ISearchIndex index = ContentSearchManager.GetIndex("sitecore_master_index") | |
using (IProviderSearchContext context = index.CreateSearchContext()) | |
{ | |
// Notice that I've swapped out the 'SearchItemResult' with 'MySearchItemResult' | |
// in the method call GetQueryable<T>, and now I'm able to use the property | |
// 'MyTextField' in the filtering | |
var results = context.GetQueryable<MySearchItemResult>() | |
.Where(x => x.MyTextField.Contains("Some value")); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections.Generic; | |
using System.Linq; | |
using Sitecore.ContentSearch; | |
using Sitecore.ContentSearch.ComputedFields; | |
using Sitecore.ContentSearch.Utilities; | |
using Sitecore.Data; | |
using Sitecore.Data.Items; | |
namespace Examples.ComputedIndexFields | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// A custom implementation of the SearchResultItem | |
public class MySearchResultItem : SearchResultItem | |
{ | |
// I've added a new property, that will be mapped to the Solr field named 'mytextfield' | |
[IndexField("mytextfield")] | |
public string MyTextField { get; set; } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using (var context = ContentSearchManager.GetIndex("sitecore_master_index").CreateSearchContext()) | |
{ | |
var facets = new FacetResults(); | |
facets = context.GetQueryable<SearchResultItem>() | |
.FacetOn(x => x.Language) | |
.GetFacets(); | |
foreach (var facetCategories in facets.Categories) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ProductSearcher | |
{ | |
public ProductSearchResult Search(SearchCriteria criteria) | |
{ | |
using (var context = ContentSearchManager.GetIndex("sitecore_master_index").CreateSearchContext()) | |
{ | |
var filterPredicate = PredicateBuilder.True<SearchResultItem>(); | |
// Only take products created over the past year | |
filterPredicate = filterPredicate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Lower and upper dates are still the same as in the previous example | |
var results = context.GetQueryable<SearchResultItem>() | |
.Where(x => x.CreatedDate.Between(lowerDate, upperDate, Inclusion.Both)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var lowerDate = new DateTime(2015, 10, 1); | |
var upperDate = new DateTime(2015, 10, 14); | |
var results = context.GetQueryable<SearchResultItem>() | |
.Where(x => x.CreatedDate >= lowerDate && x.CreatedDate <= upperDate); | |