Repository navigation
Search message ids as phrases on the SQL Server persisters - #5976
Open
johnsimons wants to merge 1 commit into
Open
johnsimons wants to merge 1 commit into
johnsimons wants to merge 1 commit into
Conversation
WebSearchToTsQuery and FREETEXT split each search term into separate words, so searching for a message id like "billing-1234-5678" also matched any message whose id shared a hyphen-separated piece, e.g. "billing-9999-5678". Build each term as a quoted phrase instead (ToTsQuery on PostgreSQL, CONTAINS on SQL Server), escaping the characters that would otherwise break the query syntax, so a term only matches messages containing it in full. A trailing * still requests a prefix match, matching the RavenDB persister's behaviour.
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.
Searching for a message id on the SQL Server persisters now returns only the messages that contain the whole id. Before,
FREETEXTmatched every message that shared any piece of the id, and ServicePulse could not open the message. A trailing*is now a prefix search on SQL Server and PostgreSQL, as it already is on RavenDB.Analysis
FREETEXT.FREETEXTsplits the input at punctuation, adds other forms of each word, and returns the rows that contain any of the resulting words. A GUID ororder-1234-5678matched every message that shared one of its pieces.messages/search/{messageId}with the default paging (50 rows, newesttime_sentfirst) and looking for the row with the matchingid. With more than 50 matches the message is usually not on that page, and ServicePulse shows "Could not find message".background-noise-NNNN-...ids failed to open, and each search returned about 15,000 rows. On a 40,000-row table, a random GUID matched 124 rows withFREETEXTand 1 with a quotedCONTAINSphrase.websearch_to_tsqueryturns a hyphenated term into a phrase. They had two other gaps:websearch_to_tsquerydrops a trailing*, and it reads a leading-as NOT, sozzz OR -ordermatched every message without "order".Changes
EF.Functions.ContainsreplacesEF.Functions.FreeText. The dialect splits the input on spaces, wraps each term in double quotes with embedded quotes doubled, and joins the terms withOR. A quoted term is a phrase, so the words the word breaker splits it into must appear together and in order.CONTAINSreads the same full-text index and catalog, so there is no migration.to_tsqueryreplaceswebsearch_to_tsquery, with a query built from the input. Each term is quoted as a phrase, a term ending in*gets:*, and the terms are joined with|. Backslashes and quotes are escaped and a bare*is skipped, becauseto_tsqueryraises a syntax error on them. The tsvector expression is unchanged. EXPLAIN on a scratch GIN index shows a bitmap index scan for a query with|and:*.Behaviour changes
verifydoes not find "verified". RavenDB (StandardAnalyzer) and PostgreSQL (simpleconfiguration) never did.*is a prefix search on SQL Server and PostgreSQL. RavenDB search already supports a trailing wildcard.FREETEXTandwebsearch_to_tsqueryignored the*.-term,"...",or) in a search. Each space-separated term is a phrase, as on SQL Server.Not changed
CONTAINS, likeFREETEXT, does not accept annvarchar(max)argument.CHANGE_TRACKING AUTO), so a new message becomes searchable 4 to 6 seconds after it appears in the list. ServicePulse can still show "Could not find message" for a message that is only seconds old.Testing
*matches a prefix, and 13 inputs that are query syntax in one of the dialects (*,zarquon\,it's*,",a & b,NEARand others) do not throw. Against the oldFREETEXTdialect, the id and prefix tests fail on both instances.FullTextSearchIndexTests(PostgreSQL, both instances) pin the|join and the:*suffix.