mirror of
https://github.com/sismics/docs.git
synced 2024-11-22 14:07:55 +01:00
Closes #227: fix searching by tag
This commit is contained in:
parent
cedd4b47b3
commit
6d35020840
@ -47,8 +47,9 @@ public class DocumentCriteria {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Tag IDs.
|
* Tag IDs.
|
||||||
|
* The first level list will be AND'ed and the second level list will be OR'ed.
|
||||||
*/
|
*/
|
||||||
private List<String> tagIdList;
|
private List<List<String>> tagIdList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Shared status.
|
* Shared status.
|
||||||
@ -110,11 +111,11 @@ public class DocumentCriteria {
|
|||||||
this.createDateMax = createDateMax;
|
this.createDateMax = createDateMax;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> getTagIdList() {
|
public List<List<String>> getTagIdList() {
|
||||||
return tagIdList;
|
return tagIdList;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTagIdList(List<String> tagIdList) {
|
public void setTagIdList(List<List<String>> tagIdList) {
|
||||||
this.tagIdList = tagIdList;
|
this.tagIdList = tagIdList;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -162,8 +163,7 @@ public class DocumentCriteria {
|
|||||||
this.updateDateMax = updateDateMax;
|
this.updateDateMax = updateDateMax;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DocumentCriteria setActiveRoute(Boolean activeRoute) {
|
public void setActiveRoute(Boolean activeRoute) {
|
||||||
this.activeRoute = activeRoute;
|
this.activeRoute = activeRoute;
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -245,8 +245,9 @@ public class LuceneIndexingHandler implements IndexingHandler {
|
|||||||
}
|
}
|
||||||
if (criteria.getTagIdList() != null && !criteria.getTagIdList().isEmpty()) {
|
if (criteria.getTagIdList() != null && !criteria.getTagIdList().isEmpty()) {
|
||||||
int index = 0;
|
int index = 0;
|
||||||
|
for (List<String> tagIdList : criteria.getTagIdList()) {
|
||||||
List<String> tagCriteriaList = Lists.newArrayList();
|
List<String> tagCriteriaList = Lists.newArrayList();
|
||||||
for (String tagId : criteria.getTagIdList()) {
|
for (String tagId : tagIdList) {
|
||||||
sb.append(String.format("left join T_DOCUMENT_TAG dt%d on dt%d.DOT_IDDOCUMENT_C = d.DOC_ID_C and dt%d.DOT_IDTAG_C = :tagId%d and dt%d.DOT_DELETEDATE_D is null ", index, index, index, index, index));
|
sb.append(String.format("left join T_DOCUMENT_TAG dt%d on dt%d.DOT_IDDOCUMENT_C = d.DOC_ID_C and dt%d.DOT_IDTAG_C = :tagId%d and dt%d.DOT_DELETEDATE_D is null ", index, index, index, index, index));
|
||||||
parameterMap.put("tagId" + index, tagId);
|
parameterMap.put("tagId" + index, tagId);
|
||||||
tagCriteriaList.add(String.format("dt%d.DOT_ID_C is not null", index));
|
tagCriteriaList.add(String.format("dt%d.DOT_ID_C is not null", index));
|
||||||
@ -254,6 +255,7 @@ public class LuceneIndexingHandler implements IndexingHandler {
|
|||||||
}
|
}
|
||||||
criteriaList.add("(" + Joiner.on(" OR ").join(tagCriteriaList) + ")");
|
criteriaList.add("(" + Joiner.on(" OR ").join(tagCriteriaList) + ")");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (criteria.getShared() != null && criteria.getShared()) {
|
if (criteria.getShared() != null && criteria.getShared()) {
|
||||||
criteriaList.add("s.count > 0");
|
criteriaList.add("s.count > 0");
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package com.sismics.docs.rest.resource;
|
|||||||
|
|
||||||
import com.google.common.base.Joiner;
|
import com.google.common.base.Joiner;
|
||||||
import com.google.common.base.Strings;
|
import com.google.common.base.Strings;
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
import com.sismics.docs.core.constant.AclType;
|
import com.sismics.docs.core.constant.AclType;
|
||||||
import com.sismics.docs.core.constant.ConfigType;
|
import com.sismics.docs.core.constant.ConfigType;
|
||||||
import com.sismics.docs.core.constant.Constants;
|
import com.sismics.docs.core.constant.Constants;
|
||||||
@ -452,15 +453,18 @@ public class DocumentResource extends BaseResource {
|
|||||||
}
|
}
|
||||||
if (tagDtoList.isEmpty()) {
|
if (tagDtoList.isEmpty()) {
|
||||||
// No tag found, the request must returns nothing
|
// No tag found, the request must returns nothing
|
||||||
documentCriteria.getTagIdList().add(UUID.randomUUID().toString());
|
documentCriteria.getTagIdList().add(Lists.newArrayList(UUID.randomUUID().toString()));
|
||||||
}
|
} else {
|
||||||
|
List<String> tagIdList = Lists.newArrayList();
|
||||||
for (TagDto tagDto : tagDtoList) {
|
for (TagDto tagDto : tagDtoList) {
|
||||||
documentCriteria.getTagIdList().add(tagDto.getId());
|
tagIdList.add(tagDto.getId());
|
||||||
List<TagDto> childrenTagDtoList = TagUtil.findChildren(tagDto, allTagDtoList);
|
List<TagDto> childrenTagDtoList = TagUtil.findChildren(tagDto, allTagDtoList);
|
||||||
for (TagDto childrenTagDto : childrenTagDtoList) {
|
for (TagDto childrenTagDto : childrenTagDtoList) {
|
||||||
documentCriteria.getTagIdList().add(childrenTagDto.getId());
|
tagIdList.add(childrenTagDto.getId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
documentCriteria.getTagIdList().add(tagIdList);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case "after":
|
case "after":
|
||||||
case "before":
|
case "before":
|
||||||
|
@ -188,7 +188,7 @@ public class TestDocumentResource extends BaseJerseyTest {
|
|||||||
Assert.assertEquals(2, searchDocuments("uat:" + DateTimeFormat.forPattern("yyyy-MM-dd").print(new Date().getTime()), document1Token));
|
Assert.assertEquals(2, searchDocuments("uat:" + DateTimeFormat.forPattern("yyyy-MM-dd").print(new Date().getTime()), document1Token));
|
||||||
Assert.assertEquals(2, searchDocuments("uafter:2010 ubefore:2040-08", document1Token));
|
Assert.assertEquals(2, searchDocuments("uafter:2010 ubefore:2040-08", document1Token));
|
||||||
Assert.assertEquals(1, searchDocuments("tag:super", document1Token));
|
Assert.assertEquals(1, searchDocuments("tag:super", document1Token));
|
||||||
// TODO waiting for #227 Assert.assertEquals(1, searchDocuments("tag:super tag:hr", document1Token));
|
Assert.assertEquals(1, searchDocuments("tag:super tag:hr", document1Token));
|
||||||
Assert.assertEquals(1, searchDocuments("shared:yes", document1Token));
|
Assert.assertEquals(1, searchDocuments("shared:yes", document1Token));
|
||||||
Assert.assertEquals(2, searchDocuments("lang:eng", document1Token));
|
Assert.assertEquals(2, searchDocuments("lang:eng", document1Token));
|
||||||
Assert.assertEquals(1, searchDocuments("after:2010 before:2040-08 tag:super shared:yes lang:eng title description full:uranium", document1Token));
|
Assert.assertEquals(1, searchDocuments("after:2010 before:2040-08 tag:super shared:yes lang:eng title description full:uranium", document1Token));
|
||||||
|
Loading…
Reference in New Issue
Block a user