/// <summary> /// Make a list of groups that should be shown according to the given parameters /// </summary> /// <param name="parms"></param> /// <returns></returns> protected override IList <OLVGroup> MakeGroups(GroupingParameters parms) { if (this.GroupingStrategy == null) { return(new List <OLVGroup>()); } else { return(this.GroupingStrategy.GetGroups(parms)); } }
public override IList <OLVGroup> GetGroups(GroupingParameters parmameters) { // set parameters for what we want (lul parma) parmameters.SortItemsByPrimaryColumn = false; parmameters.PrimarySort = m_pSortProperties.SortColumn; parmameters.PrimarySortOrder = m_pSortProperties.SortOrder; // hardcore secondary sort parmameters.SecondarySort = m_pSortProperties.SortColumnSecondary; parmameters.SecondarySortOrder = SortOrder.Ascending; // do the real work thx return(base.GetGroups(parmameters)); }
public virtual IList <OLVGroup> GetGroups(GroupingParameters parameters) { return(new List <OLVGroup>()); }
public override IList <OLVGroup> GetGroups(GroupingParameters parms) { // This strategy can only be used on FastObjectListViews FastObjectListView folv = (FastObjectListView)parms.ListView; // Separate the list view items into groups, using the group key as the descrimanent int objectCount = 0; NullableDictionary <object, List <object> > map = new NullableDictionary <object, List <object> >(); foreach (object model in folv.Objects) { object key = parms.GroupByColumn.GetGroupKey(model); if (!map.ContainsKey(key)) { map[key] = new List <object>(); } map[key].Add(model); objectCount++; } // Sort the items within each group OLVColumn primarySortColumn = parms.SortItemsByPrimaryColumn ? parms.ListView.GetColumn(0) : parms.PrimarySort; ModelObjectComparer sorter = new ModelObjectComparer(primarySortColumn, parms.PrimarySortOrder, parms.SecondarySort, parms.SecondarySortOrder); foreach (object key in map.Keys) { map[key].Sort(sorter); } // Make a list of the required groups List <OLVGroup> groups = new List <OLVGroup>(); foreach (object key in map.Keys) { string title = parms.GroupByColumn.ConvertGroupKeyToTitle(key); if (!String.IsNullOrEmpty(parms.TitleFormat)) { int count = map[key].Count; title = String.Format((count == 1 ? parms.TitleSingularFormat : parms.TitleFormat), title, count); } OLVGroup lvg = new OLVGroup(title); lvg.Key = key; lvg.SortValue = key as IComparable; lvg.Contents = map[key].ConvertAll <int>(delegate(object x) { return(folv.IndexOf(x)); }); lvg.VirtualItemCount = map[key].Count; if (parms.GroupByColumn.GroupFormatter != null) { parms.GroupByColumn.GroupFormatter(lvg, parms); } groups.Add(lvg); } // Sort the groups groups.Sort(new OLVGroupComparer(parms.PrimarySortOrder)); // Build an array that remembers which group each item belongs to. this.indexToGroupMap = new List <int>(objectCount); this.indexToGroupMap.AddRange(new int[objectCount]); for (int i = 0; i < groups.Count; i++) { OLVGroup group = groups[i]; List <int> members = (List <int>)group.Contents; foreach (int j in members) { this.indexToGroupMap[j] = i; } } return(groups); }
/// <summary> /// Make a list of groups that should be shown according to the given parameters /// </summary> /// <param name="parms"></param> /// <returns></returns> protected override IList<OLVGroup> MakeGroups(GroupingParameters parms) { if (this.GroupingStrategy == null) return new List<OLVGroup>(); else return this.GroupingStrategy.GetGroups(parms); }
public CreateGroupsEventArgs(GroupingParameters parms) { this.parameters = parms; }
/// <summary> Run a solr query against the solr document index </summary> /// <param name="QueryString"> Solr query string </param> /// <param name="SearchOptions"> Options related to this search, like the page, results per page, facets, fields, etc.. </param> /// <param name="UserMembership"> User-specific membership information, related to a search, which can be used to determine which items this user can discover</param> /// <param name="Tracer"> Trace object keeps a list of each method executed and important milestones in rendering </param> /// <param name="Complete_Result_Set_Info"> [OUT] Information about the entire set of results </param> /// <param name="Paged_Results"> [OUT] List of search results for the requested page of results </param> /// <returns> Page search result object with all relevant result information </returns> public static bool Run_Query(string QueryString, Search_Options_Info SearchOptions, Search_User_Membership_Info UserMembership, Custom_Tracer Tracer, out Search_Results_Statistics Complete_Result_Set_Info, out List <iSearch_Title_Result> Paged_Results) { // If the query string is empty, then set it back to *:* if (QueryString.Trim().Length == 0) { QueryString = "*:*"; } // Set output initially to null Paged_Results = new List <iSearch_Title_Result>(); Complete_Result_Set_Info = null; try { // Ensure page is not erroneously set to zero or negative int pageNumber = SearchOptions.Page; if (pageNumber <= 0) { pageNumber = 1; } // Get and clean the solr document url string solrDocumentUrl = Engine_ApplicationCache_Gateway.Settings.Servers.Document_Solr_Index_URL; if ((!String.IsNullOrEmpty(solrDocumentUrl)) && (solrDocumentUrl[solrDocumentUrl.Length - 1] == '/')) { solrDocumentUrl = solrDocumentUrl.Substring(0, solrDocumentUrl.Length - 1); } // Create the solr worker to query the document index var solrWorker = Solr_Operations_Cache <v5_SolrDocument> .GetSolrOperations(solrDocumentUrl); // Get the list of fields List <string> fields = new List <string> { "did", "mainthumb", "title" }; fields.AddRange(SearchOptions.Fields.Select(MetadataField => MetadataField.SolrCode)); // Create the query options QueryOptions options = new QueryOptions { Rows = SearchOptions.ResultsPerPage, Start = (pageNumber - 1) * SearchOptions.ResultsPerPage, Fields = fields }; // Was there full text search in that? if ((QueryString.Contains("(fulltext:")) && (SearchOptions.IncludeFullTextSnippets)) { options.Highlight = new HighlightingParameters { Fields = new[] { "fulltext" }, Fragsize = 255 }; options.ExtraParams = new Dictionary <string, string> { { "hl.useFastVectorHighlighter", "true" }, { "wt", "xml" } }; } else { // We still need to instruct SOLR to return the results as XML for solr to parse it options.ExtraParams = new KeyValuePair <string, string>[] { new KeyValuePair <string, string>("wt", "xml") }; } // If the search stats are needed, let's get the facets if ((SearchOptions.Facets != null) && (SearchOptions.Facets.Count > 0)) { // Create the query facters options.Facet = new FacetParameters(); foreach (Complete_Item_Aggregation_Metadata_Type facet in SearchOptions.Facets) { options.Facet.Queries.Add(new SolrFacetFieldQuery(facet.SolrCode) { MinCount = 1, Limit = 100 }); } } // Set the sort value if (SearchOptions.Sort != 0) { options.OrderBy.Clear(); switch (SearchOptions.Sort) { case 1: options.OrderBy.Add(new SortOrder("title.sort", Order.ASC)); break; case 2: options.OrderBy.Add(new SortOrder("bibid", Order.ASC)); break; case 3: options.OrderBy.Add(new SortOrder("bibid", Order.DESC)); break; case 10: options.OrderBy.Add(new SortOrder("date.gregorian", Order.ASC)); break; case 11: options.OrderBy.Add(new SortOrder("date.gregorian", Order.DESC)); break; case 12: options.OrderBy.Add(new SortOrder("timeline_date", Order.ASC)); // If sorting by this, only get records with timeline date QueryString = "(" + QueryString + ") AND timeline_date:[* TO *]"; break; } } // Should this be grouped? bool grouped_results = false; if ((SearchOptions.GroupItemsByTitle) && (SearchOptions.Sort < 10) && (QueryString.IndexOf("fulltext") < 0)) { if (Tracer != null) { Tracer.Add_Trace("v5_Solr_Documents_Searcher.Run_Query", "Grouping search request by bibid"); } grouped_results = true; GroupingParameters groupingParams = new GroupingParameters { Fields = new[] { "bibid" }, Format = GroupingFormat.Grouped, Limit = 10, Ngroups = true }; options.Grouping = groupingParams; } // Log the search term if (Tracer != null) { Tracer.Add_Trace("v5_Solr_Documents_Searcher.Run_Query", "Solr Query: " + QueryString); } if (Tracer != null) { Tracer.Add_Trace("v5_Solr_Documents_Searcher.Run_Query", "Perform the search"); } // Perform this search SolrQueryResults <v5_SolrDocument> results = solrWorker.Query(QueryString, options); if (Tracer != null) { Tracer.Add_Trace("v5_Solr_Documents_Searcher.Run_Query", "Build the results object"); } // Create the search statistcs (this part assumes no grouping, and then we fix the count shortly) List <string> metadataLabels = SearchOptions.Fields.Select(MetadataType => MetadataType.DisplayTerm).ToList(); Complete_Result_Set_Info = new Search_Results_Statistics(metadataLabels) { Total_Titles = results.NumFound, Total_Items = results.NumFound, QueryTime = results.Header.QTime }; // If the search stats were needed, get the facets out if ((SearchOptions.Facets != null) && (SearchOptions.Facets.Count > 0)) { // Copy over all the facets foreach (Complete_Item_Aggregation_Metadata_Type facetTerm in SearchOptions.Facets) { // Create the collection and and assifn the metadata type id Search_Facet_Collection thisCollection = new Search_Facet_Collection(facetTerm.ID); // Add each value foreach (var facet in results.FacetFields[facetTerm.SolrCode]) { thisCollection.Facets.Add(new Search_Facet(facet.Key, facet.Value)); } // If there was an id and facets added, save this to the search statistics if ((thisCollection.MetadataTypeID > 0) && (thisCollection.Facets.Count > 0)) { Complete_Result_Set_Info.Facet_Collections.Add(thisCollection); } } } // Build the results mapper object v5_SolrDocument_Results_Mapper mapper = new v5_SolrDocument_Results_Mapper(); // Build the results differently, depending on whether they were grouped or not if (grouped_results) { // Get the grouped results (only grouped by bibid) GroupedResults <v5_SolrDocument> title_groupings = results.Grouping["bibid"]; // Now step through each group (i.e., titles/bibs) in the groups foreach (Group <v5_SolrDocument> grouping in title_groupings.Groups) { // Convert the grouping to the new result v5_Solr_Title_Result newResult = mapper.Map_To_Result(grouping, SearchOptions.Fields); Paged_Results.Add(newResult); } // Now, fix the stats as well Complete_Result_Set_Info.Total_Items = title_groupings.Matches; Complete_Result_Set_Info.Total_Titles = title_groupings.Ngroups.Value; } else { // Pass all the results into the List and add the highlighted text to each result as well foreach (v5_SolrDocument thisResult in results) { // Convert to the new result v5_Solr_Title_Result newResult = mapper.Map_To_Result(thisResult, SearchOptions.Fields); // Add the highlight snippet, if applicable if ((results.Highlights != null) && (results.Highlights.ContainsKey(thisResult.DID)) && (results.Highlights[thisResult.DID].Count > 0) && (results.Highlights[thisResult.DID].ElementAt(0).Value.Count > 0)) { newResult.Snippet = results.Highlights[thisResult.DID].ElementAt(0).Value.ElementAt(0); } Paged_Results.Add(newResult); } } return(true); } catch (Exception ee) { return(false); } }
/// <summary> /// Return the list of groups that should be shown according to the given parameters /// </summary> /// <param name="parameters"></param> /// <returns></returns> public virtual IList<OLVGroup> GetGroups(GroupingParameters parameters) { return new List<OLVGroup>(); }
/// <summary> /// Create groups for FastListView /// </summary> /// <param name="parmameters"></param> /// <returns></returns> public override IList<OLVGroup> GetGroups(GroupingParameters parmameters) { // This strategy can only be used on FastObjectListViews FastObjectListView folv = (FastObjectListView)parmameters.ListView; // Separate the list view items into groups, using the group key as the descrimanent int objectCount = 0; NullableDictionary<object, List<object>> map = new NullableDictionary<object, List<object>>(); foreach (object model in folv.FilteredObjects) { object key = parmameters.GroupByColumn.GetGroupKey(model); if (!map.ContainsKey(key)) map[key] = new List<object>(); map[key].Add(model); objectCount++; } // Sort the items within each group OLVColumn primarySortColumn = parmameters.SortItemsByPrimaryColumn ? parmameters.ListView.GetColumn(0) : parmameters.PrimarySort; ModelObjectComparer sorter = new ModelObjectComparer(primarySortColumn, parmameters.PrimarySortOrder, parmameters.SecondarySort, parmameters.SecondarySortOrder); foreach (object key in map.Keys) { map[key].Sort(sorter); } // Make a list of the required groups List<OLVGroup> groups = new List<OLVGroup>(); foreach (object key in map.Keys) { string title = parmameters.GroupByColumn.ConvertGroupKeyToTitle(key); if (!String.IsNullOrEmpty(parmameters.TitleFormat)) { int count = map[key].Count; title = String.Format((count == 1 ? parmameters.TitleSingularFormat : parmameters.TitleFormat), title, count); } OLVGroup lvg = new OLVGroup(title); lvg.Key = key; lvg.SortValue = key as IComparable; lvg.Contents = map[key].ConvertAll<int>(delegate(object x) { return folv.IndexOf(x); }); lvg.VirtualItemCount = map[key].Count; if (parmameters.GroupByColumn.GroupFormatter != null) parmameters.GroupByColumn.GroupFormatter(lvg, parmameters); groups.Add(lvg); } // Sort the groups groups.Sort(new OLVGroupComparer(parmameters.PrimarySortOrder)); // Build an array that remembers which group each item belongs to. this.indexToGroupMap = new List<int>(objectCount); this.indexToGroupMap.AddRange(new int[objectCount]); for (int i = 0; i < groups.Count; i++) { OLVGroup group = groups[i]; List<int> members = (List<int>)group.Contents; foreach (int j in members) this.indexToGroupMap[j] = i; } return groups; }