当前位置: 首页>>代码示例>>C#>>正文


C# BooleanQuery.Clauses方法代码示例

本文整理汇总了C#中Lucene.Net.Search.BooleanQuery.Clauses方法的典型用法代码示例。如果您正苦于以下问题:C# BooleanQuery.Clauses方法的具体用法?C# BooleanQuery.Clauses怎么用?C# BooleanQuery.Clauses使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Lucene.Net.Search.BooleanQuery的用法示例。


在下文中一共展示了BooleanQuery.Clauses方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Search

        public LogQueryResults Search(LogQuery query)
        {
            if (query.DateTime_From == DateTime.MinValue || query.DateTime_To == DateTime.MinValue)
            {
                throw new ArgumentException("DateTime_From or DateTime_To Not Set");
            }
            var qryHeader = new BooleanQuery();

            if (!string.IsNullOrWhiteSpace(query.Text))
            {
                var textBooleanQuery = new BooleanQuery();
                for (int i = 0; i < textQueryFields.Length; i++)
                {
                    var termQry = new TermQuery(new Term(textQueryFields[i], query.Text));
                    textBooleanQuery.Add(termQry, BooleanClause.Occur.SHOULD);
                }
                qryHeader.Add(textBooleanQuery, BooleanClause.Occur.MUST);
            }

            if (query.ClientIP != null)
            {
                var ipStr = NAppIndexUpdater.ConvertIPToString(query.ClientIP);
                var termQry = new TermQuery(new Term(FieldKeys.ClientIP, ipStr));
                qryHeader.Add(termQry, BooleanClause.Occur.MUST);
            }

            if (query.ServerIP != null)
            {
                var ipStr = NAppIndexUpdater.ConvertIPToString(query.ServerIP);
                var termQry = new TermQuery(new Term(FieldKeys.ServerIP, ipStr));
                qryHeader.Add(termQry, BooleanClause.Occur.MUST);
            }

            if (query.ShowExceptions == LogQueryExceptions.ExceptionsOnly)
            {
                var termQry = new TermQuery(new Term(FieldKeys.Exception, "1"));
                qryHeader.Add(termQry, BooleanClause.Occur.MUST);
            }
            else if (query.ShowExceptions == LogQueryExceptions.SuccessesOnly)
            {
                var termQry = new TermQuery(new Term(FieldKeys.Exception, "1"));
                qryHeader.Add(termQry, BooleanClause.Occur.MUST);
            }

            var elapsedQuery = AddFromToQueryString(FieldKeys.Elapsed, query.TotalElapsed_From.Ticks, query.TotalElapsed_To.Ticks, TimeSpan.Zero.Ticks);
            if (elapsedQuery != null)
            {
                qryHeader.Add(elapsedQuery, BooleanClause.Occur.MUST);
            }

            var dtlQry = AddFromToQueryString(FieldKeys.Detail_Elapsed, query.DetailElapsed_From.Ticks, query.DetailElapsed_To.Ticks, TimeSpan.Zero.Ticks);
            if (dtlQry != null)
            {
                qryHeader.Add(dtlQry, BooleanClause.Occur.MUST);
            }

            var ret = new LogQueryResults()
            {
                DateTime_From = query.DateTime_From,
                DateTime_To = query.DateTime_To,
            };
            if (qryHeader.Clauses().Count > 0)
            {
                ret.LogIDs = new List<LogQueryResultDetail>();
                GetLogIDsFromMain(qryHeader, ret.DateTime_From, ret.DateTime_To, ret.LogIDs);
            }
            return ret;
        }
开发者ID:simonkang,项目名称:NAppProfiler,代码行数:68,代码来源:NAppIndexReader.cs

示例2: And

		/// <summary>
		/// 构造一个And条件语句
		/// </summary>
		/// <param name="expl">左边条件表达式</param>
		/// <param name="expr">右边条件表达式</param>
		/// <returns>条件语句</returns>
		public static Conditional And(ExpressionEx expl, ExpressionEx expr)
		{
			var conditional = new Conditional();

			var booleanQuery = new BooleanQuery();

			Query ql = Convert(expl);
			if (ql is BooleanQuery)
			{
				foreach (object variable in ((BooleanQuery)ql).Clauses())
				{
					booleanQuery.Clauses().Add(variable);
				}
			}
			else
			{
				booleanQuery.Add(ql, BooleanClause.Occur.MUST);
			}

			Query qr = Convert(expr);
			if (qr is BooleanQuery)
			{
				foreach (object variable in ((BooleanQuery)qr).Clauses())
				{
					booleanQuery.Clauses().Add(variable);
				}
			}
			else
			{
				booleanQuery.Add(qr, BooleanClause.Occur.MUST);
			}

			conditional._queryExpression = booleanQuery;

			return conditional;
		}
开发者ID:starckgates,项目名称:ElasticSearch.Net,代码行数:42,代码来源:Conditional.cs

示例3: GenreQueryFilter


//.........这里部分代码省略.........

            var genreQueryFilter = new QueryFilter(query);
            if (!isFacet)
            {
                if (termName == "_language" || isIdLookup)
                {
                    var termValueParse = terms.Split('|')[0].ToLowerInvariant();
                    if (isIdLookup)
                    {
                        termValueParse = IdHelper.NormalizeGuid(termValueParse, true);
                    }
                    genreQueryFilter =
                        new QueryFilter(
                            new TermQuery(new Term(termName.ToLowerInvariant(), termValueParse)));
                }
                else if (termName == "size" || termName == "dimensions")
                {
                    var term = new BooleanQuery();
                    term.Add(new TermQuery(new Term(termName, terms)), BooleanClause.Occur.MUST);
                    genreQueryFilter = new QueryFilter(term);
                }
                else
                {
                    genreQueryFilter =
                        new QueryFilter(
                            new TermQuery(new Term(terms.Split('|')[0].ToLowerInvariant(),
                                                   termName.ToLowerInvariant())));
                }
            }
            else
            {
                if (termName == "__created by")
                {
                    genreQueryFilter =
                        new QueryFilter(new TermQuery(new Term(termName, tempTerms)));
                }
                else
                {
                    if (Config.ExcludeContextItemFromResult)
                    {
                        if (termName == "_path")
                        {
                            var term = new BooleanQuery();
                            term.Add(new TermQuery(new Term(termName, tempTerms.ToLowerInvariant())), BooleanClause.Occur.MUST);
                            term.Add(new TermQuery(new Term(BuiltinFields.ID, tempTerms.ToLowerInvariant())),
                                     BooleanClause.Occur.MUST_NOT);
                            genreQueryFilter = new QueryFilter(term);
                        }
                        else
                        {
                            var term = new TermQuery(new Term(termName, tempTerms.ToLowerInvariant()));
                            genreQueryFilter = new QueryFilter(term);
                        }
                    }
                    else
                    {
                        var term = new TermQuery(new Term(termName, tempTerms.ToLowerInvariant()));
                        genreQueryFilter = new QueryFilter(term);
                    }
                }
            }
            if (termName == "__smallCreatedDate")
            {
                var dateStart = terms.Split('|')[0];
                var typeOfDate = terms.Split('|')[1];
                var dateEnd = new DateTime();
                if (typeOfDate == "Within a Day")
                {
                    dateEnd = DateTime.Now;
                }
                if (typeOfDate == "Within a Week")
                {
                    dateEnd = DateTime.Now.AddDays(-1);
                }
                if (typeOfDate == "Within a Month")
                {
                    dateEnd = DateTime.Now.AddDays(-7);
                }
                if (typeOfDate == "Within a Year")
                {
                    dateEnd = DateTime.Now.AddMonths(-1);
                }
                if (typeOfDate == "Older")
                {
                    dateEnd = DateTime.Now.AddYears(-1);
                }

                var boolQuery = new BooleanQuery(true);
                SearcherMethods.AddDateRangeQuery(boolQuery,
                                                  new DateRangeSearchParam.DateRangeField(termName, DateTime.Parse(dateStart),
                                                                                          dateEnd)
                                                      {InclusiveEnd = true, InclusiveStart = true}, BooleanClause.Occur.MUST);
                genreQueryFilter = new QueryFilter(boolQuery);
                if (Config.EnableBucketDebug || Constants.EnableTemporaryBucketDebug)
                {
                    Log.Info("Search Clauses Number: " + boolQuery.Clauses().Count, this);
                }
            }
            return genreQueryFilter;
        }
开发者ID:mnak,项目名称:Sitecore-Item-Buckets,代码行数:101,代码来源:Searcher.cs

示例4: RandBoolQuery

		// Random rnd is passed in so that the exact same random query may be created
		// more than once.
		public static BooleanQuery RandBoolQuery(System.Random rnd, int level, System.String field, System.String[] vals, TestBoolean2.Callback cb)
		{
			BooleanQuery current = new BooleanQuery(rnd.Next() < 0);
			for (int i = 0; i < rnd.Next(vals.Length) + 1; i++)
			{
				int qType = 0; // term query
				if (level > 0)
				{
					qType = rnd.Next(10);
				}
				Query q;
				if (qType < 7)
					q = new TermQuery(new Term(field, vals[rnd.Next(vals.Length)]));
				else
					q = RandBoolQuery(rnd, level - 1, field, vals, cb);
				
				int r = rnd.Next(10);
				BooleanClause.Occur occur;
				if (r < 2)
					occur = BooleanClause.Occur.MUST_NOT;
				else if (r < 5)
					occur = BooleanClause.Occur.MUST;
				else
					occur = BooleanClause.Occur.SHOULD;
				
				current.Add(q, occur);
			}
			if (cb != null)
				cb.PostCreate(current);
			((System.Collections.ArrayList)current.Clauses()).TrimToSize();
			return current;
		}
开发者ID:vikasraz,项目名称:indexsearchutils,代码行数:34,代码来源:TestBoolean2.cs


注:本文中的Lucene.Net.Search.BooleanQuery.Clauses方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。