fix common-phrase optimization field scope #4142
Merged
+238
−29
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.
Related issue #4128
Changes in this PR prevent boolean optimizations from collapsing field-scoped phrases into an all-fields phrase. The fix keeps optimizations within the same field/zone spec and preserves the spec when new phrase nodes are created.
Changes by area
1) Add field/zone spec hashing helper
File:
src/sphinxquery/transform_commonkeywords.cppWhat changed
HashSpec(const XQLimitSpec_t & tSpec)that hashes:m_dFieldMaskm_iFieldMaxPosm_bZoneSpanm_dZones(if any)Why
Effect
2) Seed phrase and subphrase hashes with the spec
File:
src/sphinxquery/transform_commonkeywords.cppWhat changed
sphHashPhrase()now starts its hash fromHashSpec(pNode->m_dSpec)rather than0.sphHashSubphrases()now seeds each subphrase hash withHashSpec(pNode->m_dSpec).Why
Effect
3) Include spec in common-phrase head/tail bigram hashes
File:
src/sphinxquery/transform_commonkeywords.cppWhat changed
HashSpec(...)before hashing words.Why
Effect
4) Preserve field/zone spec when building new phrase nodes
File:
src/sphinxquery/transform_commonkeywords.cppWhat changed
MakeTransformCommonPhrase(), new nodes now use the original node’sXQLimitSpec_tinstead ofXQLimitSpec_t():pCommonPhrasepNewOrpNewPhraseWhy
Effect
Behavior impact
(@f "a b") | (@f2 "a b")will no longer match rows where the phrase appears only in unrelated fields.Files touched
src/sphinxquery/transform_commonkeywords.cpp