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


C# BooleanQuery.GetClauses方法代码示例

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


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

示例1: VisitBooleanQuery

 protected virtual BooleanQuery VisitBooleanQuery(BooleanQuery b)
 {
     var qry = new BooleanQuery(b.IsCoordDisabled());
     foreach (var c in b.GetClauses())
     {
         qry.Add(new BooleanClause(VisitQuery(c.Query), c.Occur));
     }
     return qry;
 }
开发者ID:daszat,项目名称:zetbox,代码行数:9,代码来源:QueryTranslator.cs

示例2: PostCreate

			public virtual void  PostCreate(BooleanQuery q)
			{
				BooleanClause[] c = q.GetClauses();
				int opt = 0;
				for (int i = 0; i < c.Length; i++)
				{
					if (c[i].Occur == Occur.SHOULD)
						opt++;
				}
				q.MinimumNumberShouldMatch = rnd.Next(opt + 2);
			}
开发者ID:synhershko,项目名称:lucene.net,代码行数:11,代码来源:TestBooleanMinShouldMatch.cs

示例3: VisitBooleanQuery

        public virtual Query VisitBooleanQuery(BooleanQuery booleanq)
        {
            var clauses = booleanq.GetClauses();
            var visitedClauses = VisitBooleanClauses(clauses);
            BooleanQuery newQuery = null;
            if (visitedClauses != clauses)
            {
                newQuery = new BooleanQuery(booleanq.IsCoordDisabled());
                for (int i = 0; i < visitedClauses.Length; i++)
                    newQuery.Add(visitedClauses[i]);
            }
            return newQuery ?? booleanq;

        }
开发者ID:jhuntsman,项目名称:FlexNet,代码行数:14,代码来源:LucQueryVisitor.cs

示例4: VisitBooleanQuery

 public override Query VisitBooleanQuery(BooleanQuery booleanq)
 {
     _dump.Append("BoolQ(");
     var clauses = booleanq.GetClauses();
     var visitedClauses = VisitBooleanClauses(clauses);
     BooleanQuery newQuery = null;
     if (visitedClauses != clauses)
     {
         newQuery = new BooleanQuery(booleanq.IsCoordDisabled());
         for (int i = 0; i < visitedClauses.Length; i++)
             newQuery.Add(clauses[i]);
     }
     _dump.Append(")");
     return newQuery ?? booleanq;
 }
开发者ID:jhuntsman,项目名称:FlexNet,代码行数:15,代码来源:DumpVisitor.cs

示例5: Part_GysSelect_pagechange

        public ActionResult Part_GysSelect_pagechange(int? page)
        {
            if (-1 != HttpContext.检查登录())
            {
                ViewData["已登录"] = "1";
            }
            else
            {
                ViewData["已登录"] = "0";
            }

            TopDocs serchalllist = null;

            PanGu.Segment.Init(PanGuXmlPath);

            string provence = Request.Params["provence"];//所在省份
            string city = Request.Params["city"];//所在城市
            string area = Request.Params["area"];//所在区县
            string industry = Request.Params["industry"];//所属行业
            string comname = Request.Params["comname"];//企业名称

            if (provence == "不限省份" && industry == "请选择行业" && string.IsNullOrEmpty(comname))
            {
                return Content("0");
            }

            try
            {
                BooleanQuery bQuery = new BooleanQuery();
                if (provence != "不限省份")
                {
                    //Lucene.Net.Search.Query query = new QueryParser("Province", PanGuAnalyzer).Parse(provence);
                    Lucene.Net.Search.Query query = new TermQuery(new Term("Province", provence));
                    bQuery.Add(query, BooleanClause.Occur.MUST);//其中的MUST、SHOULD、MUST_NOT表示与、或、非

                    if (city != "不限城市")
                    {
                        //query = new QueryParser("City", PanGuAnalyzer).Parse(city);
                        query = new TermQuery(new Term("City", city));
                        bQuery.Add(query, BooleanClause.Occur.MUST);

                        if (area != "不限区县")
                        {
                            //query = new QueryParser("Area", PanGuAnalyzer).Parse(area);
                            //query = new TermQuery(new Term("Area", area));
                            query = new QueryParser(Lucene.Net.Util.Version.LUCENE_29, "Area", PanGuAnalyzer).Parse(area);
                            bQuery.Add(query, BooleanClause.Occur.MUST);
                        }
                    }
                }


                if (industry != "请选择行业")
                {
                    Lucene.Net.Search.Query query = new QueryParser(Lucene.Net.Util.Version.LUCENE_29, "Industry", PanGuAnalyzer).Parse(industry);
                    //Lucene.Net.Search.Query query = new TermQuery(new Term("Industry", industry));
                    bQuery.Add(query, BooleanClause.Occur.MUST);
                }

                Dictionary<string, string> dic = new Dictionary<string, string>();
                if (!string.IsNullOrEmpty(comname))
                {
                    //bQuery1.Add(query5, BooleanClause.Occur.MUST);
                    //bQuery.Add(bQuery1, BooleanClause.Occur.MUST);

                    string title = GetKeyWordsSplitBySpace(comname);
                    Lucene.Net.Search.Query query = new QueryParser(Lucene.Net.Util.Version.LUCENE_29, "Name", PanGuAnalyzer).Parse(title);
                    bQuery.Add(query, BooleanClause.Occur.MUST);
                    dic.Add("title", comname);
                }

                if (bQuery != null && bQuery.GetClauses().Length > 0)
                {
                    serchalllist = GetSearchResult(bQuery, dic, "/Lucene.Net/IndexDic/Gys");
                }

                int listcount = serchalllist.totalHits > 1000 ? 1000 : serchalllist.totalHits;
                int maxpage = Math.Max((listcount + PAGESIZE - 1) / PAGESIZE, 1);
                if (string.IsNullOrEmpty(page.ToString()) || page < 0 || page > maxpage)
                {
                    page = 1;
                }

                IList<供应商读出Lucene> serchlist = new List<供应商读出Lucene>();
                if (serchalllist != null && listcount > 0)
                {
                    int length = PAGESIZE;
                    if (maxpage == page && listcount % PAGESIZE != 0)
                        length = listcount % PAGESIZE;

                    int count = PAGESIZE * ((int)page - 1);
                    //IndexSearcher search = new IndexSearcher(IndexDic("/Lucene.Net/IndexDic/Gys"), true);
                    IndexSearcher search = new IndexSearcher(new Lucene.Net.Store.SimpleFSDirectory(new System.IO.DirectoryInfo(IndexDic("/Lucene.Net/IndexDic/Gys"))), true);
                    for (int i = count; i < count + length; i++)
                    {
                        供应商 model = new 供应商();
                        model.Id = long.Parse(search.Doc(serchalllist.scoreDocs[i].doc).Get("NumId"));
                        model.企业基本信息.企业名称 = search.Doc(serchalllist.scoreDocs[i].doc).Get("Name");

                        model.企业基本信息.所属行业 = search.Doc(serchalllist.scoreDocs[i].doc).Get("Industry");
//.........这里部分代码省略.........
开发者ID:269378737,项目名称:go81,代码行数:101,代码来源:供应商陈列Controller.cs

示例6: Part_GysList

        public ActionResult Part_GysList() //供应商列表
        {
            if (-1 != HttpContext.检查登录())
            {
                ViewData["已登录"] = "1";
            }
            else
            {
                ViewData["已登录"] = "0";
            }
            ViewData["行业列表"] = 商品分类管理.查找子分类();
            var name = Request.QueryString["name"];
            if (!string.IsNullOrWhiteSpace(name))
            {
                string comname = name;//企业名称
                try
                {
                    TopDocs serchalllist = null;
                    int page = 1;

                    PanGu.Segment.Init(PanGuXmlPath);
                    BooleanQuery bQuery = new BooleanQuery();

                    Dictionary<string, string> dic = new Dictionary<string, string>();
                    if (!string.IsNullOrEmpty(comname))
                    {
                        string title = GetKeyWordsSplitBySpace(comname);
                        Lucene.Net.Search.Query query = new QueryParser(Lucene.Net.Util.Version.LUCENE_29, "Name", PanGuAnalyzer).Parse(title);
                        bQuery.Add(query, BooleanClause.Occur.MUST);
                        dic.Add("title", comname);
                    }

                    if (bQuery != null && bQuery.GetClauses().Length > 0)
                    {
                        serchalllist = GetSearchResult(bQuery, dic, "/Lucene.Net/IndexDic/Gys");
                    }
                    var serchlist = new List<供应商读出Lucene>();
                    int listcount = serchalllist.totalHits > 1000 ? 1000 : serchalllist.totalHits;
                    int maxpage = Math.Max((listcount + PAGESIZE - 1) / PAGESIZE, 1);
                    if (serchalllist != null && listcount > 0)
                    {

                        int length = PAGESIZE;
                        if (maxpage == page && listcount % PAGESIZE != 0)
                            length = listcount % PAGESIZE;

                        //IndexSearcher search = new IndexSearcher(IndexDic("/Lucene.Net/IndexDic/Gys"), true);
                        IndexSearcher search = new IndexSearcher(new Lucene.Net.Store.SimpleFSDirectory(new System.IO.DirectoryInfo(IndexDic("/Lucene.Net/IndexDic/Gys"))), true);

                        for (int i = 0; i < length; i++)
                        {
                            供应商 model = new 供应商();
                            model.Id = long.Parse(search.Doc(serchalllist.scoreDocs[i].doc).Get("NumId"));
                            model.企业基本信息.企业名称 = search.Doc(serchalllist.scoreDocs[i].doc).Get("Name");
                            model.企业基本信息.所属行业 = search.Doc(serchalllist.scoreDocs[i].doc).Get("Industry");
                            model.所属地域.省份 = search.Doc(serchalllist.scoreDocs[i].doc).Get("Province");
                            model.所属地域.城市 = search.Doc(serchalllist.scoreDocs[i].doc).Get("City");
                            model.所属地域.区县 = search.Doc(serchalllist.scoreDocs[i].doc).Get("Area");
                            model.企业联系人信息.联系人固定电话 = search.Doc(serchalllist.scoreDocs[i].doc).Get("Telephone");
                            model.企业联系人信息.联系人姓名 = search.Doc(serchalllist.scoreDocs[i].doc).Get("P_Name");

                            var Rzjb = search.Doc(serchalllist.scoreDocs[i].doc).Get("Rzjb");
                            model.供应商用户信息.认证级别 = Rzjb == null ? 供应商.认证级别.未设置 : (供应商.认证级别)(int.Parse(Rzjb));

                            ///////////////////图标拆分
                            var 图标 = search.Doc(serchalllist.scoreDocs[i].doc).Get("Level_Flage").Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                            if (图标[0] == "1")
                            {
                                model.供应商用户信息.年检列表.Add(DateTime.Now.Year.ToString(), new 操作数据());
                            }
                            model.供应商用户信息.应急供应商 = 图标[1] == "1";
                            model.供应商用户信息.协议供应商 = 图标[2] == "1";
                            model.供应商用户信息.入库级别 = (供应商.入库级别)(int.Parse(图标[3]));
                            ///////////////////图标拆分

                            //员工人数
                            model.企业基本信息.员工人数 = (供应商.员工人数)Enum.Parse(typeof(供应商.员工人数), search.Doc(serchalllist.scoreDocs[i].doc).Get("People_Count"));

                            供应商读出Lucene m = new 供应商读出Lucene();
                            m.供应商 = model;
                            m.登记商品数 = search.Doc(serchalllist.scoreDocs[i].doc).Get("Pro_Count");
                            m.历史参标次数 = search.Doc(serchalllist.scoreDocs[i].doc).Get("History_Count");
                            m.经营类型 = search.Doc(serchalllist.scoreDocs[i].doc).Get("Management");
                            m.主营产品 = search.Doc(serchalllist.scoreDocs[i].doc).Get("Pro_Industry");
                            m.资质证书 = search.Doc(serchalllist.scoreDocs[i].doc).Get("Zzzs_Pic");
                            m.厂房及设备图 = search.Doc(serchalllist.scoreDocs[i].doc).Get("Gys_Pic");


                            //////////////////////////////////////////右边商品图片
                            var pro = search.Doc(serchalllist.scoreDocs[i].doc).Get("Show_Product");
                            if (!string.IsNullOrWhiteSpace(pro))
                            {
                                var prolist = pro.Split(new[] { "||||" }, StringSplitOptions.RemoveEmptyEntries);
                                foreach (var item in prolist)
                                {
                                    商品 sp = new 商品();
                                    var itemlist = item.Split(new[] { "****" }, StringSplitOptions.RemoveEmptyEntries);
                                    sp.商品信息.商品图片.Add(itemlist[0]);
                                    sp.商品信息.商品名 = itemlist[1];
                                    sp.销售信息.价格 = decimal.Parse(itemlist[2]);
//.........这里部分代码省略.........
开发者ID:269378737,项目名称:go81,代码行数:101,代码来源:供应商陈列Controller.cs

示例7: SearchIndex

 /// <summary>
 /// 从索引搜索结果
 /// </summary>
 private TopDocs SearchIndex(string indexdic, string keyword)
 {
     PanGu.Segment.Init(PanGuXmlPath);
     Dictionary<string, string> dic = new Dictionary<string, string>();
     BooleanQuery bQuery = new BooleanQuery();
     string title = string.Empty;
     if ((keyword != null && keyword != ""))
     {
         title = GetKeyWordsSplitBySpace(keyword);
         QueryParser parse = new MultiFieldQueryParser(Lucene.Net.Util.Version.LUCENE_29, new String[] { "Title", "Content" }, PanGuAnalyzer);
         Lucene.Net.Search.Query query = parse.Parse(title);
         parse.SetDefaultOperator(QueryParser.Operator.AND);
         bQuery.Add(query, BooleanClause.Occur.MUST);
         dic.Add("title", keyword);
     }
     if (bQuery != null && bQuery.GetClauses().Length > 0)
     {
         return GetSearchResult(bQuery, dic, indexdic);
     }
     else
     {
         return null;
     }
 }
开发者ID:269378737,项目名称:go81,代码行数:27,代码来源:新闻Controller.cs

示例8: VisitQuery

 private static void VisitQuery(BooleanQuery query, AzureQueryLogger.IndentedTextWriter writer)
 {
     foreach (BooleanClause booleanClause in query.GetClauses())
     {
         writer.WriteLine("Clause:");
         ++writer.Indent;
         writer.WriteLine("IsProhibited: {0}", (booleanClause.IsProhibited ? 1 : 0));
         writer.WriteLine("IsRequired: {0}", (booleanClause.IsRequired ? 1 : 0));
         writer.WriteLine("Occur: {0}", (object)booleanClause.Occur);
         AzureQueryLogger.Visit(booleanClause.Query, writer);
         --writer.Indent;
     }
 }
开发者ID:jscott1277,项目名称:SitecoreAzureSearchProvider,代码行数:13,代码来源:AzureQueryLogger.cs

示例9: Combine

 private void Combine(BooleanQuery target, BooleanQuery source, Occur occur)
 {
     if (source.GetClauses().Length == 1)
     {
         var clause = source.GetClauses()[0];
         if (clause.Occur == Occur.MUST)
         {
             clause.Occur = occur;
         }
         target.Add(clause);
     }
     else
     {
         target.Add(source, occur);
     }
 }
开发者ID:chriseldredge,项目名称:Lucene.Net.Linq,代码行数:16,代码来源:QueryBuildingExpressionTreeVisitor.cs

示例10: TranslateBooleanQuery

        private SectionSearchQueryPlan TranslateBooleanQuery(BooleanQuery query)
        {
            List<Query> requiredClauses = new List<Query>();
            List<Query> prohibitedClauses = new List<Query>();
            List<Query> optionalClauses = new List<Query>();
            BooleanClause[] clauses = query.GetClauses();
            foreach (BooleanClause clause in clauses)
            {
                if (clause.IsRequired)
                {
                    requiredClauses.Add(clause.Query);
                }
                else if (clause.IsProhibited)
                {
                    prohibitedClauses.Add(clause.Query);
                }
                else
                {
                    optionalClauses.Add(clause.Query);
                }
            }

            SectionSearchQueryPlan positiveNode = null;
            SectionSearchQueryPlan negativeNode = null;

            if (requiredClauses.Count > 0)
            {
                if (requiredClauses.Count == 1)
                {
                    positiveNode = Translate(requiredClauses.Get(0));
                }
                else
                {
                    SectionSearchQueryPlan[] subqueries = Translate(requiredClauses);
                    if (subqueries != null && subqueries.Length > 0) positiveNode = new AndNode(subqueries);
                }
            }
            else if (optionalClauses.Count > 0)
            {
                if (optionalClauses.Count == 1)
                {
                    positiveNode = Translate(optionalClauses.Get(0));
                }
                else
                {
                    SectionSearchQueryPlan[] subqueries = Translate(optionalClauses);
                    if (subqueries != null && subqueries.Length > 0) positiveNode = new OrNode(subqueries);
                }
            }

            if (prohibitedClauses.Count > 0)
            {
                if (prohibitedClauses.Count == 1)
                {
                    negativeNode = Translate(prohibitedClauses.Get(0));
                }
                else
                {
                    negativeNode = new OrNode(Translate(prohibitedClauses));
                }
            }

            if (negativeNode == null)
            {
                return positiveNode;
            }
            else
            {
                if (positiveNode == null)
                {
                    return new UnaryNotNode(negativeNode);
                }
                else
                {
                    return new AndNotNode(positiveNode, negativeNode);
                }
            }
        }
开发者ID:yao-yi,项目名称:BoboBrowse.Net,代码行数:78,代码来源:SectionSearchQueryPlanBuilder.cs

示例11: BuildBoolean

        private ParameterizedSql BuildBoolean(BooleanQuery booleanQuery)
        {
            var queryStringBuilder = new StringBuilder();
            var segmentsAdded = 0;
            var segmentsAddedOccur = 0;
            var currentParamNumber = 1;
            var combinedUserInputVariables = new Dictionary<string, string>();
            Occur? currentOccur = null;

            var clauses = new List<BooleanClause>();

            var areMustClauses = booleanQuery.GetClauses().Any(c => c.Occur == Occur.MUST);

            clauses.AddRange(booleanQuery.GetClauses().Where(c => c.Occur == Occur.MUST).ToList());

            // SHOULD clauses are only relevant when there are no MUST clauses.
            // See: https://lucene.apache.org/core/3_0_3/api/core/org/apache/lucene/search/BooleanClause.Occur.html
            if (areMustClauses == false)
            {
                clauses.AddRange(booleanQuery.GetClauses().Where(c => c.Occur == Occur.SHOULD).ToList());
            }

            clauses.AddRange(booleanQuery.GetClauses().Where(c => c.Occur == Occur.MUST_NOT).ToList());

            foreach (var clause in clauses)
            {
                var subQuery = Build(clause.Query);

                if (subQuery == null || subQuery.Sql == null) continue;

                if (currentOccur == null) // if first clause
                {
                    queryStringBuilder.Append("(");
                    currentOccur = clause.Occur;
                }
                // if switch from Occur.MUST clauses to Occur.SHOULD clauses,
                // or if from Occur.SHOULD clauses to Occur.MUST_NOT clauses
                else if(currentOccur != clause.Occur)
                {
                    queryStringBuilder.Append(") AND (");
                    currentOccur = clause.Occur;
                    segmentsAddedOccur = 0;
                }

                if (segmentsAddedOccur > 0)
                {
                    if (clause.Occur == Occur.MUST)
                    {
                        queryStringBuilder.Append(" AND ");
                    }
                    else if (clause.Occur == Occur.SHOULD)
                    {
                        queryStringBuilder.Append(" OR ");
                    }
                    else if (clause.Occur == Occur.MUST_NOT)
                    {
                        queryStringBuilder.Append(" AND NOT ");
                    }
                }
                else if (clause.Occur == Occur.MUST_NOT)
                {
                    queryStringBuilder.Append("NOT ");
                }

                var sqlToAppend = subQuery.Sql;

                // All sub-query sql contains parameters starting with "field1", "field2", etc and
                // are here given unique names ("field5", "field6", etc.).
                // They match user input variables with also contain keys that start with "field1", "field2", etc and
                // need to be given matching unique names.
                if (subQuery.UserInputVariables.Count > 0)
                {
                    int numUserInputVariables = subQuery.UserInputVariables.Count;
                    var param = currentParamNumber;

                    for (var i = 1; i <= numUserInputVariables; i++)
                    {
                        combinedUserInputVariables.Add("field" + param, subQuery.UserInputVariables["field" + i]);

                        param++;
                    }

                    param = currentParamNumber;
                    for (var i = numUserInputVariables; i > 0; i--)
                    {
                        sqlToAppend = Regex.Replace(sqlToAppend,
                                                    "@field" + i + "([^0-9])",
                                                    "@field" + (param + i - 1) + "$1");

                        currentParamNumber++;
                    }
                }

                queryStringBuilder.Append("(" + sqlToAppend + ")");

                // If the last clause, close the parens around MUST/SHOULD/MUST_NOT sections
                if (segmentsAdded == clauses.Count - 1)
                {
                    queryStringBuilder.Append(")");
                }
//.........这里部分代码省略.........
开发者ID:tomvonclef,项目名称:LuceneQueryToSql,代码行数:101,代码来源:QueryBuilder.cs

示例12: Combine

        private void Combine(BooleanQuery target, BooleanQuery source, Occur occur)
        {
            if (source.GetClauses().Length == 1)
            {
                var clause = source.GetClauses().Single();
                if (clause.IsProhibited && occur == Occur.SHOULD)
                {
                    source = (BooleanQuery)source.Clone();
                    source.Add(new MatchAllDocsQuery(), Occur.SHOULD);
                    target.Add(source, occur);
                    return;
                }

                if (clause.Occur == Occur.MUST)
                {
                    clause.Occur = occur;
                }
                target.Add(clause);
            }
            else
            {
                target.Add(source, occur);
            }
        }
开发者ID:Zaixu,项目名称:Lucene.Net.Linq,代码行数:24,代码来源:QueryBuildingExpressionTreeVisitor.cs


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