Finding several documents by their title in a single query (#696)

This commit is contained in:
Julien Kirch 2023-06-06 21:31:01 +02:00 committed by GitHub
parent a9cdbdc03e
commit 22a44d0c8d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 63 additions and 28 deletions

View File

@ -84,9 +84,9 @@ public class DocumentCriteria {
private String mimeType;
/**
* The title.
* Titles to include.
*/
private String title;
private List<String> titleList = new ArrayList<>();
public List<String> getTargetIdList() {
return targetIdList;
@ -192,11 +192,7 @@ public class DocumentCriteria {
this.mimeType = mimeType;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
public List<String> getTitleList() {
return titleList;
}
}

View File

@ -295,9 +295,9 @@ public class LuceneIndexingHandler implements IndexingHandler {
criteriaList.add("d.DOC_UPDATEDATE_D <= :updateDateMax");
parameterMap.put("updateDateMax", criteria.getUpdateDateMax());
}
if (criteria.getTitle() != null) {
criteriaList.add("d.DOC_TITLE_C = :title");
parameterMap.put("title", criteria.getTitle());
if (!criteria.getTitleList().isEmpty()) {
criteriaList.add("d.DOC_TITLE_C in :title");
parameterMap.put("title", criteria.getTitleList());
}
if (!criteria.getTagIdList().isEmpty()) {
int index = 0;

View File

@ -495,7 +495,36 @@ public class DocumentResource extends BaseResource {
return Response.ok().entity(response.build()).build();
}
/**
* Returns all documents.
*
* @api {post} /document/list Get documents
* @apiDescription Get documents exposed as a POST endpoint to allow longer search parameters, see the GET endpoint for the API info
* @apiName PostDocumentList
* @apiGroup Document
* @apiVersion 1.12.0
*
* @param limit Page limit
* @param offset Page offset
* @param sortColumn Sort column
* @param asc Sorting
* @param search Search query
* @param files Files list
* @return Response
*/
@POST
@Path("list")
public Response listPost(
@FormParam("limit") Integer limit,
@FormParam("offset") Integer offset,
@FormParam("sort_column") Integer sortColumn,
@FormParam("asc") Boolean asc,
@FormParam("search") String search,
@FormParam("files") Boolean files) {
return list(limit, offset, sortColumn, asc, search, files);
}
/**
* Parse a query according to the specified syntax, eg.:
* tag:assurance tag:other before:2012 after:2011-09 shared:yes lang:fra thing
@ -663,7 +692,7 @@ public class DocumentResource extends BaseResource {
break;
case "title":
// New title criteria
documentCriteria.setTitle(paramValue);
documentCriteria.getTitleList().add(paramValue);
break;
default:
fullQuery.add(criteria);

View File

@ -77,10 +77,10 @@ If a search `VALUE` is considered invalid, the search result will be empty.
* `mime:VALUE`: the document must be of the specified mime type (example: `image/png`)
* Shared
* `shared:VALUE`: if `VALUE` is `yes`the document must be shared, for other `VALUE`s the criteria is ignored
* Tags
* Tags: several `tags` or `!tag:` can be specified and the document must match all filters
* `tag:VALUE`: the document must contain a tag or a child of a tag that starts with `VALUE`, case is ignored
* `!tag:VALUE`: the document must not contain a tag or a child of a tag that starts with `VALUE`, case is ignored
* Title
* Titles: several `title` can be specified, and the document must match any of the titles
* `title:VALUE`: the title of the document must be `VALUE`
* User
* `by:VALUE`: the document creator's username must be `VALUE` with an exact match, the user must not be deleted

View File

@ -81,8 +81,17 @@ public class TestDocumentResource extends BaseJerseyTest {
.param("create_date", Long.toString(create1Date))), JsonObject.class);
String document1Id = json.getString("id");
Assert.assertNotNull(document1Id);
// Create a document with document1
// Add a file to this document
String file1Id = clientUtil.addFileToDocument(FILE_EINSTEIN_ROOSEVELT_LETTER_PNG,
document1Token, document1Id);
// Share this document
target().path("/share").request()
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, document1Token)
.put(Entity.form(new Form().param("id", document1Id)), JsonObject.class);
// Create another document with document1
json = target().path("/document").request()
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, document1Token)
.put(Entity.form(new Form()
@ -92,16 +101,7 @@ public class TestDocumentResource extends BaseJerseyTest {
.param("relations", document1Id)), JsonObject.class);
String document2Id = json.getString("id");
Assert.assertNotNull(document2Id);
// Add a file
String file1Id = clientUtil.addFileToDocument(FILE_EINSTEIN_ROOSEVELT_LETTER_PNG,
document1Token, document1Id);
// Share this document
target().path("/share").request()
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, document1Token)
.put(Entity.form(new Form().param("id", document1Id)), JsonObject.class);
// List all documents
json = target().path("/document/list")
.queryParam("sort_column", 3)
@ -148,10 +148,19 @@ public class TestDocumentResource extends BaseJerseyTest {
String document3Id = json.getString("id");
Assert.assertNotNull(document3Id);
// Add a file
// Add a file to this document
clientUtil.addFileToDocument(FILE_EINSTEIN_ROOSEVELT_LETTER_PNG,
document3Token, document3Id);
// Create another document with document3
json = target().path("/document").request()
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, document3Token)
.put(Entity.form(new Form()
.param("title", "My_super_title_document_4")
.param("language", "eng")), JsonObject.class);
String document4Id = json.getString("id");
Assert.assertNotNull(document4Id);
// List all documents from document3
json = target().path("/document/list")
.queryParam("sort_column", 3)
@ -160,7 +169,7 @@ public class TestDocumentResource extends BaseJerseyTest {
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, document3Token)
.get(JsonObject.class);
documents = json.getJsonArray("documents");
Assert.assertEquals(1, documents.size());
Assert.assertEquals(2, documents.size());
// Check highlights
json = target().path("/document/list")
@ -216,6 +225,7 @@ public class TestDocumentResource extends BaseJerseyTest {
Assert.assertEquals(0, searchDocuments("mime:empty/void", document1Token));
Assert.assertEquals(1, searchDocuments("after:2010 before:2040-08 tag:super shared:yes lang:eng simple:title simple:description full:uranium", document1Token));
Assert.assertEquals(1, searchDocuments("title:My_super_title_document_3", document3Token));
Assert.assertEquals(2, searchDocuments("title:My_super_title_document_3 title:My_super_title_document_4", document3Token));
// Search documents (nothing)
Assert.assertEquals(0, searchDocuments("random", document1Token));