public static SearchAttributeViewModel GetSearchAttributeViewModel(SearchAttribute searchAttribute) { SearchAttributeViewModel sa = new SearchAttributeViewModel(); sa.id = searchAttribute.id; //names sa.displayName = searchAttribute.displayName; sa.metadataNames.AddRange(searchAttribute.metadataName.Split(',')); //types sa.dataType = SearchAttribute.GetDataTypeAsDisplayString(searchAttribute.dataType); sa.searchType = SearchAttribute.GetSearchTypeAsDisplayString(searchAttribute.searchType); // parameter for index sa.store = searchAttribute.store; sa.multiValue = searchAttribute.multiValue; sa.analysed = searchAttribute.analysed; sa.norm = searchAttribute.norm; sa.boost = searchAttribute.boost; // resultview sa.headerItem = searchAttribute.headerItem; sa.defaultHeaderItem = searchAttribute.defaultHeaderItem; // properties sa.direction = SearchAttribute.GetDirectionAsString(searchAttribute.direction); sa.uiComponent = SearchAttribute.GetUIComponentAsString(searchAttribute.uiComponent); sa.aggregationType = SearchAttribute.GetAggregationTypeAsString(searchAttribute.aggregationType); //sa.dateFormat = searchAttribute.dateFormat; return(sa); }
/// <summary> /// 在后台组合where 条件 /// </summary> /// <param name="controller"></param> /// <param name="type"></param> /// <returns></returns> public static string BindWhere(this System.Web.Mvc.Controller controller, Type type) { List <string> wherelist = new List <string>();//where 列表 var propertys = type.GetProperties(); foreach (var p in propertys) { object[] alist = p.GetCustomAttributes(typeof(SearchAttribute), false); if (alist.Length > 0) { SearchAttribute sa = alist[0] as SearchAttribute; if (sa == null) { continue; } string w = sa.getWhere(p, controller.Request); if (string.IsNullOrWhiteSpace(w)) { continue; } wherelist.Add(w);//获取类型绑定的search对象 } } return(string.Join(" AND ", wherelist.ToArray())); }
public static SearchAttribute GetSearchAttribute(SearchAttributeViewModel searchAttributeViewModel) { SearchAttribute sa = new SearchAttribute(); //names sa.displayName = searchAttributeViewModel.displayName; sa.sourceName = Regex.Replace(searchAttributeViewModel.displayName, "[^0-9a-zA-Z]+", ""); sa.metadataName = String.Join(",", searchAttributeViewModel.metadataNames.Where(x => !string.IsNullOrEmpty(x)).ToArray()); //types sa.dataType = SearchAttribute.GetDataType(searchAttributeViewModel.dataType); sa.searchType = SearchAttribute.GetSearchType(searchAttributeViewModel.searchType); // parameter for index sa.store = searchAttributeViewModel.store; sa.multiValue = searchAttributeViewModel.multiValue; sa.analysed = searchAttributeViewModel.analysed; sa.norm = searchAttributeViewModel.norm; sa.boost = searchAttributeViewModel.boost; // resultview sa.headerItem = searchAttributeViewModel.headerItem; sa.defaultHeaderItem = searchAttributeViewModel.defaultHeaderItem; // properties sa.direction = SearchAttribute.GetDirection(searchAttributeViewModel.direction); sa.uiComponent = SearchAttribute.GetUIComponent(searchAttributeViewModel.uiComponent); sa.aggregationType = SearchAttribute.GetAggregationType(searchAttributeViewModel.aggregationType); //sa.dateFormat = searchAttributeViewModel.dateFormat; return(sa); }
public ActionResult GetSearch(string Type, int Status, string StartDate, string EndDate, string ProductType, int Overstatus, string Changeitem, string ControlNo, string Model, string Chosechangeitem, string Partno, string Partname, string Department, string Processname, string Production, string Line) { var temp_search = new SearchAttribute(Type, Status, StartDate, EndDate, ProductType, Overstatus, Changeitem, ControlNo, Model, Chosechangeitem, Partno, Partname, Department, Processname, Production, Line); var TopicList = M_Home.GetSearch(temp_search); TopicList.ForEach(Topic => { Topic.Date = Topic.Date.StringToDateTimeShort(); Topic.Timing = Topic.Timing.StringToDateTimeShort(); Topic.Detail = Topic.Detail.StripTagsRegex(); }); return(Json(TopicList, JsonRequestBehavior.AllowGet)); }
public IHttpActionResult GetStudents(string sortString = "id", string sortOrder = "asc", string searchValue = "", int pageSize = 10, int pageNumber = 1) { var searchAttr = new SearchAttribute() { SearchValue = searchValue, SortOrder = sortOrder, SortString = sortString, PageNumber = pageNumber, PageSize = pageSize }; return(Ok(_studentManager.Search(searchAttr))); }
// GET: api/Student public IHttpActionResult Get(string sortString = "id", string sortOrder = "asc", string searchValue = "", int pageSize = 10, int pageNumber = 1) { SearchAttribute search = new SearchAttribute() { SearchValue = searchValue, SortOrder = sortOrder, SortString = sortString, PageNumber = pageNumber, PageSize = pageSize }; StudentSearchDto students = _studentManager.SearchStudent(search); return(Ok(students)); }
public IHttpActionResult Get(string sortString = "id", string sortOrder = "asc", string searchValue = "", int pageSize = 10, int pageNumber = 1)//asc { SearchAttribute searchCondition = new SearchAttribute() { SearchValue = searchValue, SortOrder = sortOrder, SortString = sortString, PageNumber = pageNumber, PageSize = pageSize }; StudentSearchDto students = _studentManager.SearchStudents(searchCondition); if (students.Students.Count == 0) { return(NotFound()); } return(Ok(students)); }
/// <summary> /// 创建搜索框 /// </summary> /// <param name="helper"></param> /// <param name="type"></param> /// <param name="parms"></param> /// <returns></returns> public static string Search(this System.Web.Mvc.HtmlHelper helper, Type type, object parms) { List <string> plist = new List <string>();//可查询属性 列表 UrlHelper UrlHelper = new System.Web.Mvc.UrlHelper(helper.ViewContext.RequestContext); var propertys = type.GetProperties(); foreach (var p in propertys) { object[] alist = p.GetCustomAttributes(typeof(SearchAttribute), false); if (alist.Length > 0) { SearchAttribute sa = alist[0] as SearchAttribute; if (sa == null) { continue; } var ls = sa.getInputFiles(p); StringBuilder sb = new StringBuilder(); foreach (var l in ls) { var value = sa.getValue(p.Name, helper.ViewContext.HttpContext.Request); var displayname = ((DisplayAttribute[])p.GetCustomAttributes(typeof(DisplayAttribute), false)).FirstOrDefault(); sb.Append(string.Format("<label for='{0}' >{2}</label><input type='text' name='{0}' id='{0}' value='{1}' >", p.Name, value, displayname.Name)); } plist.Add(string.Format("<span>{0}</span>", sb.ToString()));//获取类型绑定的search对象 } } if (plist.Count == 0) { return(""); } string actionName = helper.ViewContext.RouteData.Values["action"].ToString(); string result = string.Format("<div class='query-content'><form action='{0}' name='form-{1}' id='form-{1}'> {2} <span><input type='submit' value='查询'></span><form></div>", UrlHelper.Action(actionName, parms), type.Name, string.Join("", plist.ToArray())); return(result); }
//read xml config file private void Load() { this._configXML = new XmlDocument(); this._configXML.Load(FileHelper.ConfigFilePath); XmlNodeList fieldProperties = this._configXML.GetElementsByTagName("field"); int index = 0; foreach (XmlNode fieldProperty in fieldProperties) { if (!fieldProperty.Attributes.GetNamedItem("lucene_name").Value.Equals("Primarydata")) { SearchAttribute sa = new SearchAttribute(); sa.id = index; //Names if (fieldProperty.Attributes.GetNamedItem("display_name") != null) { sa.displayName = fieldProperty.Attributes.GetNamedItem("display_name").Value; } if (fieldProperty.Attributes.GetNamedItem("lucene_name") != null) { sa.sourceName = fieldProperty.Attributes.GetNamedItem("lucene_name").Value; } if (fieldProperty.Attributes.GetNamedItem("metadata_name") != null) { sa.metadataName = fieldProperty.Attributes.GetNamedItem("metadata_name").Value; } //types if (fieldProperty.Attributes.GetNamedItem("type") != null) { sa.searchType = SearchAttribute.GetSearchType(fieldProperty.Attributes.GetNamedItem("type").Value); } if (fieldProperty.Attributes.GetNamedItem("primitive_type") != null) { sa.dataType = SearchAttribute.GetDataType(fieldProperty.Attributes.GetNamedItem("primitive_type").Value); } //// parameter for index if (fieldProperty.Attributes.GetNamedItem("store") != null) { sa.store = SearchAttribute.GetBoolean(fieldProperty.Attributes.GetNamedItem("store").Value); } if (fieldProperty.Attributes.GetNamedItem("multivalued") != null) { sa.multiValue = SearchAttribute.GetBoolean(fieldProperty.Attributes.GetNamedItem("multivalued").Value); } if (fieldProperty.Attributes.GetNamedItem("analyzed") != null) { sa.analysed = SearchAttribute.GetBoolean(fieldProperty.Attributes.GetNamedItem("analyzed").Value); } if (fieldProperty.Attributes.GetNamedItem("norm") != null) { sa.norm = SearchAttribute.GetBoolean(fieldProperty.Attributes.GetNamedItem("norm").Value); } if (fieldProperty.Attributes.GetNamedItem("boost") != null) { sa.boost = Convert.ToDouble(fieldProperty.Attributes.GetNamedItem("boost").Value); } // Resultview if (fieldProperty.Attributes.GetNamedItem("header_item") != null) { sa.headerItem = SearchAttribute.GetBoolean(fieldProperty.Attributes.GetNamedItem("header_item").Value); } if (fieldProperty.Attributes.GetNamedItem("default_visible_item") != null) { sa.defaultHeaderItem = SearchAttribute.GetBoolean(fieldProperty.Attributes.GetNamedItem("default_visible_item").Value); } if (fieldProperty.Attributes.GetNamedItem("direction") != null) { sa.direction = SearchAttribute.GetDirection(fieldProperty.Attributes.GetNamedItem("direction").Value); } if (fieldProperty.Attributes.GetNamedItem("uiComponent") != null) { sa.uiComponent = SearchAttribute.GetUIComponent(fieldProperty.Attributes.GetNamedItem("uiComponent").Value); } if (fieldProperty.Attributes.GetNamedItem("aggregationType") != null) { sa.aggregationType = SearchAttribute.GetAggregationType(fieldProperty.Attributes.GetNamedItem("aggregationType").Value); } if (fieldProperty.Attributes.GetNamedItem("date_format") != null) { sa.dateFormat = fieldProperty.Attributes.GetNamedItem("date_format").Value; } this._searchAttributeList.Add(sa); index++; } else { this._includePrimaryData = true; } } }
private XmlElement SetAttributesToNode(XmlElement xmlElement, SearchAttribute sa) { // names XmlAttribute xa = this._configXML.CreateAttribute("display_name"); xa.Value = sa.displayName; xmlElement.Attributes.Append(xa); xa = this._configXML.CreateAttribute("lucene_name"); xa.Value = sa.sourceName; xmlElement.Attributes.Append(xa); xa = this._configXML.CreateAttribute("metadata_name"); xa.Value = sa.metadataName; xmlElement.Attributes.Append(xa); //types xa = this._configXML.CreateAttribute("type"); xa.Value = SearchAttribute.GetSearchTypeAsString(sa.searchType); xmlElement.Attributes.Append(xa); xa = this._configXML.CreateAttribute("primitive_type"); xa.Value = SearchAttribute.GetDataTypeAsString(sa.dataType); xmlElement.Attributes.Append(xa); // parameter for index xa = this._configXML.CreateAttribute("store"); xa.Value = SearchAttribute.GetBooleanAsString(sa.store); xmlElement.Attributes.Append(xa); xa = this._configXML.CreateAttribute("multivalued"); xa.Value = SearchAttribute.GetBooleanAsString(sa.multiValue); xmlElement.Attributes.Append(xa); xa = this._configXML.CreateAttribute("analysed"); xa.Value = SearchAttribute.GetBooleanAsString(sa.analysed); xmlElement.Attributes.Append(xa); xa = this._configXML.CreateAttribute("norm"); xa.Value = SearchAttribute.GetBooleanAsString(sa.norm); xmlElement.Attributes.Append(xa); //boost xa = this._configXML.CreateAttribute("boost"); xa.Value = sa.boost.ToString(); xmlElement.Attributes.Append(xa); // ResultView xa = this._configXML.CreateAttribute("header_item"); xa.Value = SearchAttribute.GetBooleanAsString(sa.headerItem); xmlElement.Attributes.Append(xa); xa = this._configXML.CreateAttribute("default_visible_item"); xa.Value = SearchAttribute.GetBooleanAsString(sa.defaultHeaderItem); xmlElement.Attributes.Append(xa); // properties if (sa.searchType.Equals(SearchComponentBaseType.Property)) { xa = this._configXML.CreateAttribute("direction"); xa.Value = SearchAttribute.GetDirectionAsString(sa.direction); xmlElement.Attributes.Append(xa); xa = this._configXML.CreateAttribute("uiComponent"); xa.Value = SearchAttribute.GetUIComponentAsString(sa.uiComponent); xmlElement.Attributes.Append(xa); xa = this._configXML.CreateAttribute("aggregationType"); xa.Value = SearchAttribute.GetAggregationTypeAsString(sa.aggregationType); xmlElement.Attributes.Append(xa); xa = this._configXML.CreateAttribute("date_format"); xa.Value = sa.dateFormat; xmlElement.Attributes.Append(xa); } return(xmlElement); }