Skip to content

Commit

Permalink
handle boolean indexes
Browse files Browse the repository at this point in the history
  • Loading branch information
cekk committed Dec 2, 2024
1 parent 56ff358 commit c6f2a9d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 17 deletions.
1 change: 0 additions & 1 deletion src/rer/solrpush/browser/maintenance.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,6 @@ def sync_contents(self, brains_to_sync, solr_items, disable_progress=False):
except Exception as e:
not_indexed.append({"path": brain.getPath(), "message": str(e)})
else:
item = brain.getObject()
if not can_index(item):
remove_from_solr(brain.UID)
removed.append(brain.getPath())
Expand Down
26 changes: 12 additions & 14 deletions src/rer/solrpush/utils/solr_indexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def create_index_dict(item):
continue
field_type = field_infos.get("type")
value = getattr(adapter, field, None)
if not value:
if not value and value is not False:
continue
if callable(value):
value = value()
Expand Down Expand Up @@ -247,18 +247,19 @@ def push_to_solr(item_or_obj):
if not solr:
logger.error("Unable to push to solr. Configuration is incomplete.")
return
if not isinstance(item_or_obj, dict):
if can_index(item_or_obj):
item_or_obj = create_index_dict(item_or_obj)
else:
item_or_obj = None
if not item_or_obj:
context = item_or_obj
if isinstance(item_or_obj, dict):
obj = api.content.get(UID=item_or_obj.get("UID", ""))
if obj:
context = obj
if not can_index(context):
return False
attachment = item_or_obj.pop("attachment", None)
index_dict = create_index_dict(context)
attachment = index_dict.pop("attachment", None)
if attachment:
add_with_attachment(solr=solr, attachment=attachment, fields=item_or_obj)
add_with_attachment(solr=solr, attachment=attachment, fields=index_dict)
else:
solr.add(docs=[item_or_obj], commit=should_force_commit())
solr.add(docs=[index_dict], commit=should_force_commit())
return True


Expand All @@ -274,10 +275,7 @@ def remove_from_solr(uid):
logger.error("Unable to push to solr. Configuration is incomplete.")
return
try:
solr.delete(
q="UID:{}".format(uid),
commit=should_force_commit(),
)
solr.delete(q=f"UID:{uid}", commit=should_force_commit())
except (pysolr.SolrError, TypeError) as err:
logger.error(err)
message = _(
Expand Down
4 changes: 2 additions & 2 deletions src/rer/solrpush/utils/solr_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ def extract_from_query(query):
index_fields = get_index_fields()
params = {"q": "", "fq": []}
for index, value in query.items():
if not value:
if not value and value is not False:
continue
if index == "*":
params["q"] = "*:*"
Expand All @@ -239,7 +239,7 @@ def extract_from_query(query):
continue
# other indexes will be added in fq
value = fix_value(value=value, index_type=index_infos.get("type", ""))
if value:
if value or value is False:
if index == "path":
index = "path_parents"
params["fq"].append("{index}:{value}".format(index=index, value=value))
Expand Down

0 comments on commit c6f2a9d

Please sign in to comment.