@@ -149,6 +149,90 @@ public async Task SearchDocuments_WithFilter_ShouldReturnResults()
149149 await indexClient . DeleteIndexAsync ( indexName ) ;
150150 }
151151
152+ [ Fact ]
153+ public async Task SearchDocuments_WithFilter_OnSearchableStringField_ShouldReturnResults ( )
154+ {
155+ // Regression test for issue #27: filtering a Searchable+Filterable string field
156+ // must work. Before the fix, the analyzer lowercased 'Electronics' at index time
157+ // and the exact TermQuery at filter time found zero hits.
158+ const string indexName = "test-filter-searchable-string" ;
159+ var indexClient = factory . CreateSearchIndexClient ( ) ;
160+ var searchClient = factory . CreateSearchClient ( indexName ) ;
161+
162+ await CreateIndexAsync ( indexClient , indexName ) ;
163+ await UploadDocumentsAsync ( searchClient ) ;
164+
165+ var options = new SearchOptions
166+ {
167+ Filter = "Category eq 'Electronics'" ,
168+ Size = 50
169+ } ;
170+ var results = await searchClient . SearchAsync < Product > ( "*" , options ) ;
171+
172+ Assert . NotNull ( results ) ;
173+ var items = await results . Value . GetResultsAsync ( ) . ToListAsync ( ) ;
174+ Assert . NotEmpty ( items ) ;
175+ Assert . True ( items . All ( r => r . Document . Category == "Electronics" ) ,
176+ "All results should have Category = Electronics" ) ;
177+
178+ await indexClient . DeleteIndexAsync ( indexName ) ;
179+ }
180+
181+ [ Fact ]
182+ public async Task SearchDocuments_SearchOnDualIndexedField_StillMatchesAnalyzedTokens ( )
183+ {
184+ // Dual-indexing (TextField + StringField under same name) must not break
185+ // full-text search: a tokenized search for 'electronics' must still match.
186+ const string indexName = "test-search-on-dual-indexed" ;
187+ var indexClient = factory . CreateSearchIndexClient ( ) ;
188+ var searchClient = factory . CreateSearchClient ( indexName ) ;
189+
190+ await CreateIndexAsync ( indexClient , indexName ) ;
191+ await UploadDocumentsAsync ( searchClient ) ;
192+
193+ var options = new SearchOptions { SearchFields = { "Category" } , Size = 50 } ;
194+ var results = await searchClient . SearchAsync < Product > ( "electronics" , options ) ;
195+ var items = await results . Value . GetResultsAsync ( ) . ToListAsync ( ) ;
196+
197+ Assert . NotEmpty ( items ) ;
198+ Assert . True ( items . All ( r => r . Document . Category == "Electronics" ) ) ;
199+
200+ await indexClient . DeleteIndexAsync ( indexName ) ;
201+ }
202+
203+ [ Fact ]
204+ public async Task SearchDocuments_FilterOnNonFilterableField_ShouldError ( )
205+ {
206+ // Azure rejects $filter against a non-filterable field; the emulator should too.
207+ const string indexName = "test-filter-nonfilterable" ;
208+ var indexClient = factory . CreateSearchIndexClient ( ) ;
209+ var searchClient = factory . CreateSearchClient ( indexName ) ;
210+
211+ var index = new SearchIndex ( indexName )
212+ {
213+ Fields =
214+ [
215+ new SearchField ( nameof ( Product . Id ) , SearchFieldDataType . String ) { IsKey = true , IsStored = true , IsSearchable = true , IsFilterable = true } ,
216+ new SearchField ( nameof ( Product . Name ) , SearchFieldDataType . String ) { IsSearchable = true , IsFilterable = false , IsStored = true } ,
217+ new SearchField ( nameof ( Product . Description ) , SearchFieldDataType . String ) { IsSearchable = true , IsStored = true } ,
218+ new SearchField ( nameof ( Product . Price ) , SearchFieldDataType . Double ) { IsFilterable = true , IsSortable = true , IsStored = true } ,
219+ new SearchField ( nameof ( Product . Category ) , SearchFieldDataType . String ) { IsSearchable = true , IsFilterable = true , IsStored = true } ,
220+ new SearchField ( nameof ( Product . InStock ) , SearchFieldDataType . Boolean ) { IsFilterable = true , IsStored = true }
221+ ]
222+ } ;
223+ await indexClient . CreateIndexAsync ( index ) ;
224+ await UploadDocumentsAsync ( searchClient ) ;
225+
226+ var options = new SearchOptions { Filter = "Name eq 'Laptop Pro 15'" , Size = 50 } ;
227+ await Assert . ThrowsAnyAsync < Exception > ( async ( ) =>
228+ {
229+ var results = await searchClient . SearchAsync < Product > ( "*" , options ) ;
230+ await results . Value . GetResultsAsync ( ) . ToListAsync ( ) ;
231+ } ) ;
232+
233+ await indexClient . DeleteIndexAsync ( indexName ) ;
234+ }
235+
152236 [ Fact ]
153237 public async Task SearchDocuments_WithSorting_ShouldReturnSortedResults ( )
154238 {
@@ -464,7 +548,7 @@ private static async Task<SearchIndex> CreateIndexAsync(SearchIndexClient indexC
464548 new SearchField ( nameof ( Product . Name ) , SearchFieldDataType . String ) { IsSearchable = true , IsStored = true } ,
465549 new SearchField ( nameof ( Product . Description ) , SearchFieldDataType . String ) { IsSearchable = true , IsStored = true } ,
466550 new SearchField ( nameof ( Product . Price ) , SearchFieldDataType . Double ) { IsFilterable = true , IsSortable = true , IsStored = true } ,
467- new SearchField ( nameof ( Product . Category ) , SearchFieldDataType . String ) { IsFilterable = true , IsStored = true } ,
551+ new SearchField ( nameof ( Product . Category ) , SearchFieldDataType . String ) { IsSearchable = true , IsFilterable = true , IsStored = true } ,
468552 new SearchField ( nameof ( Product . InStock ) , SearchFieldDataType . Boolean ) { IsFilterable = true , IsStored = true }
469553 ]
470554 } ;
0 commit comments