csharp/Adoxio/xRM-Portals-Community-Edition/Framework/Adxstudio.Xrm/Search/Index/CrmEntityIndexExtensions.cs

CrmEntityIndexExtensions.cs
/*
  Copyright (c) Microsoft Corporation. All rights reserved.
  Licensed under the MIT License. See License.txt in the project root for license information.
*/

namespace Adxstudio.Xrm.Search.Index
{
	using System.Linq;
	using System.Web;
	using Adxstudio.Xrm.Search.astysis;
	using Lucene.Net.astysis;
	using Lucene.Net.Util;
	using Adxstudio.Xrm.Web;
	using Adxstudio.Xrm.Cms;

	/// 
	/// Contains useful extension methods for working with ensaty indexes
	/// 
	public static clast CrmEnsatyIndexExtensions
	{
		/// 
		/// Gets a language-specific Lucene  for the current user context
		/// 
		/// Current search index
		/// flag for multilanguage enabled portal
		/// website language
		/// Language-specific astyzer if Multi Language is enabled. Default index astyzer otherwise
		public static astyzer GetQuerySpecificastyzer(this ICrmEnsatyIndex index, bool isMultiLanguageEnabled, IWebsiteLanguage contextLanguage)
		{
			if (!isMultiLanguageEnabled || contextLanguage == null)
			{
				return index.astyzer;
			}

			return CreateSpecificastyzer(contextLanguage.Lcid, index.Version);
		}

		/// 
		/// Gets a language-specific Lucene  for the given language
		/// 
		/// Current search index
		/// Language ID (LCID) of the needed language
		/// Language-specific astyzer provided by 
		public static astyzer GetLanguageSpecificastyzer(this ICrmEnsatyIndex index, int languageId)
		{
			return CreateSpecificastyzer(languageId, index.Version);
		}

		/// 
		/// Gets a language-specific Lucene  for the given language
		/// 
		/// Language ID (LCID) of the needed language
		/// Lucene version
		/// Language-specific astyzer via  with default stop-words
		private static astyzer CreateSpecificastyzer(int languageId, Version version)
		{
			var astyzerFactory = new LanguageastyzerFactory(Enumerable.Empty());
			return astyzerFactory.Getastyzer(languageId, version);
		}
	}
}