Source:
public DocumentModel saveSearch(CoreSession session, ContentViewState searchContentViewState, String title) { UserWorkspaceService userWorkspaceService = Framework.getLocalService(UserWorkspaceService.class); DocumentModel uws = userWorkspaceService.getCurrentUserPersonalWorkspace(session, null); DocumentModel searchDoc = searchContentViewState.getSearchDocumentModel(); searchDoc.setPropertyValue("dc:title", title); if (searchDoc.hasFacet(CONTENT_VIEW_DISPLAY_FACET)) { searchDoc.setPropertyValue("cvd:contentViewName", searchContentViewState.getContentViewName()); searchDoc.setPropertyValue("saved:providerName", searchContentViewState.getPageProviderName()); searchDoc.setPropertyValue("saved:pageSize", searchContentViewState.getPageSize()); searchContentViewState.getPageSize(); List<SortInfo> sortInfos = searchContentViewState.getSortInfos(); if (sortInfos != null) { ArrayList<Map<String, Serializable>> list = new ArrayList<>(); String sortBy = "", sortOrder = ""; for (SortInfo sortInfo : sortInfos) { if (!sortBy.equals("")) { sortBy += ","; sortOrder += ","; } sortBy += sortInfo.getSortColumn(); sortOrder += sortInfo.getSortAscending() ? "ASC" : "DESC"; list.add(SortInfo.asMap(sortInfo)); } searchDoc.setPropertyValue("cvd:sortInfos", list); searchDoc.setPropertyValue("saved:sortBy", sortBy); searchDoc.setPropertyValue("saved:sortOrder", sortOrder); } searchDoc.setPropertyValue("cvd:selectedLayoutColumns", (Serializable) searchContentViewState.getResultColumns()); } else { log.warn(String.format("Search document type %s is missing %s facet", searchDoc.getType(), CONTENT_VIEW_DISPLAY_FACET)); } PathSegmentService pathService = Framework.getLocalService(PathSegmentService.class); searchDoc.setPathInfo(uws.getPathAsString(), pathService.generatePathSegment(searchDoc)); searchDoc = session.createDocument(searchDoc); session.save(); return searchDoc; }

Target:
public DocumentModel saveSearch(CoreSession session, ContentViewState searchContentViewState, String title) { UserWorkspaceService userWorkspaceService = Framework.getService(UserWorkspaceService.class); DocumentModel uws = userWorkspaceService.getCurrentUserPersonalWorkspace(session, null); DocumentModel searchDoc = searchContentViewState.getSearchDocumentModel(); searchDoc.setPropertyValue("dc:title", title); if (searchDoc.hasFacet(CONTENT_VIEW_DISPLAY_FACET)) { searchDoc.setPropertyValue("cvd:contentViewName", searchContentViewState.getContentViewName()); searchDoc.setPropertyValue("saved:providerName", searchContentViewState.getPageProviderName()); searchDoc.setPropertyValue("saved:pageSize", searchContentViewState.getPageSize()); searchContentViewState.getPageSize(); List<SortInfo> sortInfos = searchContentViewState.getSortInfos(); if (sortInfos != null) { ArrayList<Map<String, Serializable>> list = new ArrayList<>(); String sortBy = "", sortOrder = ""; for (SortInfo sortInfo : sortInfos) { if (!sortBy.isEmpty()) { sortBy += ","; sortOrder += ","; } sortBy += sortInfo.getSortColumn(); sortOrder += sortInfo.getSortAscending() ? "ASC" : "DESC"; list.add(SortInfo.asMap(sortInfo)); } searchDoc.setPropertyValue("cvd:sortInfos", list); searchDoc.setPropertyValue("saved:sortBy", sortBy); searchDoc.setPropertyValue("saved:sortOrder", sortOrder); } searchDoc.setPropertyValue("cvd:selectedLayoutColumns", (Serializable) searchContentViewState.getResultColumns()); } else { log.warn(String.format("Search document type %s is missing %s facet", searchDoc.getType(), CONTENT_VIEW_DISPLAY_FACET)); } PathSegmentService pathService = Framework.getService(PathSegmentService.class); searchDoc.setPathInfo(uws.getPathAsString(), pathService.generatePathSegment(searchDoc)); searchDoc = session.createDocument(searchDoc); session.save(); return searchDoc; }