public static SearchResult ConvertListOfMetadataToSearchResultObject(List<Metadata> metadataList, int pageSize,int currentPage) { SearchResult sro = new SearchResult(); sro.PageSize = pageSize; sro.CurrentPage = currentPage; sro.NumberOfHits = metadataList.Count(); List<HeaderItem> Header = new List<HeaderItem>(); List<HeaderItem> DefaultHeader = new List<HeaderItem>(); List<Row> RowList = new List<Row>(); foreach (Metadata m in metadataList) { if(metadataList.First()==m) { HeaderItem hi = new HeaderItem(); hi = new HeaderItem(); hi.Name = m.GetValueFromNode("datasetid").Item(0).Name; hi.DisplayName = hi.Name.Titleize(); Header.Add(hi); DefaultHeader.Add(hi); sro.Id = hi; hi = new HeaderItem(); hi.Name = m.GetValueFromNode("title").Item(0).Name; hi.DisplayName = hi.Name.Titleize(); Header.Add(hi); DefaultHeader.Add(hi); hi = new HeaderItem(); hi.Name = m.GetValueFromNode("owner").Item(0).Name; hi.DisplayName = hi.Name.Titleize(); Header.Add(hi); DefaultHeader.Add(hi); hi = new HeaderItem(); hi.Name = "PrimaryData"; hi.DisplayName = "Primary Data"; Header.Add(hi); DefaultHeader.Add(hi); hi = new HeaderItem(); hi.Name = m.GetValueFromNode("versionID").Item(0).Name; hi.DisplayName = hi.Name.Titleize(); Header.Add(hi); DefaultHeader.Add(hi); hi = new HeaderItem(); hi.Name = m.GetValueFromNode("fileType").Item(0).Name; hi.DisplayName = hi.Name.Titleize(); Header.Add(hi); hi = new HeaderItem(); hi.Name = m.GetValueFromNode("dateLastModified").Item(0).Name; hi.DisplayName = hi.Name.Titleize(); Header.Add(hi); hi = new HeaderItem(); hi.Name = m.GetValueFromNode("projectLeader").Item(0).Name; hi.DisplayName = hi.Name.Titleize(); Header.Add(hi); hi = new HeaderItem(); hi.Name = m.GetValueFromNode("dateEntry").Item(0).Name; hi.DisplayName = hi.Name.Titleize(); Header.Add(hi); hi = new HeaderItem(); hi.Name = m.GetValueFromNode("qualityLevel").Item(0).Name; hi.DisplayName = hi.Name.Titleize(); Header.Add(hi); hi = new HeaderItem(); hi.Name = m.GetValueFromNode("dataStatus").Item(0).Name; hi.DisplayName = hi.Name.Titleize(); Header.Add(hi); } Row r = new Row(); List<object> ValueList = new List<object>(); ValueList = new List<object>(); ValueList.Add(Convert.ToInt32(m.GetValueFromNode("datasetid").Item(0).InnerText)); ValueList.Add(m.GetValueFromNode("title").Item(0).InnerText); ValueList.Add(m.GetValueFromNode("owner").Item(0).InnerText); ValueList.Add("YES"); ValueList.Add(m.GetValueFromNode("versionID").Item(0).InnerText); ValueList.Add(m.GetValueFromNode("fileType").Item(0).InnerText); ValueList.Add(m.GetValueFromNode("dateLastModified").Item(0).InnerText); ValueList.Add(m.GetValueFromNode("projectLeader").Item(0).InnerText); ValueList.Add(m.GetValueFromNode("dateEntry").Item(0).InnerText); ValueList.Add(m.GetValueFromNode("qualityLevel").Item(0).InnerText); ValueList.Add(m.GetValueFromNode("dataStatus").Item(0).InnerText); r.Values = ValueList; r.PreviewItem = GetPrevieItem(); RowList.Add(r); } sro.Header = Header; sro.Rows = RowList; sro.DefaultVisibleHeaderItem = DefaultHeader; sro.PageSize = pageSize; sro.CurrentPage = currentPage; return sro; }
private static SearchResultPreview GetPrevieItem() { SearchResultPreview srp = new SearchResultPreview(); List<HeaderItem> Header = new List<HeaderItem>(); List<Row> RowList = new List<Row>(); HeaderItem hi; hi = new HeaderItem(); hi.Name = "VariableName"; Header.Add(hi); hi = new HeaderItem(); hi.Name = "VariableParameter"; Header.Add(hi); hi = new HeaderItem(); hi.Name = "Unit"; Header.Add(hi); hi = new HeaderItem(); hi.Name = "Description"; Header.Add(hi); //----------------------------------------- Row r = new Row(); List<object> ValueList = new List<object>(); ValueList.Add("Species"); ValueList.Add("No"); ValueList.Add("No"); ValueList.Add("Name of species"); r.Values = ValueList; RowList.Add(r); //----------------------------------------- r = new Row(); ValueList = new List<object>(); ValueList.Add("Plot"); ValueList.Add("No"); ValueList.Add("No"); ValueList.Add("Plot ID"); r.Values = ValueList; RowList.Add(r); //----------------------------------------- r = new Row(); ValueList = new List<object>(); ValueList.Add("Temperature"); ValueList.Add("No"); ValueList.Add("°C"); ValueList.Add("-"); r.Values = ValueList; RowList.Add(r); //----------------------------------------- r = new Row(); ValueList = new List<object>(); ValueList.Add("Date"); ValueList.Add("No"); ValueList.Add("No"); ValueList.Add("Date of Observation"); r.Values = ValueList; RowList.Add(r); //----------------------------------------- r = new Row(); ValueList = new List<object>(); ValueList.Add("Female perc"); ValueList.Add("No"); ValueList.Add("%"); ValueList.Add("Female species in %"); r.Values = ValueList; RowList.Add(r); //----------------------------------------- r = new Row(); ValueList = new List<object>(); ValueList.Add("Male perc"); ValueList.Add("No"); ValueList.Add("%"); ValueList.Add("Male species in %"); r.Values = ValueList; RowList.Add(r); //----------------------------------------- r = new Row(); ValueList = new List<object>(); ValueList.Add("Male perc"); ValueList.Add("No"); ValueList.Add("%"); ValueList.Add("Male species in %"); r.Values = ValueList; RowList.Add(r); //----------------------------------------- r = new Row(); ValueList = new List<object>(); ValueList.Add("Season"); ValueList.Add("No"); ValueList.Add("No"); ValueList.Add("Define season like summer"); r.Values = ValueList; RowList.Add(r); //----------------------------------------- r = new Row(); ValueList = new List<object>(); ValueList.Add("Weather"); ValueList.Add("No"); ValueList.Add("No"); ValueList.Add("Define weather like rainy day"); r.Values = ValueList; RowList.Add(r); //----------------------------------------- srp.Header = Header; srp.Rows = RowList; return srp; }
/// <summary> /// /// </summary> /// <remarks></remarks> /// <seealso cref=""/> /// <param name="query"></param> /// <param name="headerItemXmlNodeList"></param> /// <returns></returns> public static SearchResult search(Query query, List<XmlNode> headerItemXmlNodeList) { TopDocs docs = searcher.Search(query, 1000); SearchResult sro = new SearchResult(); sro.PageSize = 10; sro.CurrentPage = 1; sro.NumberOfHits = 100; List<HeaderItem> Header = new List<HeaderItem>(); List<HeaderItem> DefaultHeader = new List<HeaderItem>(); // create id HeaderItem id = new HeaderItem(); id.DisplayName = "ID"; id.Name = "ID"; id.DataType = "Integer"; sro.Id = id; Header.Add(id); DefaultHeader.Add(id); foreach (XmlNode ade in headerItemXmlNodeList) { HeaderItem hi = new HeaderItem(); hi = new HeaderItem(); hi.Name = ade.Attributes.GetNamedItem("lucene_name").Value; hi.DisplayName = ade.Attributes.GetNamedItem("display_name").Value; Header.Add(hi); if (ade.Attributes.GetNamedItem("default_visible_item").Value.ToLower().Equals("yes")) { DefaultHeader.Add(hi); } } List<Row> RowList = new List<Row>(); foreach (ScoreDoc sd in docs.ScoreDocs) { Document doc = searcher.Doc(sd.Doc); Row r = new Row(); List<object> ValueList = new List<object>(); ValueList = new List<object>(); ValueList.Add(doc.Get("doc_id")); foreach (XmlNode ade in headerItemXmlNodeList) { String fieldType = ade.Attributes.GetNamedItem("type").Value; String luceneName = ade.Attributes.GetNamedItem("lucene_name").Value; if (fieldType.ToLower().Equals("facet_field")) { luceneName = "facet_" + luceneName; } else if (fieldType.ToLower().Equals("category_field")) { luceneName = "category_" + luceneName; } else if (fieldType.ToLower().Equals("property_field")) { luceneName = "property_" + luceneName; } ValueList.Add(doc.Get(luceneName)); } r.Values = ValueList; RowList.Add(r); } sro.Header = Header; sro.DefaultVisibleHeaderItem = DefaultHeader; sro.Rows = RowList; return sro; }