public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { var j = JObject.Load(reader); if (j == null || !j.HasValues) return null; IPrefixFilter filter = new PrefixFilter(); foreach (var jv in j) { switch (jv.Key) { case "_cache": filter.Cache = jv.Value.Value<bool?>(); break; case "_cacheKey": case "_cache_key": filter.CacheKey = jv.Value.Value<string>(); break; case "_name": filter.FilterName = jv.Value.Value<string>(); break; default: var field = jv.Key; filter.Field = field; filter.Prefix = jv.Value.Value<string>(); break; } } return filter; }
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { var j = JObject.Load(reader); if (j == null || !j.HasValues) { return(null); } IPrefixFilter filter = new PrefixFilter(); foreach (var jv in j) { switch (jv.Key) { case "_cache": filter.Cache = jv.Value.Value <bool?>(); break; case "_cacheKey": case "_cache_key": filter.CacheKey = jv.Value.Value <string>(); break; case "_name": filter.FilterName = jv.Value.Value <string>(); break; default: var field = jv.Key; filter.Field = field; filter.Prefix = jv.Value.Value <string>(); break; } } return(filter); }
/// <summary> /// Creates the query. /// </summary> /// <param name="field">The field.</param> /// <param name="value">The value.</param> /// <returns></returns> public static Filter CreateQuery(string field, CategoryFilterValue value) { var query = new BooleanFilter(); if (!String.IsNullOrEmpty(value.Outline)) { // workaround since there is no wildcard filter in current lucene version var outline = value.Outline.TrimEnd('*'); var nodeQuery = new PrefixFilter(new Term(field, outline.ToLower())); query.Add(new FilterClause(nodeQuery, Occur.MUST)); } return query; }
public void PrefixFilter_KeyNotSet_Validation_Fails() { var filter = new PrefixFilter(); Assert.Throws <FilterException>(() => filter.ToFilterBuild().Validate()); }