@@ -6,21 +6,10 @@ namespace NRedisStack
66{
77 public class SearchCommands : SearchCommandsAsync , ISearchCommands
88 {
9- IDatabase _db ;
10- public SearchCommands ( IDatabase db , int ? defaultDialect ) : base ( db )
9+ private IDatabase _db ;
10+ public SearchCommands ( IDatabase db , int ? defaultDialect = 2 ) : base ( db , defaultDialect )
1111 {
1212 _db = db ;
13- SetDefaultDialect ( defaultDialect ) ;
14- this . defaultDialect = defaultDialect ;
15- }
16-
17- public void SetDefaultDialect ( int ? defaultDialect )
18- {
19- if ( defaultDialect == 0 )
20- {
21- throw new System . ArgumentOutOfRangeException ( "DIALECT=0 cannot be set." ) ;
22- }
23- this . defaultDialect = defaultDialect ;
2413 }
2514
2615 /// <inheritdoc/>
@@ -32,11 +21,7 @@ public RedisResult[] _List()
3221 /// <inheritdoc/>
3322 public AggregationResult Aggregate ( string index , AggregationRequest query )
3423 {
35- if ( query . dialect == null && defaultDialect != null )
36- {
37- query . Dialect ( ( int ) defaultDialect ) ;
38- }
39-
24+ setDefaultDialectIfUnset ( query ) ;
4025 var result = _db . Execute ( SearchCommandBuilder . Aggregate ( index , query ) ) ;
4126 return result . ToAggregationResult ( query ) ;
4227 }
@@ -130,20 +115,14 @@ public bool DropIndex(string indexName, bool dd = false)
130115 /// <inheritdoc/>
131116 public string Explain ( string indexName , string query , int ? dialect = null )
132117 {
133- if ( dialect == null && defaultDialect != null )
134- {
135- dialect = defaultDialect ;
136- }
118+ dialect = checkAndGetDefaultDialect ( dialect ) ;
137119 return _db . Execute ( SearchCommandBuilder . Explain ( indexName , query , dialect ) ) . ToString ( ) ! ;
138120 }
139121
140122 /// <inheritdoc/>
141123 public RedisResult [ ] ExplainCli ( string indexName , string query , int ? dialect = null )
142124 {
143- if ( dialect == null && defaultDialect != null )
144- {
145- dialect = defaultDialect ;
146- }
125+ dialect = checkAndGetDefaultDialect ( dialect ) ;
147126 return _db . Execute ( SearchCommandBuilder . ExplainCli ( indexName , query , dialect ) ) . ToArray ( ) ;
148127 }
149128
@@ -160,22 +139,21 @@ public Tuple<SearchResult, Dictionary<string, RedisResult>> ProfileSearch(string
160139 /// <inheritdoc/>
161140 public Tuple < AggregationResult , Dictionary < string , RedisResult > > ProfileAggregate ( string indexName , AggregationRequest query , bool limited = false )
162141 {
142+ setDefaultDialectIfUnset ( query ) ;
163143 return _db . Execute ( SearchCommandBuilder . ProfileAggregate ( indexName , query , limited ) )
164144 . ToProfileAggregateResult ( query ) ;
165145 }
166146 /// <inheritdoc/>
167147 public SearchResult Search ( string indexName , Query q )
168148 {
169- if ( q . dialect == null && defaultDialect != null )
170- {
171- q . Dialect ( ( int ) defaultDialect ) ;
172- }
149+ setDefaultDialectIfUnset ( q ) ;
173150 return _db . Execute ( SearchCommandBuilder . Search ( indexName , q ) ) . ToSearchResult ( q ) ;
174151 }
175152
176153 /// <inheritdoc/>
177154 public Dictionary < string , Dictionary < string , double > > SpellCheck ( string indexName , string query , FTSpellCheckParams ? spellCheckParams = null )
178155 {
156+ setDefaultDialectIfUnset ( spellCheckParams ) ;
179157 return _db . Execute ( SearchCommandBuilder . SpellCheck ( indexName , query , spellCheckParams ) ) . ToFtSpellCheckResult ( ) ;
180158 }
181159
0 commit comments