Ejemplo n.º 1
0
 /// <summary>
 /// 判断不相等
 /// </summary>
 /// <typeparam name="TEntity"></typeparam>
 /// <typeparam name="TValue"></typeparam>
 /// <param name="queries"></param>
 /// <param name="field">要进行判断的字段</param>
 /// <param name="value">要进行判断的值</param>
 /// <returns></returns>
 public static ElasticQuery <TEntity> NotEqual <TEntity, TValue>(this ElasticQuery <TEntity> queries, Expression <Func <TEntity, object> > field, TValue value)
     where TEntity : class
     where TValue : struct
 {
     queries.AddNot(t => t.Term(q => q.Field(field).Value(value)));
     return(queries);
 }
Ejemplo n.º 2
0
        /// <summary>
        ///  创建查询
        /// </summary>
        /// <typeparam name="TEntity"></typeparam>
        /// <param name="client"></param>
        /// <param name="indexName"></param>
        /// <returns></returns>
        public static ElasticQuery <TEntity> Query <TEntity>(this ElasticSearchContext client, string indexName = null) where TEntity : class
        {
            var queries = new ElasticQuery <TEntity>(client);

            if (!string.IsNullOrWhiteSpace(indexName))
            {
                queries.Index(indexName);
            }
            return(queries);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// 判断不包含
 /// </summary>
 /// <typeparam name="TEntity"></typeparam>
 /// <typeparam name="TValue"></typeparam>
 /// <param name="queries"></param>
 /// <param name="paths"></param>
 /// <param name="field"></param>
 /// <param name="values"></param>
 /// <returns></returns>
 public static ElasticQuery <TEntity> NotLike <TEntity, TValue>(this ElasticQuery <TEntity> queries, Expression <Func <TEntity, object> > paths, Expression <Func <TEntity, object> > field, IEnumerable <TValue> values) where TEntity : class
 {
     queries.AddNot(t => t.Nested(n => n.InnerHits(i => i.Explain()).Path(paths).Query(q => q.Terms(f => f.Field(field).Terms(values)))));
     return(queries);
 }
Ejemplo n.º 4
0
 /// <summary>
 /// 判断不包含
 /// </summary>
 /// <typeparam name="TEntity"></typeparam>
 /// <param name="queries"></param>
 /// <param name="field">要进行判断的字段</param>
 /// <param name="value">要进行判断的值</param>
 /// <returns></returns>
 public static ElasticQuery <TEntity> NotLike <TEntity>(this ElasticQuery <TEntity> queries, Expression <Func <TEntity, object> > field, string value) where TEntity : class
 {
     queries.AddNot(t => t.QueryString(q => q.DefaultField(field).Query(value).MinimumShouldMatch(1)));
     return(queries);
 }
Ejemplo n.º 5
0
 /// <summary>
 /// 判断不包含
 /// </summary>
 /// <typeparam name="TEntity"></typeparam>
 /// <param name="queries"></param>
 /// <param name="paths">Nested类型的集合</param>
 /// <param name="field">要进行判断的字段</param>
 /// <param name="value">要进行判断的值</param>
 /// <returns></returns>
 public static ElasticQuery <TEntity> NotLike <TEntity>(this ElasticQuery <TEntity> queries, Expression <Func <TEntity, object> > paths, Expression <Func <TEntity, object> > field, string value) where TEntity : class
 {
     queries.AddNot(t => t.Nested(n => n.Path(paths).Query(q => q.Bool(b => b.Must(m => m.QueryString(qs => qs.DefaultField(field).Query(value)))))));
     return(queries);
 }
Ejemplo n.º 6
0
 /// <summary>
 /// 小于
 /// </summary>
 /// <typeparam name="TEntity"></typeparam>
 /// <typeparam name="TValue"></typeparam>
 /// <param name="queries"></param>
 /// <param name="field">要进行判断的字段</param>
 /// <param name="value">要进行判断的值</param>
 /// <returns></returns>
 public static ElasticQuery <TEntity> LessThan <TEntity>(this ElasticQuery <TEntity> queries, Expression <Func <TEntity, object> > paths, Expression <Func <TEntity, object> > field, long value)
     where TEntity : class
 {
     queries.Add(t => t.Nested(n => n.Path(paths).Query(q => q.Bool(b => b.Must(m => m.Range(r => r.Field(field).LessThan(value)))))));
     return(queries);
 }
Ejemplo n.º 7
0
 /// <summary>
 /// 小于
 /// </summary>
 /// <typeparam name="TEntity"></typeparam>
 /// <typeparam name="TValue"></typeparam>
 /// <param name="queries"></param>
 /// <param name="field">要进行判断的字段</param>
 /// <param name="value">要进行判断的值</param>
 /// <returns></returns>
 public static ElasticQuery <TEntity> LessThan <TEntity>(this ElasticQuery <TEntity> queries, Expression <Func <TEntity, object> > paths, Expression <Func <TEntity, object> > field, DateTime time, string timeZone = "+08:00", DateMathTimeUnit dateMathTimeUnit = DateMathTimeUnit.Day)
     where TEntity : class
 {
     queries.Add(t => t.Nested(n => n.Path(paths).Query(q => q.Bool(b => b.Must(m => m.DateRange(r => r.Field(field).TimeZone(timeZone).LessThan(DateMath.Anchored(time).RoundTo(dateMathTimeUnit))))))));
     return(queries);
 }
Ejemplo n.º 8
0
 /// <summary>
 /// 小于或等于
 /// </summary>
 /// <typeparam name="TEntity"></typeparam>
 /// <typeparam name="TValue"></typeparam>
 /// <param name="queries"></param>
 /// <param name="field">要进行判断的字段</param>
 /// <param name="value">要进行判断的值</param>
 /// <returns></returns>
 public static ElasticQuery <TEntity> LessThan <TEntity>(this ElasticQuery <TEntity> queries, Expression <Func <TEntity, object> > field, long value)
     where TEntity : class
 {
     queries.Add(mu => mu.LongRange(r => r.Field(field).LessThan(value)));
     return(queries);
 }
Ejemplo n.º 9
0
 /// <summary>
 /// 小于
 /// </summary>
 /// <typeparam name="TEntity"></typeparam>
 /// <typeparam name="TValue"></typeparam>
 /// <param name="queries"></param>
 /// <param name="field">要进行判断的字段</param>
 /// <param name="value">要进行判断的值</param>
 /// <returns></returns>
 public static ElasticQuery <TEntity> LessThan <TEntity>(this ElasticQuery <TEntity> queries, Expression <Func <TEntity, object> > field, DateTime time, string timeZone = "+08:00", DateMathTimeUnit dateMathTimeUnit = DateMathTimeUnit.Day)
     where TEntity : class
 {
     queries.Add(mu => mu.DateRange(r => r.Field(field).TimeZone(timeZone).LessThan(DateMath.Anchored(time).RoundTo(dateMathTimeUnit))));
     return(queries);
 }
Ejemplo n.º 10
0
 /// <summary>
 /// 大于
 /// </summary>
 /// <typeparam name="TEntity"></typeparam>
 /// <param name="queries"></param>
 /// <param name="field"></param>
 /// <param name="value"></param>
 /// <returns></returns>
 public static ElasticQuery <TEntity> Than <TEntity>(this ElasticQuery <TEntity> queries, Expression <Func <TEntity, object> > field, double value)
     where TEntity : class
 {
     queries.Add(mu => mu.Range(r => r.Field(field).GreaterThan(value)));
     return(queries);
 }
Ejemplo n.º 11
0
 /// <summary>
 /// 判断相等
 /// </summary>
 /// <typeparam name="TEntity"></typeparam>
 /// <param name="queries"></param>
 /// <param name="field">要进行判断的字段</param>
 /// <param name="value">要进行判断的值</param>
 /// <returns></returns>
 public static ElasticQuery <TEntity> Equal <TEntity>(this ElasticQuery <TEntity> queries, Expression <Func <TEntity, object> > field, string value)
     where TEntity : class
 {
     queries.Add(t => t.QueryString(q => q.DefaultField(field).Query(value)));
     return(queries);
 }