77using NRedisStack . CountMinSketch . DataTypes ;
88using NRedisStack . TopK . DataTypes ;
99using NRedisStack . Tdigest . DataTypes ;
10+ using NRedisStack . Search ;
11+ using NRedisStack . Search . Aggregation ;
1012
1113namespace NRedisStack
1214{
@@ -614,6 +616,92 @@ public static IEnumerable<HashSet<string>> ToHashSets(this RedisResult result)
614616 return sets ;
615617 }
616618
619+ public static Dictionary < string , Dictionary < string , double > > ToFtSpellCheckResult ( this RedisResult result )
620+ {
621+ var rawTerms = ( RedisResult [ ] ) result ! ;
622+ var returnTerms = new Dictionary < string , Dictionary < string , double > > ( rawTerms . Length ) ;
623+ foreach ( var term in rawTerms )
624+ {
625+ var rawElements = ( RedisResult [ ] ) term ! ;
626+
627+ string termValue = rawElements [ 1 ] . ToString ( ) ! ;
628+
629+ var list = ( RedisResult [ ] ) rawElements [ 2 ] ! ;
630+ Dictionary < string , double > entries = new Dictionary < string , double > ( list . Length ) ;
631+ foreach ( var entry in list )
632+ {
633+ var entryElements = ( RedisResult [ ] ) entry ! ;
634+ string suggestion = entryElements [ 1 ] . ToString ( ) ! ;
635+ double score = ( double ) entryElements [ 0 ] ;
636+ entries . Add ( suggestion , score ) ;
637+ }
638+ returnTerms . Add ( termValue , entries ) ;
639+ }
640+
641+ return returnTerms ;
642+ }
643+
644+ public static List < Tuple < string , double > > ToStringDoubleTupleList ( this RedisResult result ) // TODO: consider create class Suggestion instead of List<Tuple<string, double>>
645+ {
646+ var results = ( RedisResult [ ] ) result ! ;
647+ var list = new List < Tuple < string , double > > ( results . Length / 2 ) ;
648+ for ( int i = 0 ; i < results . Length ; i += 2 )
649+ {
650+ var suggestion = results [ i ] . ToString ( ) ! ;
651+ var score = ( double ) results [ i + 1 ] ;
652+ list . Add ( new Tuple < string , double > ( suggestion , score ) ) ;
653+ }
654+ return list ;
655+ }
656+
657+ public static Dictionary < string , RedisResult > ToStringRedisResultDictionary ( this RedisResult value )
658+ {
659+ var res = ( RedisResult [ ] ) value ! ;
660+ var dict = new Dictionary < string , RedisResult > ( ) ;
661+ foreach ( var pair in res )
662+ {
663+ var arr = ( RedisResult [ ] ) pair ! ;
664+ dict . Add ( arr [ 0 ] . ToString ( ) , arr [ 1 ] ) ;
665+ }
666+ return dict ;
667+ }
668+
669+ public static Tuple < SearchResult , Dictionary < string , RedisResult > > ToProfileSearchResult ( this RedisResult result , Query q )
670+ {
671+ var results = ( RedisResult [ ] ) result ! ;
672+
673+ var searchResult = results [ 0 ] . ToSearchResult ( q ) ;
674+ var profile = results [ 1 ] . ToStringRedisResultDictionary ( ) ;
675+ return new Tuple < SearchResult , Dictionary < string , RedisResult > > ( searchResult , profile ) ;
676+ }
677+
678+ public static SearchResult ToSearchResult ( this RedisResult result , Query q )
679+ {
680+ return new SearchResult ( ( RedisResult [ ] ) result ! , ! q . NoContent , q . WithScores , q . WithPayloads /*, q.ExplainScore*/ ) ;
681+ }
682+
683+ public static Tuple < AggregationResult , Dictionary < string , RedisResult > > ToProfileAggregateResult ( this RedisResult result , AggregationRequest q )
684+ {
685+ var results = ( RedisResult [ ] ) result ! ;
686+ var aggregateResult = results [ 0 ] . ToAggregationResult ( q ) ;
687+ var profile = results [ 1 ] . ToStringRedisResultDictionary ( ) ;
688+ return new Tuple < AggregationResult , Dictionary < string , RedisResult > > ( aggregateResult , profile ) ;
689+ }
690+
691+ public static AggregationResult ToAggregationResult ( this RedisResult result , AggregationRequest query )
692+ {
693+ if ( query . IsWithCursor ( ) )
694+ {
695+ var results = ( RedisResult [ ] ) result ! ;
696+
697+ return new AggregationResult ( results [ 0 ] , ( long ) results [ 1 ] ) ;
698+ }
699+ else
700+ {
701+ return new AggregationResult ( result ) ;
702+ }
703+ }
704+
617705 public static Dictionary < string , RedisResult > [ ] ToDictionarys ( this RedisResult result )
618706 {
619707 var resArr = ( RedisResult [ ] ) result ! ;
@@ -624,6 +712,7 @@ public static Dictionary<string, RedisResult>[] ToDictionarys(this RedisResult r
624712 }
625713
626714 return dicts ;
715+
627716 }
628717 }
629718}
0 commit comments