Add custom parameter for exact search by title

This commit is contained in:
Julien Kirch 2021-10-12 13:50:32 +02:00 committed by GitHub
parent b0d0e93364
commit d98c1bddec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 26 additions and 3 deletions

View File

@ -52,7 +52,7 @@ public class DocumentCriteria {
private List<List<String>> tagIdList;
/**
* Tag IDs to excluded.
* Tag IDs to exclude.
* The first and second level list will be excluded.
*/
private List<List<String>> excludedTagIdList;
@ -81,7 +81,12 @@ public class DocumentCriteria {
* MIME type of a file.
*/
private String mimeType;
/**
* The title.
*/
private String title;
public List<String> getTargetIdList() {
return targetIdList;
}
@ -194,4 +199,12 @@ public class DocumentCriteria {
public void setMimeType(String mimeType) {
this.mimeType = mimeType;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
}

View File

@ -295,6 +295,10 @@ 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.getTagIdList() != null && !criteria.getTagIdList().isEmpty()) {
int index = 0;
for (List<String> tagIdList : criteria.getTagIdList()) {

View File

@ -598,6 +598,10 @@ public class DocumentResource extends BaseResource {
// New fulltext search criteria
fullQuery.add(params[1]);
break;
case "title":
// New title criteria
documentCriteria.setTitle(params[1]);
break;
default:
fullQuery.add(criteria);
break;

View File

@ -143,7 +143,7 @@ public class TestDocumentResource extends BaseJerseyTest {
json = target().path("/document").request()
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, document3Token)
.put(Entity.form(new Form()
.param("title", "My super title document 3")
.param("title", "My_super_title_document_3")
.param("description", "My super description for document 3")
.param("language", "eng")
.param("create_date", Long.toString(create3Date))), JsonObject.class);
@ -217,6 +217,7 @@ public class TestDocumentResource extends BaseJerseyTest {
Assert.assertEquals(1, searchDocuments("mime:image/png", 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("title:My_super_title_document_3", document3Token));
// Search documents (nothing)
Assert.assertEquals(0, searchDocuments("random", document1Token));
@ -228,6 +229,7 @@ public class TestDocumentResource extends BaseJerseyTest {
Assert.assertEquals(0, searchDocuments("before:2040-05-38", document1Token));
Assert.assertEquals(0, searchDocuments("tag:Nop", document1Token));
Assert.assertEquals(0, searchDocuments("lang:fra", document1Token));
Assert.assertEquals(0, searchDocuments("title:Unknown title", document3Token));
// Get document 1
json = target().path("/document/" + document1Id).request()