forked from Qortal/qortal
"namefilter" param in GET /arbitrary/resources/search
is now exact match, which makes more sense when filtering results by names in a list.
This commit is contained in:
parent
28bd4adcd2
commit
a286db2dfd
@ -174,29 +174,31 @@ public class ArbitraryResource {
|
|||||||
@Parameter(description = "Query (searches both name and identifier fields)") @QueryParam("query") String query,
|
@Parameter(description = "Query (searches both name and identifier fields)") @QueryParam("query") String query,
|
||||||
@Parameter(description = "Identifier (searches identifier field only)") @QueryParam("identifier") String identifier,
|
@Parameter(description = "Identifier (searches identifier field only)") @QueryParam("identifier") String identifier,
|
||||||
@Parameter(description = "Name (searches name field only)") @QueryParam("name") List<String> names,
|
@Parameter(description = "Name (searches name field only)") @QueryParam("name") List<String> names,
|
||||||
@Parameter(description = "Filter names by list (partial matches allowed)") @QueryParam("namefilter") String nameListFilter,
|
|
||||||
@Parameter(description = "Prefix only (if true, only the beginning of fields are matched)") @QueryParam("prefix") Boolean prefixOnly,
|
@Parameter(description = "Prefix only (if true, only the beginning of fields are matched)") @QueryParam("prefix") Boolean prefixOnly,
|
||||||
@Parameter(description = "Default resources (without identifiers) only") @QueryParam("default") Boolean defaultResource,
|
@Parameter(description = "Default resources (without identifiers) only") @QueryParam("default") Boolean defaultResource,
|
||||||
@Parameter(ref = "limit") @QueryParam("limit") Integer limit,
|
@Parameter(description = "Filter names by list (exact matches only)") @QueryParam("namefilter") String nameListFilter,
|
||||||
@Parameter(ref = "offset") @QueryParam("offset") Integer offset,
|
|
||||||
@Parameter(ref = "reverse") @QueryParam("reverse") Boolean reverse,
|
|
||||||
@Parameter(description = "Include followed names only") @QueryParam("followedonly") Boolean followedOnly,
|
@Parameter(description = "Include followed names only") @QueryParam("followedonly") Boolean followedOnly,
|
||||||
@Parameter(description = "Exclude blocked content") @QueryParam("excludeblocked") Boolean excludeBlocked,
|
@Parameter(description = "Exclude blocked content") @QueryParam("excludeblocked") Boolean excludeBlocked,
|
||||||
@Parameter(description = "Include status") @QueryParam("includestatus") Boolean includeStatus,
|
@Parameter(description = "Include status") @QueryParam("includestatus") Boolean includeStatus,
|
||||||
@Parameter(description = "Include metadata") @QueryParam("includemetadata") Boolean includeMetadata) {
|
@Parameter(description = "Include metadata") @QueryParam("includemetadata") Boolean includeMetadata,
|
||||||
|
@Parameter(ref = "limit") @QueryParam("limit") Integer limit,
|
||||||
|
@Parameter(ref = "offset") @QueryParam("offset") Integer offset,
|
||||||
|
@Parameter(ref = "reverse") @QueryParam("reverse") Boolean reverse) {
|
||||||
|
|
||||||
try (final Repository repository = RepositoryManager.getRepository()) {
|
try (final Repository repository = RepositoryManager.getRepository()) {
|
||||||
|
|
||||||
boolean defaultRes = Boolean.TRUE.equals(defaultResource);
|
boolean defaultRes = Boolean.TRUE.equals(defaultResource);
|
||||||
boolean usePrefixOnly = Boolean.TRUE.equals(prefixOnly);
|
boolean usePrefixOnly = Boolean.TRUE.equals(prefixOnly);
|
||||||
|
|
||||||
|
List<String> exactMatchNames = new ArrayList<>();
|
||||||
|
|
||||||
if (nameListFilter != null) {
|
if (nameListFilter != null) {
|
||||||
// Load names from supplied list of names
|
// Load names from supplied list of names
|
||||||
names.addAll(ResourceListManager.getInstance().getStringsInList(nameListFilter));
|
exactMatchNames.addAll(ResourceListManager.getInstance().getStringsInList(nameListFilter));
|
||||||
}
|
}
|
||||||
|
|
||||||
List<ArbitraryResourceInfo> resources = repository.getArbitraryRepository()
|
List<ArbitraryResourceInfo> resources = repository.getArbitraryRepository()
|
||||||
.searchArbitraryResources(service, query, identifier, names, usePrefixOnly, defaultRes, followedOnly, excludeBlocked, limit, offset, reverse);
|
.searchArbitraryResources(service, query, identifier, names, usePrefixOnly, exactMatchNames, defaultRes, followedOnly, excludeBlocked, limit, offset, reverse);
|
||||||
|
|
||||||
if (resources == null) {
|
if (resources == null) {
|
||||||
return new ArrayList<>();
|
return new ArrayList<>();
|
||||||
|
@ -26,7 +26,7 @@ public interface ArbitraryRepository {
|
|||||||
|
|
||||||
public List<ArbitraryResourceInfo> getArbitraryResources(Service service, String identifier, List<String> names, boolean defaultResource, Boolean followedOnly, Boolean excludeBlocked, Integer limit, Integer offset, Boolean reverse) throws DataException;
|
public List<ArbitraryResourceInfo> getArbitraryResources(Service service, String identifier, List<String> names, boolean defaultResource, Boolean followedOnly, Boolean excludeBlocked, Integer limit, Integer offset, Boolean reverse) throws DataException;
|
||||||
|
|
||||||
public List<ArbitraryResourceInfo> searchArbitraryResources(Service service, String query, String identifier, List<String> names, boolean prefixOnly, boolean defaultResource, Boolean followedOnly, Boolean excludeBlocked, Integer limit, Integer offset, Boolean reverse) throws DataException;
|
public List<ArbitraryResourceInfo> searchArbitraryResources(Service service, String query, String identifier, List<String> names, boolean prefixOnly, List<String> namesFilter, boolean defaultResource, Boolean followedOnly, Boolean excludeBlocked, Integer limit, Integer offset, Boolean reverse) throws DataException;
|
||||||
|
|
||||||
public List<ArbitraryResourceNameInfo> getArbitraryResourceCreatorNames(Service service, String identifier, boolean defaultResource, Integer limit, Integer offset, Boolean reverse) throws DataException;
|
public List<ArbitraryResourceNameInfo> getArbitraryResourceCreatorNames(Service service, String identifier, boolean defaultResource, Integer limit, Integer offset, Boolean reverse) throws DataException;
|
||||||
|
|
||||||
|
@ -393,7 +393,7 @@ public class HSQLDBArbitraryRepository implements ArbitraryRepository {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<ArbitraryResourceInfo> searchArbitraryResources(Service service, String query, String identifier, List<String> names, boolean prefixOnly,
|
public List<ArbitraryResourceInfo> searchArbitraryResources(Service service, String query, String identifier, List<String> names, boolean prefixOnly,
|
||||||
boolean defaultResource, Boolean followedOnly, Boolean excludeBlocked,
|
List<String> exactMatchNames, boolean defaultResource, Boolean followedOnly, Boolean excludeBlocked,
|
||||||
Integer limit, Integer offset, Boolean reverse) throws DataException {
|
Integer limit, Integer offset, Boolean reverse) throws DataException {
|
||||||
StringBuilder sql = new StringBuilder(512);
|
StringBuilder sql = new StringBuilder(512);
|
||||||
List<Object> bindParams = new ArrayList<>();
|
List<Object> bindParams = new ArrayList<>();
|
||||||
@ -436,7 +436,7 @@ public class HSQLDBArbitraryRepository implements ArbitraryRepository {
|
|||||||
bindParams.add(queryWildcard);
|
bindParams.add(queryWildcard);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle name matches
|
// Handle name searches
|
||||||
if (names != null && !names.isEmpty()) {
|
if (names != null && !names.isEmpty()) {
|
||||||
sql.append(" AND (");
|
sql.append(" AND (");
|
||||||
|
|
||||||
@ -450,6 +450,18 @@ public class HSQLDBArbitraryRepository implements ArbitraryRepository {
|
|||||||
sql.append(")");
|
sql.append(")");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Handle name exact matches
|
||||||
|
if (exactMatchNames != null && !exactMatchNames.isEmpty()) {
|
||||||
|
sql.append(" AND name IN (?");
|
||||||
|
bindParams.add(exactMatchNames.get(0));
|
||||||
|
|
||||||
|
for (int i = 1; i < exactMatchNames.size(); ++i) {
|
||||||
|
sql.append(", ?");
|
||||||
|
bindParams.add(exactMatchNames.get(i));
|
||||||
|
}
|
||||||
|
sql.append(")");
|
||||||
|
}
|
||||||
|
|
||||||
// Handle "followed only"
|
// Handle "followed only"
|
||||||
if (followedOnly != null && followedOnly) {
|
if (followedOnly != null && followedOnly) {
|
||||||
List<String> followedNames = ListUtils.followedNames();
|
List<String> followedNames = ListUtils.followedNames();
|
||||||
|
Loading…
Reference in New Issue
Block a user