//public bool IsPropRow( DataRow DataRow ) { return ( _CswNbtNodePropData.Row == DataRow ); } /// <summary> /// True if the property must must be unique /// </summary> public bool IsUnique() { return(_CswNbtMetaDataNodeTypeProp.IsUnique()); }
/// <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()