Skip to content

fix: restore case-insensitive contains/not contains/not in and consolidate metadata filter pipeline - #15686

Merged
yingfeng merged 3 commits into
infiniflow:mainfrom
xugangqiang:main
Jun 5, 2026
Merged

yingfeng merged 3 commits into
infiniflow:mainfrom
xugangqiang:main

Conversation

@xugangqiang

Copy link
Copy Markdown
Contributor

Summary

This PR fixes case-sensitivity regressions introduced in #15656 and consolidates the metadata filtering pipeline by removing the duplicate applySingleCondition adapter layer.

Bug fixes

  1. contains / not contains: restored case-insensitive matching (was lost when applySingleCondition was replaced by common.MetaFilter.matchValue which lacked strings.ToLower)
  2. not in: restored case-insensitive matching (was lost for same reason; uses strings.EqualFold)
  3. != with date filter values: non-date metadata values now correctly match the ≠ operator (a non-date value IS not equal to any date, but was returning false)

Architecture

  1. Removed applySingleCondition (65 lines) — the inline switch was a duplicate of common.MetaFilter logic. ApplyMetaFilter now converts conditions and delegates to common.MetaFilter once per filter set, eliminating ~25 lines of duplicate AND/OR merge logic.
  2. Added filterSet — O(n+m) hash-map fast path for in/not in operators, replacing the O(n*m) linear scan in matchValue.
  3. Exported NormalizeOperator from common for consistent operator alias handling.

Cleanup

  1. Removed 18 lines of dead code (matchValue's in/not in branches already bypassed by filterOut delegation)
  2. Fixed orphaned godoc comment for convertOperator
  3. Fixed incorrect filterSet doc comment (claimed "matching EqualFold" but used strings.ToLower)
  4. Completed convertToMetaCondition operator normalization documentation

Testing

  • 60 tests (24 service + 36 common), all passing
  • New tests: ==, ≠, >, <, ≥, ≤, empty, not empty through ApplyMetaFilter
  • New tests: <, ≤, ≠ through MetaFilter; not-in-empty-list through filterSet
  • All 18 MetaFilter tests pass; all 10 filterSet unit tests pass

This change eliminates the duplicate filtering implementation between
service.ApplyMetaFilter and common.MetaFilter by removing the
applySingleCondition adapter layer and consolidating all operator
handling into common.MetaFilter.

Key changes:
- Remove applySingleCondition (65 lines of inline switch logic)
- ApplyMetaFilter now converts MetaFilterCondition to MetaCondition
  and delegates directly to common.MetaFilter once per filter set
- Add filterSet: O(n+m) hash-map fast path for in/not in operators
  (replaces O(n*m) linear scan in matchValue)
- Export NormalizeOperator from common for operator alias mapping
  (includes ==, !=, >=, <=, is, not is aliases)

Bug fixes:
- contains/not contains: restored case-insensitive matching (ToLower)
- not in: restored case-insensitive matching (EqualFold)
- != with date filter: non-date metadata values now correctly
  match the != operator (they are not equal to the date)
- Added == to operatorMapping so both ParseAndConvert and
  convertToMetaCondition normalize it to =

Performance:
- in/not in: O(n*m) linear scan -> O(n+m) hash-map lookup via filterSet
- = operator delegates to common.MetaFilter (O(n) iteration for
  correctness/case-insensitivity, matching Python behavior)

Cleanup:
- Removed 18 lines of dead code (matchValue's in/not in branches
  bypassed by filterOut delegation)
- Fixed orphaned godoc comment for convertOperator (reordered with
  NormalizeOperator)
- Fixed filterSet doc comment: removed incorrect 'matching EqualFold'
  claim
- Completed convertToMetaCondition operator normalization comment

Tests: 60 tests (24 service + 36 common), all passing.
New tests cover ==, !=, >=, <=, >, <, empty, not empty operators
through ApplyMetaFilter; <, <=, !=, not-in-empty-list through
MetaFilter/filterSet.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@dosubot dosubot Bot added size:L This PR changes 100-499 lines, ignoring generated files. ☯️ refactor Pull request that refactor/refine code 🐞 bug Something isn't working, pull request that fix bug. labels Jun 5, 2026
@xugangqiang xugangqiang added the ci Continue Integration label Jun 5, 2026
@coderabbitai

coderabbitai Bot commented Jun 5, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 70d49ce2-8943-4c26-9c37-feb17262c892

📥 Commits

Reviewing files that changed from the base of the PR and between 98d943a and d2a88d7.

📒 Files selected for processing (2)
  • internal/service/metadata_filter.go
  • internal/service/metadata_filter_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • internal/service/metadata_filter.go

📝 Walkthrough

Walkthrough

This PR refactors metadata filtering by introducing operator alias normalization ("==" → "="), optimizing in/not in matching with lookup maps, updating date comparison semantics, and delegating service-layer filtering to a unified common implementation.

Changes

Metadata Filtering Enhancement

Layer / File(s) Summary
Operator normalization and alias support
internal/common/metadata_utils.go, internal/common/metadata_utils_test.go
Adds "==" as an operator alias normalized to "=", exposes public NormalizeOperator wrapper, and verifies the alias in operator conversion tests.
Set-based filtering optimization for in/not in
internal/common/metadata_utils.go, internal/common/metadata_utils_test.go
Replaces per-item list scanning with prebuilt lookup maps via new filterSet function; filterOut routes in/not in operators to the optimized path while matchValue no longer handles them. Tests cover case sensitivity, empty lists, and multi-value exclusion scenarios.
Date mismatch comparison behavior
internal/common/metadata_utils.go
Updates compareValues to return true for "≠" operator when filter value is a date but metadata value is not.
Service layer delegation to common filtering
internal/service/metadata_filter.go, internal/service/metadata_filter_test.go
Refactors ApplyMetaFilter to delegate AND/OR merging to common.MetaFilter instead of manual docID operations. Adds convertToMetaCondition helper for operator normalization and comma-separated value parsing. Tests verify operator aliases, numeric comparisons, empty semantics, and edge cases in CSV parsing.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • infiniflow/ragflow#15648: Introduces the initial metadata_utils.go with operator conversion and MetaFilter semantics that are directly extended here with alias normalization and optimization.
  • infiniflow/ragflow#15656: Modifies the same internal/service/metadata_filter.go file with related changes to metadata-filter evaluation and in/not in operator handling.

Suggested labels

🧪 test

Suggested reviewers

  • yingfeng
  • yuzhichang
  • JinHai-CN
  • Haruko386
  • qinling0210

Poem

🐰 A rabbit hops through filter fields,
Where == now maps to =, precision yields!
Lookup maps bloom where lists once crawled,
And services delegate—through common paths called! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 28.57% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main changes: restoring case-insensitive filtering and consolidating the metadata filter pipeline.
Description check ✅ Passed The description provides comprehensive detail on bug fixes, architecture changes, and testing. It follows the template structure with clear categorization of changes.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@xugangqiang
xugangqiang marked this pull request as draft June 5, 2026 03:36
@xugangqiang
xugangqiang marked this pull request as ready for review June 5, 2026 03:36

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@internal/service/metadata_filter.go`:
- Around line 240-249: The code that handles the "in"/"not in" branch splits
f.Value into parts and appends trimmed parts to arr but does not filter out
empty or whitespace-only entries, causing "" to be included in mc.Value; update
the loop over parts (the slice named parts derived from f.Value) to TrimSpace
each p and skip any that result in an empty string (i.e., continue when trimmed
== "") before appending to arr so mc.Value contains only non-empty values.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: bebfb38f-7687-4412-9d84-7b38ffaccd19

📥 Commits

Reviewing files that changed from the base of the PR and between 9f3e289 and 98d943a.

📒 Files selected for processing (5)
  • internal/common/metadata_utils.go
  • internal/common/metadata_utils_test.go
  • internal/dao/task_test.go
  • internal/service/metadata_filter.go
  • internal/service/metadata_filter_test.go
💤 Files with no reviewable changes (1)
  • internal/dao/task_test.go

Comment thread internal/service/metadata_filter.go Resolved
@xugangqiang
xugangqiang requested a review from qinling0210 June 5, 2026 03:40
xugangqiang and others added 2 commits June 5, 2026 11:48
This file was accidentally included in the previous commit via
git add internal/. The change was pre-existing in the working tree
but unrelated to the metadata filter refactoring.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
When f.Value is "A,,B" or "A, ,B", strings.Split produces empty
or whitespace-only entries. These are now filtered out after TrimSpace
to prevent unintended matches against empty-string metadata values.

Add 5 test cases:
- InEmptyParts: A,,B produces [A B]
- InOnlyWhitespaceParts: A, , ,B produces [A B]
- InAllEmptyParts: ,,, produces []
- NotInEmptyParts: A,,B produces [A B]
- InMixedSpaces: spaces around values preserve trimmed values

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@codecov

codecov Bot commented Jun 5, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.16%. Comparing base (794c1f4) to head (d2a88d7).
⚠️ Report is 8 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #15686   +/-   ##
=======================================
  Coverage   93.16%   93.16%           
=======================================
  Files          10       10           
  Lines         717      717           
  Branches      118      118           
=======================================
  Hits          668      668           
  Misses         29       29           
  Partials       20       20           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@yingfeng
yingfeng merged commit f6ff862 into infiniflow:main Jun 5, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🐞 bug Something isn't working, pull request that fix bug. ci Continue Integration ☯️ refactor Pull request that refactor/refine code size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants