Skip to content

Instantly share code, notes, and snippets.

View Program.cs
using Nest;
using System;
using System.Collections.Generic;
using System.Linq;
namespace NestPercolation
{
class Program
{
static void Main(string[] args)
View QueryStringSearchExtension.cs
public static class QueryStringSearchExtensions {
public static IQueriedSearch<TSource, QueryStringQuery> InAnalyzedField<TSource, TExistingQuery>(
this IQueriedSearch<TSource, TExistingQuery> search,
Expression<Func<TSource, string>> fieldSelector,
double? relativeImportance = null)
where TExistingQuery : QueryStringQuery
{
fieldSelector.ValidateNotNullArgument("fieldSelector");
return search.InField(search.Client.Conventions.FieldNameConvention.GetFieldNameForAnalyzed((Expression)fieldSelector), relativeImportance);
@lindstromhenrik
lindstromhenrik / HighlightExtensions.cs
Created Mar 14, 2017
Highlighting all attachment fields
View HighlightExtensions.cs
public static class HighlightExtensions
{
public static IQueriedSearch<TSource, TExistingQuery> WithAttachmentHighlight<TSource, TExistingQuery>(
this IQueriedSearch<TSource, TExistingQuery> search, Action<FieldHighlightRequest> highlightAction = null)
where TExistingQuery : QueryStringQuery
{
return new Search<TSource, TExistingQuery>(search, context =>
{
var fieldName = "*$$attachment";
var request = new FieldHighlightRequest(fieldName);
@lindstromhenrik
lindstromhenrik / NestedFacetExtensions.cs
Created Apr 12, 2016
NestedFacetExtensions. Extensions to the Find nested facets API
View NestedFacetExtensions.cs
public static class NestedFacetExtensions
{
// Allow passing Action<NestedTermsFacetRequest> facetRequestAction (in order to set for example Size on the request)
public static ITypeSearch<TSource> TermsFacetFor<TSource, TListItem>
(this ITypeSearch<TSource> search,Expression<Func<TSource, IEnumerable<TListItem>>> nestedFieldSelector,
Expression<Func<TListItem, string>> itemFieldSelector,
Expression<Func<TListItem, Filter>> filterExpression = null,
Action<NestedTermsFacetRequest> facetRequestAction = null)
{
var facetFilter = NestedFilter.Create(search.Client.Conventions, nestedFieldSelector, filterExpression);
@lindstromhenrik
lindstromhenrik / gist:30391262cf166a07f451
Last active Nov 15, 2018
NestedTermsFacetExtensions for EPiServer Find
View gist:30391262cf166a07f451
public static class NestedTermsFacetExtensions
{
public static ITypeSearch<TSource> NestedTermsFacetFor<TSource, TEnumerable>(
this ITypeSearch<TSource> search,
Expression<Func<TSource, IEnumerable<TEnumerable>>> enumerableFieldSelector, Expression<Func<TEnumerable, string>> itemFieldSelector)
{
return search.AddNestedTermsFacetFor(enumerableFieldSelector, itemFieldSelector, null);
}
public static ITypeSearch<TSource> NestedTermsFacetFor<TSource, TEnumerable>(
@lindstromhenrik
lindstromhenrik / gist:9779858
Last active Dec 2, 2016
ThenByScore-extension for EPiServer Find
View gist:9779858
public static ITypeSearch<TSource> ThenByScore<TSource>(this ITypeSearch<TSource> search)
{
return new Search<TSource, IQuery>(search, context =>
context.RequestBody.Sort.Add(new Sorting("_score")));
}
@lindstromhenrik
lindstromhenrik / gist:8647566
Created Jan 27, 2014
Custom tags tracking using EPiServer Find CMS 6 R2
View gist:8647566
// At query time add appropriate tags
using EPiServer.Find.Framework.Statistics;
client.Search<>()
...
.Track(new string[] { "mytag" })
.GetResults()
// When fetching autocomplete/didyoumean/spellcheck through the REST endpoint
@lindstromhenrik
lindstromhenrik / gist:6699210
Last active Dec 23, 2015
List indices (docs/size)
View gist:6699210
$.ajax
({
type: "GET",
url: "https://server/_status",
dataType: 'jsonp'
}).done(function(data) {
for(indexName in data.indices)
{
$('#indices').append('<div><span>' + indexName + '</span>&nbsp;<span>' + data.indices[indexName].docs.num_docs + '</span>&nbsp;<span>' + data.indices[indexName].index.primary_size +'</span></div>');
}
@lindstromhenrik
lindstromhenrik / gist:5451390
Created Apr 24, 2013
Extension for using FilterHits with BuildFilter()
View gist:5451390
public static ITypeSearch<TSource> FilterHits<TSource>(this ITypeSearch<TSource> search, Filter filter)
{
return new Search<TSource, IQuery>(search, context =>
{
var filterToAdd = filter;
if (context.RequestBody.Filter.IsNotNull())
{
filterToAdd = filter & context.RequestBody.Filter;
}
context.RequestBody.Filter = filterToAdd;
@lindstromhenrik
lindstromhenrik / TermsFacetExtensions.cs
Last active Dec 12, 2015
TermsFacetFor<> - properties of objects in IEnumerables
View TermsFacetExtensions.cs
public static class TermsFacetExtensions
{
public static ITypeSearch<TSource> TermsFacetFor<TSource, TListItem>(this ITypeSearch<TSource> search, Expression<Func<TSource, IEnumerable<TListItem>>> fieldListSelector, Expression<Func<TListItem, object>> fieldListItemSelector)
{
fieldListSelector.ValidateNotNullArgument("fieldListSelector");
fieldListItemSelector.ValidateNotNullArgument("fieldListItemSelector");
var facetName = fieldListSelector.GetFieldPath() + "." + fieldListItemSelector.GetFieldPath();
var fieldName = search.Client.Conventions.FieldNameConvention.GetFieldName(fieldListSelector) + "." + search.Client.Conventions.FieldNameConvention.GetFieldName(fieldListItemSelector);
You can’t perform that action at this time.