Commit f21a50e9 authored by redmitry@list.ru's avatar redmitry@list.ru

add "confidence" search param

parent 295c5c56
......@@ -60,7 +60,8 @@ import org.bson.json.JsonWriter;
public class MongoQueries {
public static int searchToolsCount(ToolsDAO toolsDAO, String id, String text, String name, String homepage, String description, List<String> tags) {
public static int searchToolsCount(ToolsDAO toolsDAO, String id, String text,
String name, String homepage, String description, List<String> confidence, List<String> tags) {
try {
final MongoCollection<Document> col = toolsDAO.database.getCollection(toolsDAO.collection);
......@@ -83,6 +84,10 @@ public class MongoQueries {
aggregation.add(Aggregates.match(Filters.regex("description", description, "i")));
}
if (confidence != null && !confidence.isEmpty()) {
aggregation.add(Aggregates.match(Filters.in("confidence", confidence)));
}
if (tags != null && !tags.isEmpty()) {
aggregation.add(Aggregates.match(Filters.in("tags", tags)));
}
......@@ -129,7 +134,7 @@ public class MongoQueries {
*/
public static void searchTools(ToolsDAO toolsDAO, Writer writer, String id, Long skip, Long limit,
String text, String name, String homepage, String description, List<String> projections) {
searchTools(toolsDAO, writer, id, skip, limit, text, name, homepage, description, null, projections);
searchTools(toolsDAO, writer, id, skip, limit, text, name, homepage, description, null, null, projections);
}
/**
......@@ -148,7 +153,7 @@ public class MongoQueries {
* @param projections - properties to write or null for all.
*/
public static void searchTools(ToolsDAO toolsDAO, Writer writer, String id, Long skip, Long limit,
String text, String name, String homepage, String description, List<String> tags, List<String> projections) {
String text, String name, String homepage, String description, List<String> confidence, List<String> tags, List<String> projections) {
try {
final MongoCollection<Document> col = toolsDAO.database.getCollection(toolsDAO.collection);
try (JsonWriter jwriter = new AbstractDAO.ReusableJsonWriter(writer)) {
......@@ -181,6 +186,10 @@ public class MongoQueries {
if (description != null && !description.isEmpty()) {
aggregation.add(Aggregates.match(Filters.regex("description", description, "i")));
}
if (confidence != null && !confidence.isEmpty()) {
aggregation.add(Aggregates.match(Filters.in("confidence", confidence)));
}
if (tags != null && !tags.isEmpty()) {
aggregation.add(Aggregates.match(Filters.in("tags", tags)));
......@@ -249,12 +258,12 @@ public class MongoQueries {
public static int aggregateToolsCount(
ToolsDAO toolsDAO, String id, String text, String name,
String description, List<String> types, String[] edam_terms) {
return aggregateToolsCount(toolsDAO, id, text, name, description, null, types, edam_terms);
return aggregateToolsCount(toolsDAO, id, text, name, description, null, null, types, edam_terms);
}
public static int aggregateToolsCount(
ToolsDAO toolsDAO, String id, String text, String name,
String description, List<String> tags, List<String> types, String[] edam_terms) {
ToolsDAO toolsDAO, String id, String text, String name, String description,
List<String> confidence, List<String> tags, List<String> types, String[] edam_terms) {
final MongoCollection<Document> col = toolsDAO.database.getCollection(toolsDAO.collection);
final ArrayList<Bson> aggregation = new ArrayList();
......@@ -273,6 +282,10 @@ public class MongoQueries {
if (description != null && !description.isEmpty()) {
aggregation.add(Aggregates.match(Filters.regex("description", description, "i")));
}
if (confidence != null && !confidence.isEmpty()) {
aggregation.add(Aggregates.match(Filters.in("confidence", confidence)));
}
if (tags != null && !tags.isEmpty()) {
aggregation.add(Aggregates.match(Filters.in("tags", tags)));
......@@ -322,14 +335,15 @@ public class MongoQueries {
Writer writer, String id, Long skip,
Long limit, String text, String name, String description,
List<String> types, List<String> projections, String[] edam_terms) {
aggregateTools(toolsDAO, metricsDAO, writer, id, skip, limit, text, name, description, null, types, projections, edam_terms);
aggregateTools(toolsDAO, metricsDAO, writer, id, skip, limit, text, name,
description, null,null, types, projections, edam_terms);
}
public static void aggregateTools(
ToolsDAO toolsDAO, MetricsDAO metricsDAO,
Writer writer, String id, Long skip,
Long limit, String text, String name, String description, List<String> tags,
List<String> types, List<String> projections, String[] edam_terms) {
Long limit, String text, String name, String description, List<String> confidence,
List<String> tags, List<String> types, List<String> projections, String[] edam_terms) {
try {
final MongoCollection<Document> col = toolsDAO.database.getCollection(toolsDAO.collection);
try (JsonWriter jwriter = new AbstractDAO.ReusableJsonWriter(writer)) {
......@@ -361,6 +375,10 @@ public class MongoQueries {
if (description != null && !description.isEmpty()) {
aggregation.add(Aggregates.match(Filters.regex("description", description, "i")));
}
if (confidence != null && !confidence.isEmpty()) {
aggregation.add(Aggregates.match(Filters.in("confidence", confidence)));
}
if (tags != null && !tags.isEmpty()) {
aggregation.add(Aggregates.match(Filters.in("tags", tags)));
......
......@@ -167,6 +167,9 @@ public class MonitorRestServices {
@QueryParam("description")
@Parameter(description = "text to search in the 'description' property")
final String description,
@QueryParam("confidence")
@Parameter(description = "values to match the 'confidence' property")
final List<String> confidence,
@QueryParam("tags")
@Parameter(description = "text to match the 'tags' property")
final List<String> tags,
......@@ -174,7 +177,7 @@ public class MonitorRestServices {
executor.submit(() -> {
if (range != null) {
asyncResponse.resume(searchAsync(id, range.getFirstPos(),
range.getLastPos(), projections, text, name, homepage, description, tags)
range.getLastPos(), projections, text, name, homepage, description, confidence, tags)
.header("Access-Control-Allow-Headers", "Range")
.header("Access-Control-Expose-Headers", "Accept-Ranges")
.header("Access-Control-Expose-Headers", "Content-Range")
......@@ -185,7 +188,7 @@ public class MonitorRestServices {
to += skip;
}
asyncResponse.resume(searchAsync(id, skip, to, projections, text, name, homepage, description, tags)
asyncResponse.resume(searchAsync(id, skip, to, projections, text, name, homepage, description, confidence, tags)
.header("Access-Control-Allow-Headers", "Range")
.header("Access-Control-Expose-Headers", "Accept-Ranges")
.header("Access-Control-Expose-Headers", "Content-Range")
......@@ -203,6 +206,7 @@ public class MonitorRestServices {
final String name,
final String homepage,
final String description,
final List<String> confidence,
final List<String> tags) {
StreamingOutput stream = (OutputStream out) -> {
......@@ -215,11 +219,13 @@ public class MonitorRestServices {
}
try (Writer writer = new BufferedWriter(new OutputStreamWriter(out, "UTF-8"))) {
MongoQueries.searchTools(toolsDAO, writer, id, from, limit, text, name, homepage, description, tags, projections);
MongoQueries.searchTools(toolsDAO, writer, id, from, limit, text, name,
homepage, description, confidence, tags, projections);
}
};
final long count = MongoQueries.searchToolsCount(toolsDAO, id, text, name, homepage, description, tags);
final long count = MongoQueries.searchToolsCount(toolsDAO, id, text, name, homepage,
description, confidence, tags);
final ContentRange range = new ContentRange("tools", from, to, count);
......@@ -274,6 +280,9 @@ public class MonitorRestServices {
@QueryParam("description")
@Parameter(description = "text to search in the 'description' property")
final String description,
@QueryParam("confidence")
@Parameter(description = "values to match the 'confidence' property")
final List<String> confidence,
@QueryParam("tags")
@Parameter(description = "text to match the 'tags' property")
final List<String> tags,
......@@ -287,7 +296,8 @@ public class MonitorRestServices {
executor.submit(() -> {
if (range != null) {
asyncResponse.resume(aggregateAsync(
id, range.getFirstPos(), range.getLastPos(), projections, text, name, description, tags, types, edam_term)
id, range.getFirstPos(), range.getLastPos(), projections, text,
name, description, confidence, tags, types, edam_term)
.header("Access-Control-Allow-Headers", "Range")
.header("Access-Control-Expose-Headers", "Accept-Ranges")
.header("Access-Control-Expose-Headers", "Content-Range")
......@@ -298,7 +308,8 @@ public class MonitorRestServices {
to += skip;
}
asyncResponse.resume(aggregateAsync(id, skip, to, projections, text, name, description, tags, types, edam_term)
asyncResponse.resume(aggregateAsync(id, skip, to, projections, text, name,
description, confidence, tags, types, edam_term)
.header("Access-Control-Allow-Headers", "Range")
.header("Access-Control-Expose-Headers", "Accept-Ranges")
.header("Access-Control-Expose-Headers", "Content-Range")
......@@ -314,6 +325,7 @@ public class MonitorRestServices {
final String text,
final String name,
final String description,
final List<String> confidence,
final List<String> tags,
final List<String> types,
final String edam_term) {
......@@ -327,11 +339,11 @@ public class MonitorRestServices {
}
try (Writer writer = new BufferedWriter(new OutputStreamWriter(out, "UTF-8"))) {
MongoQueries.aggregateTools(toolsDAO, metricsDAO, writer, id, limit,
limit, text, name, description, tags, types, projections, null);
limit, text, name, description, confidence, tags, types, projections, null);
}
};
final long count = MongoQueries.aggregateToolsCount(
toolsDAO, id, text, name, description, tags, types, null);
toolsDAO, id, text, name, description, confidence, tags, types, null);
final ContentRange range = new ContentRange("items", from, to, count);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment