Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion component/api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<parent>
<artifactId>social-component</artifactId>
<groupId>io.meeds.social</groupId>
<version>7.1.x-SNAPSHOT</version>
<version>7.1.x-meeds-qaui-SNAPSHOT</version>
</parent>
<artifactId>social-component-api</artifactId>
<name>Meeds:: PLF:: Social API</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,13 @@ public List<SpaceMembershipStatus> getStatusList() {
return Stream.of(status, extraStatus).filter(Objects::nonNull).toList();
}

public boolean isSortingEmpty() {
return sorting == null;
}

public Sorting getSorting() {
if (sorting == null) {
sorting = new Sorting(Sorting.SortBy.TITLE, Sorting.OrderBy.ASC);
return new Sorting(Sorting.SortBy.TITLE, Sorting.OrderBy.ASC);
}
return sorting;
}
Expand Down
2 changes: 1 addition & 1 deletion component/common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<parent>
<artifactId>social-component</artifactId>
<groupId>io.meeds.social</groupId>
<version>7.1.x-SNAPSHOT</version>
<version>7.1.x-meeds-qaui-SNAPSHOT</version>
</parent>
<groupId>io.meeds.social</groupId>
<artifactId>social-component-common</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion component/core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<parent>
<artifactId>social-component</artifactId>
<groupId>io.meeds.social</groupId>
<version>7.1.x-SNAPSHOT</version>
<version>7.1.x-meeds-qaui-SNAPSHOT</version>
</parent>
<artifactId>social-component-core</artifactId>
<name>Meeds:: PLF:: Social Core Component</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,23 @@ public class SpaceSearchConnector {
}
""";

public static final String DEFAULT_SORTING_QUERY = """
{
"_score": {
"order": "desc"
}
}
""";

public static final String SORTING_QUERY = """
{
"@sortField@": {
"order": "@sortOrder@"
}
},
"_score"
""";

private static final String TERM_REPLACEMENT = "@term@";

private static final String PHRASE_REPLACEMENT = "@phrase@";
Expand Down Expand Up @@ -275,6 +292,7 @@ private String buildQueryStatement(SpaceSearchFilter filter,
String tagsQuery = buildTagsQueryStatement(metadataFilters.get(TagService.METADATA_TYPE.getName()));
String visibilityQuery = buildVisibilityStatement(filter.getVisibility());
String registrationQuery = buildRegistrationStatement(filter.getRegistration());
String sortQuery = buildSortQuery(filter);
boolean noCommaToTemplate = StringUtils.isBlank(categoryQuery) || StringUtils.isBlank(templateQuery);
boolean noCommaToFavorite = StringUtils.isBlank(favoriteQuery) || StringUtils.isAllBlank(templateQuery, categoryQuery);
boolean noCommaToPermission = StringUtils.isBlank(permissionsQuery)
Expand Down Expand Up @@ -307,6 +325,7 @@ private String buildQueryStatement(SpaceSearchFilter filter,
noCommaToRegistration ? registrationQuery :
String.format(PREFIX_COMMA_TO_APPEND, registrationQuery))
.replace("@tags_query@", tagsQuery)
.replace("@sortQuery@", sortQuery)
.replace("@offset@",
String.valueOf(offset))
.replace("@limit@",
Expand Down Expand Up @@ -585,4 +604,16 @@ private Long parseLong(JSONObject hitSource, String key) {
return StringUtils.isBlank(value) ? null : Long.parseLong(value);
}

private String buildSortQuery(SpaceSearchFilter filter) {
if (StringUtils.isBlank(filter.getSortField())) {
return DEFAULT_SORTING_QUERY;
}
String sortFiled = filter.getSortField();
String sortDirection = filter.getSortDirection();
return switch (sortFiled) {
case "date" -> SORTING_QUERY.replace("@sortField@", "lastUpdatedDate").replace("@sortOrder@", sortDirection);
default -> DEFAULT_SORTING_QUERY;
};
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,8 @@ public class SpaceSearchFilter {

private SpaceVisibility visibility;

private String sortField;

private String sortDirection;

}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ public class ActivitySearchFilter {

private boolean favorites;

private String sortField;

private String sortDirection;

public ActivitySearchFilter(String term) {
this.term = term;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -82,14 +81,31 @@ public class ActivitySearchConnector {
" }" +
"},";

public static final String CATEGORY_IDS_QUERY = """
public static final String CATEGORY_IDS_QUERY = """
{
"terms":{
"categoryId": [@categoryIds@]
}
}
""";

public static final String DEFAULT_SORTING_QUERY = """
{
"_score": {
"order": "desc"
}
}
""";

public static final String SORTING_QUERY = """
{
"@sortField@": {
"order": "@sortOrder@"
}
},
"_score"
""";

private static final String TERM_REPLACEMENT = "@term@";

private static final String PHRASE_REPLACEMENT = "@phrase@";
Expand Down Expand Up @@ -185,11 +201,13 @@ private String buildQueryStatement(Set<Long> streamFeedOwnerIds,
String favoriteQuery = buildFavoriteQueryStatement(metadataFilters.get(FavoriteService.METADATA_TYPE.getName()));
String tagsQuery = buildTagsQueryStatement(metadataFilters.get(TagService.METADATA_TYPE.getName()));
String categoryQuery = buildCategoryIdQueryStatement(filter);
String sortQuery = buildSortQueryStatement(filter);
return retrieveSearchQuery().replace("@term_query@", termQuery)
.replace("@favorite_query@", favoriteQuery)
.replace("@tags_query@", tagsQuery)
.replace("@category_query@", categoryQuery)
.replace("@permissions@", StringUtils.join(streamFeedOwnerIds, ","))
.replace("@sortQuery@", sortQuery)
.replace("@offset@", String.valueOf(offset))
.replace("@limit@", String.valueOf(limit));
}
Expand Down Expand Up @@ -429,6 +447,20 @@ private String buildTermQueryStatement(String phrase) {
}
}

private String buildSortQueryStatement(ActivitySearchFilter filter) {
String sortFiled = filter.getSortField();
String sortDirection = filter.getSortDirection();

if (StringUtils.isBlank(sortFiled)) {
return DEFAULT_SORTING_QUERY;
}

return switch (sortFiled) {
case "date" -> SORTING_QUERY.replace("@sortField@", "lastUpdatedDate").replace("@sortOrder@", sortDirection);
default -> SORTING_QUERY.replace("@sortField@", sortFiled).replace("@sortOrder@", sortDirection);
};
}

private Long parseLong(JSONObject hitSource, String key) {
String value = (String) hitSource.get(key);
return StringUtils.isBlank(value) ? null : Long.parseLong(value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,6 @@ private Document getDocument(String id) {
if (profile.getProperty(Profile.ENROLLMENT_DATE) != null) {
fields.put("enrollmentDate", profile.getProperty(Profile.ENROLLMENT_DATE).toString());
}
Date createdDate = new Date(profile.getCreatedTime());

for (ProfilePropertySetting profilePropertySetting : profilePropertyService.getPropertySettings()) {
if (profilePropertySetting.isVisible() && !fields.containsKey(profilePropertySetting.getPropertyName())) {
Object propertyValue = profile.getProperty(profilePropertySetting.getPropertyName());
Expand Down Expand Up @@ -306,7 +304,7 @@ private Document getDocument(String id) {
fields.put("connections", "@@@[" + connectionsStr + "]@@@");
}

Document document = new ProfileIndexDocument(id, null, createdDate, (Set<String>) null, fields);
Document document = new ProfileIndexDocument(id, null, new Date(), (Set<String>) null, fields);
document.setPermissions(getGroupIdentityIds(identity));
LOG.info("profile document generated for identity id={} remote_id={} duration_ms={}",
id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,11 @@ public Document create(String id) {
fields.put("registration", space.getRegistration());
fields.put("templateId", String.valueOf(space.getTemplateId()));

Date createdDate = new Date(space.getCreatedTime());
Date updatedDate = new Date(space.getLastUpdatedTime());

DocumentWithMetadata document = new DocumentWithMetadata();
document.setId(id);
document.setLastUpdatedDate(createdDate);
document.setLastUpdatedDate(updatedDate);
document.setFields(fields);

setPermissions(space, document);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,9 @@ private SpaceSearchFilter getSpaceSearchFilter() {
filter.getTagNames(),
statusType,
filter.getRegistration(),
filter.getVisibility());
filter.getVisibility(),
filter.isSortingEmpty() ? null : filter.getSorting().sortBy.getFieldName(),
filter.isSortingEmpty() ? null : filter.getSorting().orderBy.name().toLowerCase());
} else {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ public void testCountFavorites() {
null,
null,
null,
null,
null,
null);
when(client.countRequest(argThat(esQuery -> hasUserFavoriteQueryPart(esQuery)
&& hasPermissionQueryPart(esQuery, MEMBER, 1, USER_NAME)),
Expand All @@ -182,6 +184,8 @@ public void testSearchFavorites() {
null,
null,
null,
null,
null,
null);
when(client.sendRequest(argThat(esQuery -> hasUserFavoriteQueryPart(esQuery)
&& hasPermissionQueryPart(esQuery, MEMBER, 1, USER_NAME)),
Expand Down Expand Up @@ -209,6 +213,8 @@ public void testSearchManagingSpaces() {
null,
null,
null,
null,
null,
null);
filter.setManagingTemplateIds(Collections.singletonList(2l));
when(client.sendRequest(argThat(esQuery -> hasUserFavoriteQueryPart(esQuery)
Expand Down Expand Up @@ -245,6 +251,8 @@ public void testSearchSpacesByCategoryIds() {
null,
null,
null,
null,
null,
null);
when(client.sendRequest(argThat(esQuery -> hasCategoryIdsQueryPart(esQuery, categoryIds)),
eq(index))).thenReturn(SEARCH_RESULT);
Expand All @@ -266,6 +274,8 @@ public void testNotSearchWhenNotUnifiedSearch() {
null,
SpaceMembershipStatus.MEMBER,
null,
null,
null,
null),
0,
10));
Expand Down Expand Up @@ -314,6 +324,8 @@ public void testSearchSpaceNoMembership() {
null,
null,
null,
null,
null,
null);
when(client.sendRequest(argThat(esQuery -> hasNotUserFavoriteQueryPart(esQuery)
&& hasPermissionQueryPart(esQuery,
Expand Down Expand Up @@ -346,6 +358,8 @@ public void testSearchTags() {
Arrays.asList("tag1", "tag2"),
null,
null,
null,
null,
null);
when(client.sendRequest(argThat(esQuery -> hasNotUserFavoriteQueryPart(esQuery)
&& hasPermissionQueryPart(esQuery, PERMISSIONS_FIELD, 2, "all", USER_NAME)
Expand Down Expand Up @@ -373,6 +387,8 @@ private void checkPermissionField(SpaceMembershipStatus status, String fieldName
null,
status,
null,
null,
null,
null);
when(client.sendRequest(argThat(esQuery -> hasNotUserFavoriteQueryPart(esQuery)
&& hasPermissionQueryPart(esQuery, fieldName, 1, USER_NAME)),
Expand Down
2 changes: 1 addition & 1 deletion component/notification/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<parent>
<artifactId>social-component</artifactId>
<groupId>io.meeds.social</groupId>
<version>7.1.x-SNAPSHOT</version>
<version>7.1.x-meeds-qaui-SNAPSHOT</version>
</parent>
<artifactId>social-component-notification</artifactId>
<name>Meeds:: PLF:: Social Notification Component</name>
Expand Down
2 changes: 1 addition & 1 deletion component/oauth-auth/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<parent>
<artifactId>social-component</artifactId>
<groupId>io.meeds.social</groupId>
<version>7.1.x-SNAPSHOT</version>
<version>7.1.x-meeds-qaui-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Loading