<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using Newtonsoft.Json;
using System.Linq.Expressions;
using System.Globalization;

namespace Nest
{
	public class FilterDescriptor<T> : FilterContainer
		where T : class
	{
		internal IFilterContainer Self { get { return this; } }

		public FilterDescriptor<T> Name(string name)
		{
			Self.FilterName = name;
			return this;
		}
		public FilterDescriptor<T> CacheKey(string cacheKey)
		{
			Self.CacheKey = cacheKey;
			return this;
		}
		public FilterDescriptor<T> Cache(bool cache)
		{
			Self.Cache = cache;
			return this;
		}
		

		public FilterDescriptor<T> Strict(bool strict = true)
		{
			var f = new FilterDescriptor<T>();
			f.Self.IsStrict = strict;
			f.Self.IsVerbatim = Self.IsVerbatim;
			return f;
		}

		public FilterDescriptor<T> Verbatim(bool verbatim = true)
		{
			var f = new FilterDescriptor<T>();
			f.Self.IsStrict = Self.IsStrict;
			f.Self.IsVerbatim = verbatim;
			return f;
		}

		/// <summary>
		/// A thin wrapper allowing fined grained control what should happen if a filter is conditionless
		/// if you need to fallback to something other than a match_all query
		/// </summary>
		public FilterContainer Conditionless(Action<ConditionlessFilterDescriptor<T>> selector)
		{
			var filter = new ConditionlessFilterDescriptor<T>();
			selector(filter);

			return (filter.FilterDescriptor == null || filter.FilterDescriptor.IsConditionless) ? filter._Fallback : filter.FilterDescriptor;
		}

		internal FilterContainer Raw(string rawJson)
		{
			var f = new FilterDescriptor<T>();
			f.Self.IsStrict = Self.IsStrict;
			f.Self.IsVerbatim = Self.IsVerbatim;
			f.Self.RawFilter = rawJson;
			return f;
		}

		/// <summary>
		/// Filters documents where a specific field has a value in them.
		/// </summary>
		public FilterContainer Exists(Expression<Func<T, object>> fieldDescriptor)
		{
			IExistsFilter filter = new ExistsFilterDescriptor();
			filter.Field = fieldDescriptor;
			this.SetCacheAndName(filter);
			return this.New(filter, f => f.Exists = filter);<commit_msg>Fixes #999 by making Raw public (instead of internal and similar to QueryDescriptor)<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using Newtonsoft.Json;
using System.Linq.Expressions;
using System.Globalization;

namespace Nest
{
	public class FilterDescriptor<T> : FilterContainer
		where T : class
	{
		internal IFilterContainer Self { get { return this; } }

		public FilterDescriptor<T> Name(string name)
		{
			Self.FilterName = name;
			return this;
		}
		public FilterDescriptor<T> CacheKey(string cacheKey)
		{
			Self.CacheKey = cacheKey;
			return this;
		}
		public FilterDescriptor<T> Cache(bool cache)
		{
			Self.Cache = cache;
			return this;
		}
		

		public FilterDescriptor<T> Strict(bool strict = true)
		{
			var f = new FilterDescriptor<T>();
			f.Self.IsStrict = strict;
			f.Self.IsVerbatim = Self.IsVerbatim;
			return f;
		}

		public FilterDescriptor<T> Verbatim(bool verbatim = true)
		{
			var f = new FilterDescriptor<T>();
			f.Self.IsStrict = Self.IsStrict;
			f.Self.IsVerbatim = verbatim;
			return f;
		}

		/// <summary>
		/// A thin wrapper allowing fined grained control what should happen if a filter is conditionless
		/// if you need to fallback to something other than a match_all query
		/// </summary>
		public FilterContainer Conditionless(Action<ConditionlessFilterDescriptor<T>> selector)
		{
			var filter = new ConditionlessFilterDescriptor<T>();
			selector(filter);

			return (filter.FilterDescriptor == null || filter.FilterDescriptor.IsConditionless) ? filter._Fallback : filter.FilterDescriptor;
		}

		public FilterContainer Raw(string rawJson)
		{
			var f = new FilterDescriptor<T>();
			f.Self.IsStrict = Self.IsStrict;
			f.Self.IsVerbatim = Self.IsVerbatim;
			f.Self.RawFilter = rawJson;
			return f;
		}

		/// <summary>
		/// Filters documents where a specific field has a value in them.
		/// </summary>
		public FilterContainer Exists(Expression<Func<T, object>> fieldDescriptor)
		{
			IExistsFilter filter = new ExistsFilterDescriptor();
			filter.Field = fieldDescriptor;
			this.SetCacheAndName(filter);
			return this.New(filter, f => f.Exists = filter);
{'fraction_non_alphanumeric': 0.10421077393554458, 'fraction_numerical': 0.0007057163020465773, 'mean_word_length': 3.761478163493841, 'pattern_counts': {'":': 0, '<': 39, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6425264', 'n_tokens_mistral': 1485, 'n_tokens_neox': 1278, 'n_words': 353}