mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +08:00
Added a filter for projections over StringFields (#8213)
This commit is contained in:
committed by
Sébastien Ros
parent
cfa335a8cf
commit
4eba79c66e
@@ -49,6 +49,10 @@ namespace Orchard.Projections.FilterEditors.Forms {
|
||||
f._Operator.Add(new SelectListItem { Value = Convert.ToString(StringOperator.Ends), Text = T("Ends with").Text });
|
||||
f._Operator.Add(new SelectListItem { Value = Convert.ToString(StringOperator.NotEnds), Text = T("Does not end with").Text });
|
||||
f._Operator.Add(new SelectListItem { Value = Convert.ToString(StringOperator.NotContains), Text = T("Does not contain").Text });
|
||||
f._Operator.Add(new SelectListItem {
|
||||
Value = Convert.ToString(StringOperator.ContainsAnyIfProvided),
|
||||
Text = T("Contains any word (if any is provided)").Text
|
||||
});
|
||||
|
||||
return f;
|
||||
};
|
||||
@@ -88,6 +92,14 @@ namespace Orchard.Projections.FilterEditors.Forms {
|
||||
return y => y.Not(x => x.Like(property, Convert.ToString(value), HqlMatchMode.End));
|
||||
case StringOperator.NotContains:
|
||||
return y => y.Not(x => x.Like(property, Convert.ToString(value), HqlMatchMode.Anywhere));
|
||||
case StringOperator.ContainsAnyIfProvided:
|
||||
if (string.IsNullOrWhiteSpace((string)value))
|
||||
return x => x.IsNotEmpty("Id"); // basically, return every possible ContentItem
|
||||
var values3 = Convert.ToString(value)
|
||||
.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
var predicates3 = values3.Skip(1)
|
||||
.Select<string, Action<IHqlExpressionFactory>>(x => y => y.Like(property, x, HqlMatchMode.Anywhere)).ToArray();
|
||||
return x => x.Disjunction(y => y.Like(property, values3[0], HqlMatchMode.Anywhere), predicates3);
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
@@ -118,6 +130,11 @@ namespace Orchard.Projections.FilterEditors.Forms {
|
||||
return T("{0} does not end with '{1}'", fieldName, value);
|
||||
case StringOperator.NotContains:
|
||||
return T("{0} does not contain '{1}'", fieldName, value);
|
||||
case StringOperator.ContainsAnyIfProvided:
|
||||
return T("{0} contains any of '{1}' (or '{1}' is empty)",
|
||||
fieldName,
|
||||
new LocalizedString(string.Join("', '",
|
||||
value.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries))));
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
@@ -135,5 +152,6 @@ namespace Orchard.Projections.FilterEditors.Forms {
|
||||
Ends,
|
||||
NotEnds,
|
||||
NotContains,
|
||||
ContainsAnyIfProvided
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user