Skip to content

Instantly share code, notes, and snippets.

@NaibafCH
Last active January 16, 2018 12:24
Show Gist options
  • Save NaibafCH/4c8ac2ca423ccc2ae23ef5645ef267c9 to your computer and use it in GitHub Desktop.
Save NaibafCH/4c8ac2ca423ccc2ae23ef5645ef267c9 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
using Lucene.Net.Search;
using Sitecore.ContentSearch;
using Sitecore.ContentSearch.Linq;
using Sitecore.ContentSearch.Linq.Common;
using Sitecore.ContentSearch.Linq.Lucene;
using Sitecore.ContentSearch.Linq.Methods;
using Sitecore.ContentSearch.Linq.Parsing;
using Sitecore.ContentSearch.LuceneProvider;
namespace Sitecore.ContentSearch.LuceneProvider.Extensions
{
public static class LuceneProviderExtensions
{
public static SearchResults<T> GetResults<T>(this IQueryable<T> queryable, IProviderSearchContext context, Func<Query, Query> searchBehaviour)
{
var extendedQuery = (LuceneQuery)((IHasNativeQuery)queryable).Query;
var methods = new List<QueryMethod> { new GetResultsMethod(GetResultsOptions.Default) };
methods.AddRange(extendedQuery.Methods);
var query = searchBehaviour(extendedQuery.Query);
var newQuery = new LuceneQuery(query, extendedQuery.Filter, methods, extendedQuery.VirtualFieldProcessors,
extendedQuery.FacetQueries, extendedQuery.UsedAnalyzers, extendedQuery.ExecutionContexts);
var linqToLucene = new LinqToLuceneIndex<T>((LuceneSearchContext)context, new IExecutionContext[0]);
return linqToLucene.Execute<SearchResults<T>>(newQuery);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment