Benjamin Habegger created OAK-12358:
---------------------------------------

             Summary: [oak-search] FulltextIndexEditor doesn't delete a 
document when its last indexed property is removed
                 Key: OAK-12358
                 URL: https://issues.apache.org/jira/browse/OAK-12358
             Project: Jackrabbit Oak
          Issue Type: Bug
          Components: oak-search
            Reporter: Benjamin Habegger


h3. Summary
When a node has an indexed document, and a later commit removes the last 
property that was actually being indexed on it (rule/type unchanged), the stale 
document is never deleted -- it stays in the index and keeps matching queries 
on the old value forever.

h3. Details
{{FulltextIndexEditor.addOrUpdate()}} calls {{makeDocument()}} to (re)build the 
document for a node on every commit that touches it. If the node has no 
indexable property left, {{makeDocument()}} returns {{null}} -- "nothing to 
index" -- and {{addOrUpdate()}} just returns {{false}}. There is no branch 
anywhere in that method that calls {{deleteDocument()}} for this case.

This is only a bug on the *update* path. A brand-new node that never had any 
indexed property is fine as-is -- {{makeDocument()}} returning {{null}} there 
is correct, since no document was ever created for it. The gap is specifically: 
a node *had* a document (some property made it indexable), a later commit 
removes that last property, and the now-content-less update silently leaves the 
old document behind instead of deleting it.

The recently-fixed OAK-12244 ({{wasIndexable}}/{{isIndexable()}} tracking) 
doesn't cover this -- it tracks whether the node's *rule* stopped matching, not 
whether the document's *content* disappeared while the rule still matches.

Affects every backend sharing this class: {{oak-lucene}} and 
{{oak-search-elastic}}.

h3. Example
# Index rule for {{nt:unstructured}} indexes property {{status}}.
# Commit 1: create {{/content/foo}} with {{jcr:primaryType=nt:unstructured}}, 
{{status=published}}. Document is created. {{WHERE status = 'published'}} 
returns {{/content/foo}}.
# Commit 2: remove the {{status}} property from {{/content/foo}} (type 
unchanged). The rule still matches, so no delete is triggered by OAK-12244's 
guard; {{makeDocument()}} now returns {{null}} since there's nothing left to 
index, and {{addOrUpdate()}} does nothing further.
# {{WHERE status = 'published'}} *still* returns {{/content/foo}} -- the node 
no longer has that property at all, but its stale document is still there.

h3. Related
OAK-12244 -- fixed the sibling "rule transition" case; this ticket is the 
"content transition" case that fix didn't cover.




--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to