public void Build <T>(QueryBuilderContext <T> ctx) where T : class, new() { var softDeletesQuery = ctx.GetSourceAs <ISoftDeletesQuery>(); if (softDeletesQuery == null || softDeletesQuery.IncludeSoftDeletes) { return; } var idsQuery = ctx.GetSourceAs <IIdentityQuery>(); var opt = ctx.GetOptionsAs <IElasticQueryOptions>(); if (opt == null || !opt.SupportsSoftDeletes || (idsQuery != null && idsQuery.Ids.Count > 0)) { return; } var missingFilter = new MissingFilter { Field = Deleted }; var termFilter = new TermFilter { Field = Deleted, Value = softDeletesQuery.IncludeSoftDeletes }; ctx.Filter &= (new FilterContainer(missingFilter) || new FilterContainer(termFilter)); }
public override void BuildFilter <T>(object query, object options, ref FilterContainer container) { var fieldValuesQuery = query as IFieldConditionsQuery; if (fieldValuesQuery?.FieldConditions == null || fieldValuesQuery.FieldConditions.Count <= 0) { return; } foreach (var fieldValue in fieldValuesQuery.FieldConditions) { switch (fieldValue.Operator) { case ComparisonOperator.Equals: container &= new TermFilter { Field = fieldValue.Field, Value = fieldValue.Value }; break; case ComparisonOperator.NotEquals: container &= new NotFilter { Filter = FilterContainer.From(new TermFilter { Field = fieldValue.Field, Value = fieldValue.Value }) }; break; case ComparisonOperator.IsEmpty: container &= new MissingFilter { Field = fieldValue.Field }; break; case ComparisonOperator.HasValue: container &= new ExistsFilter { Field = fieldValue.Field }; break; } } }