forked from Qortal/qortal
Added prefix
parameter to GET /names/search
.
This commit is contained in:
parent
dc1289787d
commit
5a873f9465
@ -173,6 +173,7 @@ public class NamesResource {
|
|||||||
)
|
)
|
||||||
@ApiErrors({ApiError.NAME_UNKNOWN, ApiError.REPOSITORY_ISSUE})
|
@ApiErrors({ApiError.NAME_UNKNOWN, ApiError.REPOSITORY_ISSUE})
|
||||||
public List<NameData> searchNames(@QueryParam("query") String query,
|
public List<NameData> searchNames(@QueryParam("query") String query,
|
||||||
|
@Parameter(description = "Prefix only (if true, only the beginning of the name is matched)") @QueryParam("prefix") Boolean prefixOnly,
|
||||||
@Parameter(ref = "limit") @QueryParam("limit") Integer limit,
|
@Parameter(ref = "limit") @QueryParam("limit") Integer limit,
|
||||||
@Parameter(ref = "offset") @QueryParam("offset") Integer offset,
|
@Parameter(ref = "offset") @QueryParam("offset") Integer offset,
|
||||||
@Parameter(ref="reverse") @QueryParam("reverse") Boolean reverse) {
|
@Parameter(ref="reverse") @QueryParam("reverse") Boolean reverse) {
|
||||||
@ -181,7 +182,9 @@ public class NamesResource {
|
|||||||
throw ApiExceptionFactory.INSTANCE.createCustomException(request, ApiError.INVALID_CRITERIA, "Missing query");
|
throw ApiExceptionFactory.INSTANCE.createCustomException(request, ApiError.INVALID_CRITERIA, "Missing query");
|
||||||
}
|
}
|
||||||
|
|
||||||
return repository.getNameRepository().searchNames(query, limit, offset, reverse);
|
boolean usePrefixOnly = Boolean.TRUE.equals(prefixOnly);
|
||||||
|
|
||||||
|
return repository.getNameRepository().searchNames(query, usePrefixOnly, limit, offset, reverse);
|
||||||
} catch (ApiException e) {
|
} catch (ApiException e) {
|
||||||
throw e;
|
throw e;
|
||||||
} catch (DataException e) {
|
} catch (DataException e) {
|
||||||
|
@ -14,7 +14,7 @@ public interface NameRepository {
|
|||||||
|
|
||||||
public boolean reducedNameExists(String reducedName) throws DataException;
|
public boolean reducedNameExists(String reducedName) throws DataException;
|
||||||
|
|
||||||
public List<NameData> searchNames(String query, Integer limit, Integer offset, Boolean reverse) throws DataException;
|
public List<NameData> searchNames(String query, boolean prefixOnly, Integer limit, Integer offset, Boolean reverse) throws DataException;
|
||||||
|
|
||||||
public List<NameData> getAllNames(Integer limit, Integer offset, Boolean reverse) throws DataException;
|
public List<NameData> getAllNames(Integer limit, Integer offset, Boolean reverse) throws DataException;
|
||||||
|
|
||||||
|
@ -103,7 +103,7 @@ public class HSQLDBNameRepository implements NameRepository {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<NameData> searchNames(String query, Integer limit, Integer offset, Boolean reverse) throws DataException {
|
public List<NameData> searchNames(String query, boolean prefixOnly, 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<>();
|
||||||
|
|
||||||
@ -111,7 +111,10 @@ public class HSQLDBNameRepository implements NameRepository {
|
|||||||
+ "is_for_sale, sale_price, reference, creation_group_id FROM Names "
|
+ "is_for_sale, sale_price, reference, creation_group_id FROM Names "
|
||||||
+ "WHERE LCASE(name) LIKE ? ORDER BY name");
|
+ "WHERE LCASE(name) LIKE ? ORDER BY name");
|
||||||
|
|
||||||
bindParams.add(String.format("%%%s%%", query.toLowerCase()));
|
// Search anywhere in the name, unless "prefixOnly" has been requested
|
||||||
|
// Note that without prefixOnly it will bypass any indexes
|
||||||
|
String queryWildcard = prefixOnly ? String.format("%s%%", query.toLowerCase()) : String.format("%%%s%%", query.toLowerCase());
|
||||||
|
bindParams.add(queryWildcard);
|
||||||
|
|
||||||
if (reverse != null && reverse)
|
if (reverse != null && reverse)
|
||||||
sql.append(" DESC");
|
sql.append(" DESC");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user