mirror of
https://github.com/Qortal/qortal.git
synced 2025-04-14 23:35:54 +00:00
changed to list and added to cache
This commit is contained in:
parent
6a6380e9e7
commit
2e9f358d0b
@ -172,7 +172,7 @@ public class ArbitraryResource {
|
||||
@Parameter(description = "Name (searches name field only)") @QueryParam("name") List<String> names,
|
||||
@Parameter(description = "Title (searches title metadata field only)") @QueryParam("title") String title,
|
||||
@Parameter(description = "Description (searches description metadata field only)") @QueryParam("description") String description,
|
||||
@Parameter(description = "Keywords (searches description metadata field by keywords. Input is a string of keywords separated by commas.)") @QueryParam("keywords") String keywords,
|
||||
@Parameter(description = "Keyword (searches description metadata field by keywords)") @QueryParam("keywords") List<String> keywords,
|
||||
@Parameter(description = "Prefix only (if true, only the beginning of fields are matched)") @QueryParam("prefix") Boolean prefixOnly,
|
||||
@Parameter(description = "Exact match names only (if true, partial name matches are excluded)") @QueryParam("exactmatchnames") Boolean exactMatchNamesOnly,
|
||||
@Parameter(description = "Default resources (without identifiers) only") @QueryParam("default") Boolean defaultResource,
|
||||
|
@ -46,7 +46,7 @@ public interface ArbitraryRepository {
|
||||
|
||||
public List<ArbitraryResourceData> getArbitraryResources(Service service, String identifier, List<String> names, boolean defaultResource, Boolean followedOnly, Boolean excludeBlocked, Boolean includeMetadata, Boolean includeStatus, Integer limit, Integer offset, Boolean reverse) throws DataException;
|
||||
|
||||
public List<ArbitraryResourceData> searchArbitraryResources(Service service, String query, String identifier, List<String> names, String title, String description, String keywords, boolean prefixOnly, List<String> namesFilter, boolean defaultResource, SearchMode mode, Integer minLevel, Boolean followedOnly, Boolean excludeBlocked, Boolean includeMetadata, Boolean includeStatus, Long before, Long after, Integer limit, Integer offset, Boolean reverse) throws DataException;
|
||||
public List<ArbitraryResourceData> searchArbitraryResources(Service service, String query, String identifier, List<String> names, String title, String description, List<String> keywords, boolean prefixOnly, List<String> namesFilter, boolean defaultResource, SearchMode mode, Integer minLevel, Boolean followedOnly, Boolean excludeBlocked, Boolean includeMetadata, Boolean includeStatus, Long before, Long after, Integer limit, Integer offset, Boolean reverse) throws DataException;
|
||||
|
||||
List<ArbitraryResourceData> searchArbitraryResourcesSimple(
|
||||
Service service,
|
||||
|
@ -862,12 +862,11 @@ public class HSQLDBArbitraryRepository implements ArbitraryRepository {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ArbitraryResourceData> searchArbitraryResources(Service service, String query, String identifier, List<String> names, String title, String description, String keywords, boolean prefixOnly,
|
||||
public List<ArbitraryResourceData> searchArbitraryResources(Service service, String query, String identifier, List<String> names, String title, String description, List<String> keywords, boolean prefixOnly,
|
||||
List<String> exactMatchNames, boolean defaultResource, SearchMode mode, Integer minLevel, Boolean followedOnly, Boolean excludeBlocked,
|
||||
Boolean includeMetadata, Boolean includeStatus, Long before, Long after, Integer limit, Integer offset, Boolean reverse) throws DataException {
|
||||
|
||||
if(Settings.getInstance().isDbCacheEnabled()) {
|
||||
|
||||
List<ArbitraryResourceData> list
|
||||
= HSQLDBCacheUtils.callCache(
|
||||
ArbitraryResourceCache.getInstance(),
|
||||
@ -889,6 +888,7 @@ public class HSQLDBArbitraryRepository implements ArbitraryRepository {
|
||||
Optional.ofNullable(description),
|
||||
prefixOnly,
|
||||
Optional.ofNullable(exactMatchNames),
|
||||
Optional.ofNullable(keywords),
|
||||
defaultResource,
|
||||
Optional.ofNullable(minLevel),
|
||||
Optional.ofNullable(() -> ListUtils.followedNames()),
|
||||
@ -909,6 +909,7 @@ public class HSQLDBArbitraryRepository implements ArbitraryRepository {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
StringBuilder sql = new StringBuilder(512);
|
||||
List<Object> bindParams = new ArrayList<>();
|
||||
|
||||
@ -995,24 +996,25 @@ public class HSQLDBArbitraryRepository implements ArbitraryRepository {
|
||||
bindParams.add(queryWildcard);
|
||||
}
|
||||
|
||||
if (keywords != null) {
|
||||
String[] encryptedTokens = keywords.split(",");
|
||||
|
||||
if (keywords != null && !keywords.isEmpty()) {
|
||||
List<String> searchKeywords = new ArrayList<>(keywords);
|
||||
|
||||
List<String> conditions = new ArrayList<>();
|
||||
List<String> bindValues = new ArrayList<>();
|
||||
List<String> bindValues = new ArrayList<>();
|
||||
|
||||
for (String token : encryptedTokens) {
|
||||
conditions.add("POSITION(? IN description) > 0");
|
||||
bindValues.add(token.trim());
|
||||
for (int i = 0; i < searchKeywords.size(); i++) {
|
||||
conditions.add("LOWER(description) LIKE ?");
|
||||
bindValues.add("%" + searchKeywords.get(i).trim().toLowerCase() + "%");
|
||||
}
|
||||
|
||||
|
||||
String finalCondition = String.join(" OR ", conditions);
|
||||
sql.append(" AND (").append(finalCondition).append(")");
|
||||
|
||||
bindParams.addAll(bindValues);
|
||||
|
||||
bindParams.addAll(bindValues);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// Handle name searches
|
||||
if (names != null && !names.isEmpty()) {
|
||||
|
@ -167,6 +167,7 @@ public class HSQLDBCacheUtils {
|
||||
Optional<String> description,
|
||||
boolean prefixOnly,
|
||||
Optional<List<String>> exactMatchNames,
|
||||
Optional<List<String>> keywords,
|
||||
boolean defaultResource,
|
||||
Optional<Integer> minLevel,
|
||||
Optional<Supplier<List<String>>> includeOnly,
|
||||
@ -207,6 +208,36 @@ public class HSQLDBCacheUtils {
|
||||
stream = filterTerm(title, data -> data.metadata != null ? data.metadata.getTitle() : null, prefixOnly, stream);
|
||||
stream = filterTerm(description, data -> data.metadata != null ? data.metadata.getDescription() : null, prefixOnly, stream);
|
||||
|
||||
// New: Filter by keywords if provided
|
||||
if (keywords.isPresent() && !keywords.get().isEmpty()) {
|
||||
List<String> searchKeywords = keywords.get().stream()
|
||||
.map(String::toLowerCase)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
stream = stream.filter(candidate -> {
|
||||
|
||||
if (candidate.metadata != null && candidate.metadata.getDescription() != null) {
|
||||
String descriptionLower = candidate.metadata.getDescription().toLowerCase();
|
||||
return searchKeywords.stream().anyMatch(descriptionLower::contains);
|
||||
}
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
if (keywords.isPresent() && !keywords.get().isEmpty()) {
|
||||
List<String> searchKeywords = keywords.get().stream()
|
||||
.map(String::toLowerCase)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
stream = stream.filter(candidate -> {
|
||||
if (candidate.metadata != null && candidate.metadata.getDescription() != null) {
|
||||
String descriptionLower = candidate.metadata.getDescription().toLowerCase();
|
||||
return searchKeywords.stream().anyMatch(descriptionLower::contains);
|
||||
}
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
// if exact names is set, retain resources with exact names
|
||||
if( exactMatchNames.isPresent() && !exactMatchNames.get().isEmpty()) {
|
||||
|
||||
|
@ -26,6 +26,7 @@ public class HSQLDBCacheUtilsTests {
|
||||
private static final String DESCRIPTION = "description";
|
||||
private static final String PREFIX_ONLY = "prefixOnly";
|
||||
private static final String EXACT_MATCH_NAMES = "exactMatchNames";
|
||||
private static final String KEYWORDS = "keywords";
|
||||
private static final String DEFAULT_RESOURCE = "defaultResource";
|
||||
private static final String MODE = "mode";
|
||||
private static final String MIN_LEVEL = "minLevel";
|
||||
@ -634,6 +635,7 @@ public class HSQLDBCacheUtilsTests {
|
||||
Optional<String> description = Optional.ofNullable((String) valueByKey.get(DESCRIPTION));
|
||||
boolean prefixOnly = valueByKey.containsKey(PREFIX_ONLY);
|
||||
Optional<List<String>> exactMatchNames = Optional.ofNullable((List<String>) valueByKey.get(EXACT_MATCH_NAMES));
|
||||
Optional<List<String>> keywords = Optional.ofNullable((List<String>) valueByKey.get(KEYWORDS));
|
||||
boolean defaultResource = valueByKey.containsKey(DEFAULT_RESOURCE);
|
||||
Optional<SearchMode> mode = Optional.of((SearchMode) valueByKey.getOrDefault(MODE, SearchMode.ALL));
|
||||
Optional<Integer> minLevel = Optional.ofNullable((Integer) valueByKey.get(MIN_LEVEL));
|
||||
@ -660,6 +662,7 @@ public class HSQLDBCacheUtilsTests {
|
||||
description,
|
||||
prefixOnly,
|
||||
exactMatchNames,
|
||||
keywords,
|
||||
defaultResource,
|
||||
minLevel,
|
||||
followedOnly,
|
||||
|
Loading…
x
Reference in New Issue
Block a user