mirror of
https://github.com/sismics/docs.git
synced 2024-11-22 05:57:57 +01:00
Finding several documents by their title in a single query (#696)
This commit is contained in:
parent
a9cdbdc03e
commit
22a44d0c8d
@ -84,9 +84,9 @@ public class DocumentCriteria {
|
|||||||
private String mimeType;
|
private String mimeType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The title.
|
* Titles to include.
|
||||||
*/
|
*/
|
||||||
private String title;
|
private List<String> titleList = new ArrayList<>();
|
||||||
|
|
||||||
public List<String> getTargetIdList() {
|
public List<String> getTargetIdList() {
|
||||||
return targetIdList;
|
return targetIdList;
|
||||||
@ -192,11 +192,7 @@ public class DocumentCriteria {
|
|||||||
this.mimeType = mimeType;
|
this.mimeType = mimeType;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getTitle() {
|
public List<String> getTitleList() {
|
||||||
return title;
|
return titleList;
|
||||||
}
|
|
||||||
|
|
||||||
public void setTitle(String title) {
|
|
||||||
this.title = title;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -295,9 +295,9 @@ public class LuceneIndexingHandler implements IndexingHandler {
|
|||||||
criteriaList.add("d.DOC_UPDATEDATE_D <= :updateDateMax");
|
criteriaList.add("d.DOC_UPDATEDATE_D <= :updateDateMax");
|
||||||
parameterMap.put("updateDateMax", criteria.getUpdateDateMax());
|
parameterMap.put("updateDateMax", criteria.getUpdateDateMax());
|
||||||
}
|
}
|
||||||
if (criteria.getTitle() != null) {
|
if (!criteria.getTitleList().isEmpty()) {
|
||||||
criteriaList.add("d.DOC_TITLE_C = :title");
|
criteriaList.add("d.DOC_TITLE_C in :title");
|
||||||
parameterMap.put("title", criteria.getTitle());
|
parameterMap.put("title", criteria.getTitleList());
|
||||||
}
|
}
|
||||||
if (!criteria.getTagIdList().isEmpty()) {
|
if (!criteria.getTagIdList().isEmpty()) {
|
||||||
int index = 0;
|
int index = 0;
|
||||||
|
@ -495,7 +495,36 @@ public class DocumentResource extends BaseResource {
|
|||||||
|
|
||||||
return Response.ok().entity(response.build()).build();
|
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.:
|
* Parse a query according to the specified syntax, eg.:
|
||||||
* tag:assurance tag:other before:2012 after:2011-09 shared:yes lang:fra thing
|
* tag:assurance tag:other before:2012 after:2011-09 shared:yes lang:fra thing
|
||||||
@ -663,7 +692,7 @@ public class DocumentResource extends BaseResource {
|
|||||||
break;
|
break;
|
||||||
case "title":
|
case "title":
|
||||||
// New title criteria
|
// New title criteria
|
||||||
documentCriteria.setTitle(paramValue);
|
documentCriteria.getTitleList().add(paramValue);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
fullQuery.add(criteria);
|
fullQuery.add(criteria);
|
||||||
|
@ -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`)
|
* `mime:VALUE`: the document must be of the specified mime type (example: `image/png`)
|
||||||
* Shared
|
* Shared
|
||||||
* `shared:VALUE`: if `VALUE` is `yes`the document must be shared, for other `VALUE`s the criteria is ignored
|
* `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 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
|
* `!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`
|
* `title:VALUE`: the title of the document must be `VALUE`
|
||||||
* User
|
* User
|
||||||
* `by:VALUE`: the document creator's username must be `VALUE` with an exact match, the user must not be deleted
|
* `by:VALUE`: the document creator's username must be `VALUE` with an exact match, the user must not be deleted
|
||||||
|
@ -81,8 +81,17 @@ public class TestDocumentResource extends BaseJerseyTest {
|
|||||||
.param("create_date", Long.toString(create1Date))), JsonObject.class);
|
.param("create_date", Long.toString(create1Date))), JsonObject.class);
|
||||||
String document1Id = json.getString("id");
|
String document1Id = json.getString("id");
|
||||||
Assert.assertNotNull(document1Id);
|
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()
|
json = target().path("/document").request()
|
||||||
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, document1Token)
|
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, document1Token)
|
||||||
.put(Entity.form(new Form()
|
.put(Entity.form(new Form()
|
||||||
@ -92,16 +101,7 @@ public class TestDocumentResource extends BaseJerseyTest {
|
|||||||
.param("relations", document1Id)), JsonObject.class);
|
.param("relations", document1Id)), JsonObject.class);
|
||||||
String document2Id = json.getString("id");
|
String document2Id = json.getString("id");
|
||||||
Assert.assertNotNull(document2Id);
|
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
|
// List all documents
|
||||||
json = target().path("/document/list")
|
json = target().path("/document/list")
|
||||||
.queryParam("sort_column", 3)
|
.queryParam("sort_column", 3)
|
||||||
@ -148,10 +148,19 @@ public class TestDocumentResource extends BaseJerseyTest {
|
|||||||
String document3Id = json.getString("id");
|
String document3Id = json.getString("id");
|
||||||
Assert.assertNotNull(document3Id);
|
Assert.assertNotNull(document3Id);
|
||||||
|
|
||||||
// Add a file
|
// Add a file to this document
|
||||||
clientUtil.addFileToDocument(FILE_EINSTEIN_ROOSEVELT_LETTER_PNG,
|
clientUtil.addFileToDocument(FILE_EINSTEIN_ROOSEVELT_LETTER_PNG,
|
||||||
document3Token, document3Id);
|
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
|
// List all documents from document3
|
||||||
json = target().path("/document/list")
|
json = target().path("/document/list")
|
||||||
.queryParam("sort_column", 3)
|
.queryParam("sort_column", 3)
|
||||||
@ -160,7 +169,7 @@ public class TestDocumentResource extends BaseJerseyTest {
|
|||||||
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, document3Token)
|
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, document3Token)
|
||||||
.get(JsonObject.class);
|
.get(JsonObject.class);
|
||||||
documents = json.getJsonArray("documents");
|
documents = json.getJsonArray("documents");
|
||||||
Assert.assertEquals(1, documents.size());
|
Assert.assertEquals(2, documents.size());
|
||||||
|
|
||||||
// Check highlights
|
// Check highlights
|
||||||
json = target().path("/document/list")
|
json = target().path("/document/list")
|
||||||
@ -216,6 +225,7 @@ public class TestDocumentResource extends BaseJerseyTest {
|
|||||||
Assert.assertEquals(0, searchDocuments("mime:empty/void", document1Token));
|
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("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(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)
|
// Search documents (nothing)
|
||||||
Assert.assertEquals(0, searchDocuments("random", document1Token));
|
Assert.assertEquals(0, searchDocuments("random", document1Token));
|
||||||
|
Loading…
Reference in New Issue
Block a user