Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reindexing Context's Page Container on Change/Insert/Delete #278

Open
drfho opened this issue May 25, 2024 · 2 comments
Open

Reindexing Context's Page Container on Change/Insert/Delete #278

drfho opened this issue May 25, 2024 · 2 comments
Assignees
Labels
documentation Some important hints

Comments

@drfho
Copy link
Contributor

drfho commented May 25, 2024

The latest changes address the different cases:

[1] CASE-1: ZMS_INSERT

  • is page-like class and filterMatch of current node (eg. new ZMSFolder)
  • is not page-like and filterMatch of container-page (eg. new ZMSTextarea into ZMSFolder)
  • is not page-like and filterMatch of current node (e.g. new ZMSFile)

[2] CASE-2: CHANGE

  • container-page is not current node and filterMatch of container-page
  • filterMatch of current node

# Reindex node's content by each connector.
for connector in connectors:
if self.matches_ids_filter(node) or self.matches_ids_filter(page):
# CASE-1: ZMS_INSERT
# Reindex the current node if page or its container page.
if self.REQUEST.get('ZMS_INSERT', None):
if node.isPage() and self.matches_ids_filter(node):
self.reindex(connector, node, recursive=False, fileparsing=fileparsing)
elif not node.isPage() and self.matches_ids_filter(page):
self.reindex(connector, page, recursive=False, fileparsing=fileparsing)
if not node.isPage() and self.matches_ids_filter(node):
# After reindexing the page add the node if filter-match.
self.reindex(connector, node, recursive=False, fileparsing=fileparsing)
# CASE-2: CHANGE
# Reindex container page if node!=page and the node if filter-match.
else:
if node != page and self.matches_ids_filter(page):
self.reindex(connector, page, recursive=False, fileparsing=fileparsing)
if self.matches_ids_filter(node):
self.reindex(connector, node, recursive=False, fileparsing=fileparsing)

The incremental reindex still shows a surprising logical (?) problem: on ZMS_INSERT the content of the container page is aggregated only of the content-objects that have the same meta_id like the objects that is inserted. Exp: if a ZMSTextarea is added to a document, the indexed page content only concats the ZMSTextarea-content but ignores any other object class e.g. the content of ZMSTable-object.
It seems that the context that is needed for the attribute rendering is in case of standard_html not referring to the iterated object's standard_html, LINE 355 child_node.getBodyContent(request):

try:
# ZMSFile.standard_html will work in get_file.
if not (node.meta_id == 'ZMSFile' and attr_id == 'standard_html'):
if attr_id == 'standard_html' and request.get('ZMS_INSERT', None) and node.isPage():
# ZMS_INSERT Page: attr('standard_html') does not work.
for child_node in node.getObjChildren('e',request,self.PAGEELEMENTS):
value += child_node.getBodyContent(request)
else:
value = node.attr(attr_id)

[1] On INSERTING an new ZMSTextarea prevents Reindexing Page-Content not derived from ZMSTextarea
reindex_insert_1

[2] On CHANGE a PAGEELEMENT or the PAGE-Container renders/reindexes the full content
reindex_insert_2

Debugging the get_attr_data()-iteration

# ZMS_INSERT Page: attr('standard_html') does not work.
for child_node in node.getObjChildren('e',request,self.PAGEELEMENTS):
value += child_node.getBodyContent(request)

reveals that standard_html-attr of the inserted obj-class is applied and not the one of the iterated item. In case of ZMSFile this results in empty data for any ZMSTextarea, because the standard_html of ZMSFile cannot render ZMSTextarea appropiately.

reindex_insert_3

The other way round: if inserting a ZMSTextarea the ZMSFile cannot be renderd

child_node.meta_id
'ZMSFile'
child_node.getBodyContent(request)
'<!-- ZMSTextarea.standard_html -->\n\n\n\n<!-- /ZMSTextarea.standard_html -->'
child_node.attr('standard_html')
'<!-- ZMSTextarea.standard_html -->\n\n\n\n<!-- /ZMSTextarea.standard_html -->'
child_node.attr('title')
'antrag.pdf'

NOTE: Fullindex works correctly and thus corrects any missing page content.

Ref:
[1] Ensure Reindexing Context's Page Container on Change/Insert #277
[2] https://github.com/idasm-unibe-ch/unibe-cms-opensearch/issues/50

drfho added a commit that referenced this issue May 26, 2024
@drfho
Copy link
Contributor Author

drfho commented May 26, 2024

Addressing the iteration-item's class' content-modell standard_html explictly does the job:

self.getMetaobjAttr(child_node.meta_id, 'standard_html')['ob'](zmscontext=child_node)

# ZMS_INSERT Page: attr('standard_html') does not work.
for child_node in node.getObjChildren('e',request,self.PAGEELEMENTS):
# value += child_node.getBodyContent(request) # This would not work.
# Explicitly call ob-method to get the correct standard_html:
value += self.getMetaobjAttr(child_node.meta_id, 'standard_html')['ob'](zmscontext=child_node)

@drfho drfho added the documentation Some important hints label May 26, 2024
@drfho drfho changed the title Reindexing Context's Page Container on Change/Insert Reindexing Context's Page Container on Change/Insert/Delete May 27, 2024
@drfho
Copy link
Contributor Author

drfho commented May 27, 2024

Unindexing

If a ZMS-node may be a page or a page-element: if latter is deleted (moved to trashcan) the containg page mus be reindexed If a page is deleted this node must be removed from index in all it's languages.

# --------------------------------------------------------------------------
# ZMSZCatalogAdapter.unindex_node
# --------------------------------------------------------------------------
def unindex_nodes(self, nodes=[], forced=False):
# Is triggered by zmscontainerobject.moveObjsToTrashcan().
standard.writeBlock(self, "[unindex_nodes]")
# Get closest catalog-connectors.
path_nodes = self.breadcrumbs_obj_path()
path_nodes.reverse()
for path_node in path_nodes:
if path_node.getCatalogAdapter():
connectors = path_node.getCatalogAdapter().get_connectors()
break
if not connectors:
root = self.getRootElement()
connectors = root.getCatalogAdapter().get_connectors()
try:
if self.getConfProperty('ZMS.CatalogAwareness.active', 1) or forced:
# [1] Reindex page-container nodes of deleted page-elements.
pageelement_nodes = [node for node in nodes if not node.isPage()]
if pageelement_nodes:
for pageelement_node in pageelement_nodes:
# Todo: Avoid redundant reindexing of page-container.
self.reindex_node(node=pageelement_node)
# [2] Unindex deleted page-nodes if filter-match.
nodes = [node for node in nodes if self.matches_ids_filter(node)]
for connector in connectors:
connector.manage_objects_remove(nodes)
return True
except:
standard.writeError( self, "unindex_nodes not successful")
return False

The possible languages of a deleted node (not the catalog-connector node, which may have a different language set) is set as global var in the main interface function manage_opensearch_objects_remove() ...

for node in nodes:
# Set node's language list as global variable.
global langs
langs = node.getLangIds()
break

... and then used in the bulk-deleting bulk_opensearch_delete():

# Create language specific opensearch id
for lang in globals()['langs']:
_id = "%s:%s"%(x['uid'],lang)
d = {"_op_type":"delete", "_index":index_name, "_id":_id}
actions.append(d)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Some important hints
Projects
None yet
Development

No branches or pull requests

2 participants