public TableCriteriaForMappingByValue(TableMappingByValue <TRow, TSearch, TColumn, TCriteria> mapping, SearchCriteria <TColumn> criteria) { _mapping = mapping; _metaData = _mapping.MetaData; _criteria = criteria; Score = GetScore(_metaData, criteria); }
public override TableCriteriaScore GetScore <TRow>(TableMappingMetaData <TRow, TColumn> metaData) { if (SearchValues.Length == 0) { return(new TableCriteriaScore(1, false)); } return(new TableCriteriaScore(SearchValues.Length / (float)metaData.PossibleValues.Length, true)); }
public override TableCriteriaScore GetScore <TRow>(TableMappingMetaData <TRow, TColumn> metaData) { var resultRange = new BinarySearchTable <TColumn>(metaData.PossibleValues).ReduceByRange(x => x, Start, End, metaData.Comparer); var nbResults = resultRange.TotalCount; if (nbResults == 0) { return(TableCriteriaScore.Impossible); } return(new TableCriteriaScore((float)nbResults / metaData.PossibleValues.Length, PreserveSearchability)); }
public override SearchCriteria <TColumn> Optimize <TRow>(TableMappingMetaData <TRow, TColumn> metaData) { switch (SearchValues.Length) { case 0: return(null); case 1: return(this); } // Try to remove duplicate search values return(ByValues(SearchValues.Distinct(metaData.EqualityComparer).ToArray())); }
private static TableCriteriaScore GetScore(TableMappingMetaData <TRow, TColumn> metaData, SearchCriteria <TColumn> criteria) { // There are no values, will always return an empty set if (metaData.PossibleValues.Length == 0) { return(TableCriteriaScore.Impossible); } // No criteria or criteria contains no value, we ignore the criteria if (criteria == null) { return(TableCriteriaScore.NotOptimizable); } return(criteria.GetScore(metaData)); }
public override SearchCriteria <TColumn> Optimize <TRow>(TableMappingMetaData <TRow, TColumn> metaData) { if (metaData.Comparer.Compare(Start, End) == 0) { return(ByValues(Start)); } var resultRange = new BinarySearchTable <TColumn>(metaData.PossibleValues).ReduceByRange(x => x, Start, End, metaData.Comparer); var nbResults = resultRange.TotalCount; if (nbResults <= 1) { return(ByValues(resultRange.Materialize())); } if (nbResults < 10) { return(new SearchCriteriaByRange <TColumn>(Start, End, true)); } return(this); }
public override BinarySearchTable <TRow> Reduce <TRow>(BinarySearchTable <TRow> rows, TableMappingMetaData <TRow, TColumn> metaData) { return(rows.ReduceByValues(metaData.GetTargetValue, SearchValues, metaData.Comparer)); }
public override BinarySearchTable <TRow> Reduce <TRow>(BinarySearchTable <TRow> rows, TableMappingMetaData <TRow, TColumn> metaData) { return(rows.ReduceByRange(metaData.GetTargetValue, Start, End, metaData.Comparer, PreserveSearchability)); }
public override TableCriteriaScore GetScore <TRow>(TableMappingMetaData <TRow, TColumn> metaData) { return(TableCriteriaScore.NotOptimizable); }
public override SearchCriteria <TColumn> Optimize <TRow>(TableMappingMetaData <TRow, TColumn> metaData) { return(this); }
public override BinarySearchTable <TRow> Reduce <TRow>(BinarySearchTable <TRow> rows, TableMappingMetaData <TRow, TColumn> metaData) { return(null); }