Repository navigation
feat: let a search index's text mapping declare alternates - #84
Merged
Merged
Conversation
SearchField.String() couldn't declare multi, the alternate analyzers
MongoDB Search also indexes a string with, which a query picks by name
with path: { value, multi }. A field that needed one had to be written
whole with SearchField.Raw, or the whole index with Definition.
SearchField.Multi(name, alternate) returns the text mapping with one
more alternate, rendered as multi: { name: { type: "string", ... } },
as written by hand, so a declaration moved from Definition to Map
matches the index already on the server. MongoDB Search takes multi
only on text, of text alternates without alternates of their own, so
Multi throws ArgumentException otherwise, and for a name taken.
Closes #83
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #83.
SearchField.String(analyzer, searchAnalyzer)couldn't declaremulti: the alternate analyzers MongoDB Search also indexes a string with, and which a query picks by name withpath: { value, multi }. A field that needed one had to be written whole withSearchField.Raw, or the whole index withDefinition(BsonDocument). That's what keeps core's 12 search indexes on raw BSON: 134 of their 135 string fields carry akeywordalternate forwildcard.What it does
SearchField.Multi(name, alternate)returns the text mapping with one more alternate. Each call adds one, so a field can have several, and the mapping it's called on is left as it was:It renders
multi: { keyword: { type: "string", analyzer: "lucene.keyword" } }on the string mapping, exactly as core writes it by hand. A declaration moved fromDefinitiontoMapthen matches the index already on the server, and nothing is rebuilt. Comparing listed definitions already handledmulti, defaults filled into alternates included, so that needed no change.What MongoDB Search refuses,
Multirefuses up front withArgumentException. I checked each case against Atlas Local 8.3.4:multion a non-text mappingunrecognized field "multi"multi definition must be string fieldmulti definition cannot contain nested multi definitionMultialso throws for a name already taken or a blank one.docs/search.mdshowsMultiunder theSearchFieldtable, with awildcardthat picks the alternate throughSearchPath.Analyzer.Tests
SearchTests(integration, on Atlas Local and community-search):MigrateAllAsync_TextWithAnAlternateAsDeclared_LeavesItForSearchesToPick:wildcardofAda L*on thekeywordalternate finds Ada Lovelace;SearchFieldTests(unit):Multi_TextAlternates_AreWrittenUnderTheTextsMulti: two alternates, and one added to aRawmapping that has one already.Multi_OfAMapping_LeavesItAsItWasMulti_AlternateMongoDbCantTake_ThrowsArgumentException, which covers:Multi_NullAlternate_ThrowsArgumentNullExceptionSearchIndexBuilderTests(unit):SearchIndex_TextWithAnAlternate_IsMappedWithItBesideTheFieldsOtherMappings: the issue's example renders with the field's autocomplete and token mappings, and the features' fields.Ran locally on net10.0; CI runs net11.0 as well:
QueryAsync_JoinOn*_IsLeftToTheDrivertests, which fail only locally, against the InsurUp driver fork;SearchTests: all 48 pass on both servers.🤖 Generated with Claude Code