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 results = context.GetQueryable<SearchResultItem>() | |
.Where(x => x.Template.Matches("^.*$")); |
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 queryable = context.GetQueryable<SearchResultItem>(); | |
var fuzzyWithSimilarity = queryable.Where(x => x.Template.Like("Marty McFly", 0.3f)); | |
var fuzzyWithNoSimilatiry = queryable.Where(x => x.Template.Like("Marty McFly")); | |
var fuzzyWithPhrase = queryable.Where(x => x.Template.Like("A martini. Shaken, not stirred.", 10)); |
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()) | |
{ | |
// Create an initial predicate - use .True<T> since we'll be AND'ing this clause together | |
var filterPredicate = PredicateBuilder.True<SearchResultItem>(); | |
// Ensure correct parent | |
filterPredicate = filterPredicate.And(x => x.Parent == ID.Parse("TheParentId")); | |
// Ensure correct path | |
filterPredicate = filterPredicate.And(x => x.Path.Contains("/Path/To/SearchResults")); |
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 results = context.GetQueryable<SearchResultItem>() | |
.Where(...) | |
.Skip(0).Take(20) | |
.GetResults(); | |
var numberOfSearchResults = results.TotalHits; | |
var searchResuls = results.Hits; |
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()) | |
{ | |
// Grab the first 20 search results | |
var results = context.GetQueryable<SearchResultItem>() | |
.Where(...) | |
.Skip(0).Take(20); | |
} |
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 results = context.GetQueryable<SearchResultItem>() | |
.OrderBy(x => x.CreatedDate) | |
.ThenBy(x => x.Content); | |
} | |
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 results = context.GetQueryable<SearchResultItem>() | |
.OrderBy(x => x.CreatedDate); | |
} |
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> | |
<!-- Code omitted... --> | |
<settings> | |
<!-- CONTENT SEARCH SEARCH MAX RESULTS | |
The max number of results that a query returns. | |
If a limit is not specified in the query (ie Take(10)) the search will use this value to set the number of rows returned. | |
It is important, for performance, that only the rows you need for a single request or page of results is returned. | |
--> |
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 sections for indexes --> | |
<indexConfigurations> | |
<defaultSolrIndexConfiguration type="Sitecore.ContentSearch.SolrProvider.SolrIndexConfiguration, Sitecore.ContentSearch.SolrProvider"> | |
<!-- DEFAULT FIELD MAPPING --> | |
<fieldMap type="Sitecore.ContentSearch.SolrProvider.SolrFieldMap, Sitecore.ContentSearch.SolrProvider"> | |
<typeMatches hint="raw:AddTypeMatch"> |
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
namespace Sitecore.ContentSearch.SearchTypes | |
{ | |
public class SearchResultItem : ISearchResult, IObjectIndexers | |
{ | |
[IndexField("_content")] | |
public virtual string Content { get; set; } | |
[IndexField("__smallcreateddate")] | |
public virtual DateTime CreatedDate { get; set; } |