mirror of
https://github.com/infiniflow/ragflow.git
synced 2025-12-08 20:42:30 +08:00
Fix:ListOperations does not support sorting arrays of objects. (#11278)
### What problem does this PR solve? pr: #11276 change: ListOperations does not support sorting arrays of objects. ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue)
This commit is contained in:
@ -121,10 +121,26 @@ class ListOperations(ComponentBase,ABC):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
def _sort(self):
|
def _sort(self):
|
||||||
if self._param.sort_method == "asc":
|
items = self.inputs or []
|
||||||
self._set_outputs(sorted(self.inputs))
|
method = getattr(self._param, "sort_method", "asc") or "asc"
|
||||||
elif self._param.sort_method == "desc":
|
reverse = method == "desc"
|
||||||
self._set_outputs(sorted(self.inputs, reverse=True))
|
|
||||||
|
if not items:
|
||||||
|
self._set_outputs([])
|
||||||
|
return
|
||||||
|
|
||||||
|
first = items[0]
|
||||||
|
|
||||||
|
if isinstance(first, dict):
|
||||||
|
outputs = sorted(
|
||||||
|
items,
|
||||||
|
key=lambda x: self._hashable(x),
|
||||||
|
reverse=reverse,
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
outputs = sorted(items, reverse=reverse)
|
||||||
|
|
||||||
|
self._set_outputs(outputs)
|
||||||
|
|
||||||
def _drop_duplicates(self):
|
def _drop_duplicates(self):
|
||||||
seen = set()
|
seen = set()
|
||||||
@ -145,5 +161,6 @@ class ListOperations(ComponentBase,ABC):
|
|||||||
if isinstance(x, set):
|
if isinstance(x, set):
|
||||||
return tuple(sorted(self._hashable(v) for v in x))
|
return tuple(sorted(self._hashable(v) for v in x))
|
||||||
return x
|
return x
|
||||||
|
|
||||||
def thoughts(self) -> str:
|
def thoughts(self) -> str:
|
||||||
return "ListOperation in progress"
|
return "ListOperation in progress"
|
||||||
|
|||||||
Reference in New Issue
Block a user