private CswNbtSearchFilter makeFilter(CswNbtMetaDataNodeTypeProp NodeTypeProp, string Value, Int32 ResultCount, bool Removeable, CswEnumNbtSearchPropOrderSourceType Source) { CswNbtSearchFilter ret = new CswNbtSearchFilter(NodeTypeProp.PropName, CswEnumNbtSearchFilterType.propval, NodeTypeProp.PropId.ToString() + "_" + Value, Value, ResultCount, string.Empty, Removeable, Source); ret.FirstPropVersionId = NodeTypeProp.FirstPropVersionId; return(ret); }
private CswNbtSearchFilter makeFilter(CswNbtMetaDataPropertySet PropertySet, Int32 ResultCount, bool Removeable, CswEnumNbtSearchPropOrderSourceType Source) { CswNbtSearchFilter ret = new CswNbtSearchFilter("Filter To", CswEnumNbtSearchFilterType.propertyset, "PS_" + PropertySet.PropertySetId.ToString(), "All " + PropertySet.Name, ResultCount, PropertySet.IconFileName, Removeable, Source); ret.PropertySetId = PropertySet.PropertySetId; ret.UseMoreLink = false; return(ret); }
private CswNbtSearchFilter makeFilter(CswNbtMetaDataObjectClass ObjectClass, Int32 ResultCount, bool Removeable, CswEnumNbtSearchPropOrderSourceType Source) { CswNbtSearchFilter ret = new CswNbtSearchFilter("Filter To", CswEnumNbtSearchFilterType.objectclass, "OC_" + ObjectClass.ObjectClassId.ToString(), "All " + ObjectClass.ObjectClass.ToString(), ResultCount, ObjectClass.IconFileName, Removeable, Source); ret.ObjectClassId = ObjectClass.ObjectClassId; ret.UseMoreLink = false; return(ret); }
} // FilterOptions() private CswNbtSearchFilter makeFilter(CswNbtMetaDataNodeType NodeType, Int32 ResultCount, bool Removeable, CswEnumNbtSearchPropOrderSourceType Source) { CswNbtSearchFilter ret = new CswNbtSearchFilter("Filter To", CswEnumNbtSearchFilterType.nodetype, "NT_" + NodeType.NodeTypeId.ToString(), NodeType.NodeTypeName, ResultCount, NodeType.IconFileName, Removeable, Source); ret.FirstVersionId = NodeType.FirstVersionNodeTypeId; ret.UseMoreLink = false; return(ret); }
} // removeFilter() public void removeFilter(CswNbtSearchFilter Filter) { if (Filter.Type == CswEnumNbtSearchFilterType.nodetype) { // Clear all filters FiltersApplied.Clear(); } else { Collection <CswNbtSearchFilter> FiltersToRemove = new Collection <CswNbtSearchFilter>(); foreach (CswNbtSearchFilter MatchingFilterObj in FiltersApplied.Where(AppliedFilter => AppliedFilter == Filter)) { FiltersToRemove.Add(MatchingFilterObj); } foreach (CswNbtSearchFilter DoomedFilter in FiltersToRemove) { FiltersApplied.Remove(DoomedFilter); } } _FilteredPropIds = null; } // removeFilter()
/// <summary> /// New Filters to offer, based on Results /// </summary> public JArray FilterOptions(ICswNbtTree Tree) { JArray FiltersArr = new JArray(); Tree.goToRoot(); bool SingleNodeType = IsSingleNodeType(); if (false == SingleNodeType) { // Filter on NodeTypes only SortedList <string, NodeTypeEntry> NodeTypeOptions = new SortedList <string, NodeTypeEntry>(); Int32 ChildCnt = Tree.getChildNodeCount(); for (Int32 n = 0; n < ChildCnt; n++) { Tree.goToNthChild(n); CswNbtNodeKey NodeKey = Tree.getNodeKeyForCurrentPosition(); if (NodeKey != null) { CswNbtMetaDataNodeType NodeType = _CswNbtResources.MetaData.getNodeType(NodeKey.NodeTypeId); string LatestName = NodeType.getNodeTypeLatestVersion().NodeTypeName; if (false == NodeTypeOptions.ContainsKey(LatestName)) { NodeTypeOptions.Add(LatestName, new NodeTypeEntry { NodeType = NodeType, NodeTypeId = NodeType.NodeTypeId, LatestName = LatestName, Count = 0 }); } NodeTypeOptions[LatestName].Count += 1; } Tree.goToParentNode(); } // for( Int32 n = 0; n < ChildCnt; n++ ) if (NodeTypeOptions.Keys.Count == 1) { if (false == IsSingleNodeType()) { // If we have uniform results but no nodetype filter applied // add the filter to the filters list for display NodeTypeEntry entry = NodeTypeOptions.Values[0]; CswNbtSearchFilter NodeTypeFilter = makeFilter(entry.NodeType, entry.Count, false, CswEnumNbtSearchPropOrderSourceType.Unknown); addFilter(NodeTypeFilter); } SingleNodeType = true; } else { JArray FilterSet = new JArray(); FiltersArr.Add(FilterSet); foreach (NodeTypeEntry entry in NodeTypeOptions.Values) { CswNbtSearchFilter NodeTypeFilter = makeFilter(entry.NodeType, entry.Count, true, CswEnumNbtSearchPropOrderSourceType.Unknown); FilterSet.Add(NodeTypeFilter.ToJObject()); } } } // if( false == SingleNodeType ) if (SingleNodeType) { // Filter on property values in the results Collection <Int32> FilteredPropIds = getFilteredPropIds(); Dictionary <Int32, Dictionary <string, Int32> > PropCounts = new Dictionary <Int32, Dictionary <string, Int32> >(); SortedSet <CswNbtSearchPropOrder.SearchOrder> PropOrder = new SortedSet <CswNbtSearchPropOrder.SearchOrder>(); Int32 ChildCnt = Tree.getChildNodeCount(); for (Int32 n = 0; n < ChildCnt; n++) { Tree.goToNthChild(n); if (0 == PropOrder.Count) { PropOrder = _CswNbtSearchPropOrder.getPropOrderDict(Tree.getNodeKeyForCurrentPosition()); } Collection <CswNbtTreeNodeProp> Props = Tree.getChildNodePropsOfNode(); foreach (CswNbtTreeNodeProp Prop in Props) { CswNbtMetaDataFieldType FieldType = _CswNbtResources.MetaData.getFieldType(Prop.FieldType); if (false == FilteredPropIds.Contains(Prop.NodeTypePropId) && FieldType.Searchable) { string Gestalt = Prop.Gestalt; if (Gestalt.Length > 50) { Gestalt = Gestalt.Substring(0, 50); } if (false == PropCounts.ContainsKey(Prop.NodeTypePropId)) { PropCounts[Prop.NodeTypePropId] = new Dictionary <string, Int32>(); } if (false == PropCounts[Prop.NodeTypePropId].ContainsKey(Gestalt)) { PropCounts[Prop.NodeTypePropId][Gestalt] = 0; } PropCounts[Prop.NodeTypePropId][Gestalt] += 1; } } Tree.goToParentNode(); } // for( Int32 n = 0; n < ChildCnt; n++ ) foreach (Int32 NodeTypePropId in PropCounts.Keys.OrderBy(NodeTypePropId => PropOrder.First(Order => Order.NodeTypePropId == NodeTypePropId).Order)) { CswNbtMetaDataNodeTypeProp NodeTypeProp = _CswNbtResources.MetaData.getNodeTypePropLatestVersion(NodeTypePropId); if (false == NodeTypeProp.IsUnique()) // case 27649 { CswNbtSearchPropOrder.SearchOrder order = PropOrder.First(Order => Order.NodeTypePropId == NodeTypePropId); JArray FilterSet = new JArray(); FiltersArr.Add(FilterSet); // Sort by count descending, then alphabetically by gestalt Dictionary <string, Int32> sortedDict = (from entry in PropCounts[NodeTypePropId] orderby entry.Value descending, entry.Key ascending select entry ).ToDictionary(pair => pair.Key, pair => pair.Value); foreach (string Value in sortedDict.Keys) { Int32 Count = sortedDict[Value]; CswNbtSearchFilter Filter = makeFilter(NodeTypeProp, Value, Count, true, order.Source); FilterSet.Add(Filter.ToJObject()); } } // if( false == NodeTypeProp.IsUnique() ) } // foreach( Int32 NodeTypePropId in PropCounts.Keys.OrderBy( NodeTypePropId => PropOrder.First( Order => Order.NodeTypePropId == NodeTypePropId ).Order ) ) } // if( SingleNodeType ) return(FiltersArr); } // FilterOptions()
} // addNodeTypeFilter() public void addFilter(CswNbtSearchFilter Filter) { FiltersApplied.Add(Filter); _FilteredPropIds = null; } // addFilter()