internal SlowMinShouldMatchScorer(BooleanWeight weight, AtomicReader reader, IndexSearcher searcher) : base(weight) { this.dv = reader.GetSortedSetDocValues("dv"); this.maxDoc = reader.MaxDoc; BooleanQuery bq = (BooleanQuery)weight.Query; this.minNrShouldMatch = bq.MinimumNumberShouldMatch; this.sims = new SimScorer[(int)dv.ValueCount]; foreach (BooleanClause clause in bq.GetClauses()) { Debug.Assert(!clause.IsProhibited); Debug.Assert(!clause.IsRequired); Term term = ((TermQuery)clause.Query).Term; long ord = dv.LookupTerm(term.Bytes); if (ord >= 0) { bool success = ords.Add(ord); Debug.Assert(success); // no dups TermContext context = TermContext.Build(reader.Context, term); SimWeight w = weight.Similarity.ComputeWeight(1f, searcher.CollectionStatistics("field"), searcher.TermStatistics(term, context)); var dummy = w.GetValueForNormalization(); // ignored w.Normalize(1F, 1F); sims[(int)ord] = weight.Similarity.GetSimScorer(w, (AtomicReaderContext)reader.Context); } } }
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; }
public virtual void TestMethod() { RAMDirectory directory = new RAMDirectory(); System.String[] categories = new System.String[] { "food", "foodanddrink", "foodanddrinkandgoodtimes", "food and drink" }; Query rw1 = null; Query rw2 = null; try { IndexWriter writer = new IndexWriter(directory, new WhitespaceAnalyzer(), true); for (int i = 0; i < categories.Length; i++) { Document doc = new Document(); doc.Add(Field.Keyword("category", categories[i])); writer.AddDocument(doc); } writer.Close(); IndexReader reader = IndexReader.Open(directory); PrefixQuery query = new PrefixQuery(new Term("category", "foo")); rw1 = query.Rewrite(reader); BooleanQuery bq = new BooleanQuery(); bq.Add(query, true, false); rw2 = bq.Rewrite(reader); } catch (System.IO.IOException e) { Assert.Fail(e.Message); } BooleanQuery bq1 = null; if (rw1 is BooleanQuery) { bq1 = (BooleanQuery)rw1; } BooleanQuery bq2 = null; if (rw2 is BooleanQuery) { bq2 = (BooleanQuery)rw2; } else { Assert.Fail("Rewrite"); } Assert.AreEqual(bq1.GetClauses().Length, bq2.GetClauses().Length, "Number of Clauses Mismatch"); }
/// <summary>Expert: called when re-writing queries under MultiSearcher. /// /// Create a single query suitable for use by all subsearchers (in 1-1 /// correspondence with queries). This is an optimization of the OR of /// all queries. We handle the common optimization cases of equal /// queries and overlapping clauses of boolean OR queries (as generated /// by MultiTermQuery.rewrite() and RangeQuery.rewrite()). /// Be careful overriding this method as queries[0] determines which /// method will be called and is not necessarily of the same type as /// the other queries. /// </summary> public virtual Query Combine(Query[] queries) { System.Collections.Hashtable uniques = new System.Collections.Hashtable(); for (int i = 0; i < queries.Length; i++) { Query query = queries[i]; BooleanClause[] clauses = null; // check if we can split the query into clauses bool splittable = (query is BooleanQuery); if (splittable) { BooleanQuery bq = (BooleanQuery)query; splittable = bq.IsCoordDisabled(); clauses = bq.GetClauses(); for (int j = 0; splittable && j < clauses.Length; j++) { splittable = (clauses[j].GetOccur() == BooleanClause.Occur.SHOULD); } } if (splittable) { for (int j = 0; j < clauses.Length; j++) { Query tmp = clauses[j].GetQuery(); if (uniques.Contains(tmp) == false) { uniques.Add(tmp, tmp); } } } else { if (uniques.Contains(query) == false) { uniques.Add(query, query); } } } // optimization: if we have just one query, just return it if (uniques.Count == 1) { System.Collections.IDictionaryEnumerator iter = uniques.GetEnumerator(); iter.MoveNext(); return(iter.Value as Query); } System.Collections.IDictionaryEnumerator it = uniques.GetEnumerator(); BooleanQuery result = new BooleanQuery(true); while (it.MoveNext()) { result.Add((Query)it.Value, BooleanClause.Occur.SHOULD); } return(result); }
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); }
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; }
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); }
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; }
/// <summary>Expert: called when re-writing queries under MultiSearcher. /// /// Create a single query suitable for use by all subsearchers (in 1-1 /// correspondence with queries). This is an optimization of the OR of /// all queries. We handle the common optimization cases of equal /// queries and overlapping clauses of boolean OR queries (as generated /// by MultiTermQuery.rewrite()). /// Be careful overriding this method as queries[0] determines which /// method will be called and is not necessarily of the same type as /// the other queries. /// </summary> public virtual Query Combine(Query[] queries) { System.Collections.Hashtable uniques = new System.Collections.Hashtable(); for (int i = 0; i < queries.Length; i++) { Query query = queries[i]; BooleanClause[] clauses = null; // check if we can split the query into clauses bool splittable = (query is BooleanQuery); if (splittable) { BooleanQuery bq = (BooleanQuery)query; splittable = bq.IsCoordDisabled(); clauses = bq.GetClauses(); for (int j = 0; splittable && j < clauses.Length; j++) { splittable = (clauses[j].GetOccur() == BooleanClause.Occur.SHOULD); } } if (splittable) { for (int j = 0; j < clauses.Length; j++) { SupportClass.CollectionsHelper.AddIfNotContains(uniques, clauses[j].GetQuery()); } } else { SupportClass.CollectionsHelper.AddIfNotContains(uniques, query); } } // optimization: if we have just one query, just return it if (uniques.Count == 1) { foreach (object key in uniques.Keys) { return((Query)key); } } BooleanQuery result = new BooleanQuery(true); foreach (object key in uniques.Keys) { result.Add((Query)key, BooleanClause.Occur.SHOULD); } return(result); }
/// <summary>Expert: called when re-writing queries under MultiSearcher. /// /// Create a single query suitable for use by all subsearchers (in 1-1 /// correspondence with queries). This is an optimization of the OR of /// all queries. We handle the common optimization cases of equal /// queries and overlapping clauses of boolean OR queries (as generated /// by MultiTermQuery.rewrite()). /// Be careful overriding this method as queries[0] determines which /// method will be called and is not necessarily of the same type as /// the other queries. /// </summary> public virtual Query Combine(params Query[] queries) { Support.Set <Query> uniques = new Support.Set <Query>(); for (int i = 0; i < queries.Length; i++) { Query query = queries[i]; BooleanClause[] clauses = null; // check if we can split the query into clauses bool splittable = (query is BooleanQuery); if (splittable) { BooleanQuery bq = (BooleanQuery)query; splittable = bq.IsCoordDisabled(); clauses = bq.GetClauses(); for (int j = 0; splittable && j < clauses.Length; j++) { splittable = (clauses[j].GetOccur() == BooleanClause.Occur.SHOULD); } } if (splittable) { for (int j = 0; j < clauses.Length; j++) { uniques.Add(clauses[j].GetQuery()); } } else { uniques.Add(query); } } // optimization: if we have just one query, just return it if (uniques.Count == 1) { foreach (Query key in uniques) { return((Query)key); } } BooleanQuery result = new BooleanQuery(true); foreach (Query key in uniques) { result.Add(key, BooleanClause.Occur.SHOULD); } return(result); }
/// <summary>Expert: called when re-writing queries under MultiSearcher. /// /// Create a single query suitable for use by all subsearchers (in 1-1 /// correspondence with queries). This is an optimization of the OR of /// all queries. We handle the common optimization cases of equal /// queries and overlapping clauses of boolean OR queries (as generated /// by MultiTermQuery.rewrite()). /// Be careful overriding this method as queries[0] determines which /// method will be called and is not necessarily of the same type as /// the other queries. /// </summary> public virtual Query Combine(Query[] queries) { var uniques = new System.Collections.Generic.HashSet <Query>(); for (int i = 0; i < queries.Length; i++) { Query query = queries[i]; BooleanClause[] clauses = null; // check if we can split the query into clauses bool splittable = (query is BooleanQuery); if (splittable) { BooleanQuery bq = (BooleanQuery)query; splittable = bq.IsCoordDisabled(); clauses = bq.GetClauses(); for (int j = 0; splittable && j < clauses.Length; j++) { splittable = (clauses[j].Occur == Occur.SHOULD); } } if (splittable) { for (int j = 0; j < clauses.Length; j++) { uniques.Add(clauses[j].Query); } } else { uniques.Add(query); } } // optimization: if we have just one query, just return it if (uniques.Count == 1) { return(uniques.First()); } BooleanQuery result = new BooleanQuery(true); foreach (Query key in uniques) { result.Add(key, Occur.SHOULD); } return(result); }
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 = Random.Next(opt + 2); if (Random.NextBoolean()) { // also add a random negation Term randomTerm = new Term(Field, Vals[Random.Next(Vals.Length)]); q.Add(new TermQuery(randomTerm), Occur.MUST_NOT); } }
/// <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; } }
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"); ////可提供商品类别 //供应商._产品类别 lb = new 供应商._产品类别(); //lb.一级分类 = search.Doc(serchalllist.scoreDocs[i].doc).Get("Industry"); //model.可提供产品类别列表.Add(lb); 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]); sp.Id = long.Parse(itemlist[3]); m.商品列表.Add(sp); } } //判断会员类别 var 服务记录 = 供应商服务记录管理.查询供应商服务记录(0, 0, Query<供应商服务记录>.Where(o => o.所属供应商.用户ID == model.Id)); if (服务记录.Any()) { var 已开通服务 = 服务记录.First().已开通的服务; if (已开通服务.Any()) { if (已开通服务.Where(o => o.所申请项目名.Contains("商务会员") && o.结束时间 > DateTime.Now).Any()) { m.会员类别 = "商务会员"; } else if (已开通服务.Where(o => o.所申请项目名.Contains("标准会员") && o.结束时间 > DateTime.Now).Any()) { m.会员类别 = "标准会员"; } else if (已开通服务.Where(o => o.所申请项目名.Contains("基础会员") && o.结束时间 > DateTime.Now).Any()) { m.会员类别 = "基础会员"; } } } //判断会员类别 serchlist.Add(SetHighlighter(dic, m)); } } ViewData["供应商列表"] = serchlist; //ViewData["listcount"] = listcount; //ViewData["pagesize"] = 2; ViewData["currentpage"] = page; ViewData["pagecount"] = maxpage; } catch { ViewData["供应商列表"] = new List<供应商读出Lucene>(); ViewData["currentpage"] = 1; ViewData["pagecount"] = 1; } ViewBag.Provence = provence; ViewBag.City = city; ViewBag.Area = area; ViewBag.Industry = industry; ViewBag.Comname = comname; return PartialView("Part_Gys/Part_GysSelect_Page"); }
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]); sp.Id = long.Parse(itemlist[3]); m.商品列表.Add(sp); } } //判断会员类别 var 服务记录 = 供应商服务记录管理.查询供应商服务记录(0, 0, Query<供应商服务记录>.Where(o => o.所属供应商.用户ID == model.Id)); if (服务记录.Any()) { var 已开通服务 = 服务记录.First().已开通的服务; if (已开通服务.Any()) { if (已开通服务.Where(o => o.所申请项目名.Contains("商务会员") && o.结束时间 > DateTime.Now).Any()) { m.会员类别 = "商务会员"; } else if (已开通服务.Where(o => o.所申请项目名.Contains("标准会员") && o.结束时间 > DateTime.Now).Any()) { m.会员类别 = "标准会员"; } else if (已开通服务.Where(o => o.所申请项目名.Contains("基础会员") && o.结束时间 > DateTime.Now).Any()) { m.会员类别 = "基础会员"; } } } //判断会员类别 serchlist.Add(SetHighlighter(dic, m)); } } ViewData["供应商列表"] = serchlist; ViewData["currentpage"] = page; ViewData["pagecount"] = maxpage; } catch { ViewData["供应商列表"] = new List<供应商读出Lucene>(); ViewData["currentpage"] = 1; ViewData["pagecount"] = 1; } ViewBag.Provence = "不限省份"; ViewBag.City = "不限城市"; ViewBag.Area = "不限区县"; ViewBag.Industry = "请选择行业"; ViewBag.Comname = comname; return PartialView("Part_Gys/Part_GysList_SearchBox"); } else { //未付费 var q = MongoDB.Driver.Builders.Query<供应商>.Where(o => o.审核数据.审核状态 == 审核状态.审核通过||o.入网审核数据.审核状态== 审核状态.审核通过); long listcount = (int)用户管理.计数用户<供应商>(0, 0, q, false); long maxpagesize = Math.Max((listcount + PAGESIZE - 1) / PAGESIZE, 1); ViewData["currentpage"] = 1; ViewData["pagecount"] = maxpagesize; ViewData["供应商列表"] = 用户管理.查询用户<供应商>(0, PAGESIZE, q, false, SortBy<供应商>.Descending(o => o.供应商用户信息.认证级别).Descending(o => o.基本数据.修改时间), false); return PartialView("Part_Gys/Part_GysList"); } }
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); } }
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(")"); } segmentsAdded++; segmentsAddedOccur++; } return new ParameterizedSql(queryStringBuilder.ToString(), combinedUserInputVariables); }
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); } } }
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; } }
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); } }