mirror of
https://github.com/sismics/docs.git
synced 2024-11-22 05:57:57 +01:00
Closes #305: exclude tags from search
This commit is contained in:
parent
d654564f6b
commit
8b1c41ae1e
@ -51,6 +51,12 @@ public class DocumentCriteria {
|
||||
*/
|
||||
private List<List<String>> tagIdList;
|
||||
|
||||
/**
|
||||
* Tag IDs to excluded.
|
||||
* The first and second level list will be excluded.
|
||||
*/
|
||||
private List<List<String>> excludedTagIdList;
|
||||
|
||||
/**
|
||||
* Shared status.
|
||||
*/
|
||||
@ -119,6 +125,15 @@ public class DocumentCriteria {
|
||||
this.tagIdList = tagIdList;
|
||||
}
|
||||
|
||||
public List<List<String>> getExcludedTagIdList() {
|
||||
return excludedTagIdList;
|
||||
}
|
||||
|
||||
public DocumentCriteria setExcludedTagIdList(List<List<String>> excludedTagIdList) {
|
||||
this.excludedTagIdList = excludedTagIdList;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Boolean getShared() {
|
||||
return shared;
|
||||
}
|
||||
|
@ -309,6 +309,19 @@ public class LuceneIndexingHandler implements IndexingHandler {
|
||||
criteriaList.add("(" + Joiner.on(" OR ").join(tagCriteriaList) + ")");
|
||||
}
|
||||
}
|
||||
if (criteria.getExcludedTagIdList() != null && !criteria.getExcludedTagIdList().isEmpty()) {
|
||||
int index = 0;
|
||||
for (List<String> tagIdList : criteria.getExcludedTagIdList()) {
|
||||
List<String> tagCriteriaList = Lists.newArrayList();
|
||||
for (String tagId : tagIdList) {
|
||||
sb.append(String.format("left join T_DOCUMENT_TAG dtex%d on dtex%d.DOT_IDDOCUMENT_C = d.DOC_ID_C and dtex%d.DOT_IDTAG_C = :tagIdEx%d and dtex%d.DOT_DELETEDATE_D is null ", index, index, index, index, index));
|
||||
parameterMap.put("tagIdEx" + index, tagId);
|
||||
tagCriteriaList.add(String.format("dtex%d.DOT_ID_C is null", index));
|
||||
index++;
|
||||
}
|
||||
criteriaList.add("(" + Joiner.on(" AND ").join(tagCriteriaList) + ")");
|
||||
}
|
||||
}
|
||||
if (criteria.getShared() != null && criteria.getShared()) {
|
||||
criteriaList.add("s.count > 0");
|
||||
}
|
||||
|
@ -459,11 +459,15 @@ public class DocumentResource extends BaseResource {
|
||||
|
||||
switch (params[0]) {
|
||||
case "tag":
|
||||
case "!tag":
|
||||
// New tag criteria
|
||||
List<TagDto> tagDtoList = TagUtil.findByName(params[1], allTagDtoList);
|
||||
if (documentCriteria.getTagIdList() == null) {
|
||||
documentCriteria.setTagIdList(new ArrayList<>());
|
||||
}
|
||||
if (documentCriteria.getExcludedTagIdList() == null) {
|
||||
documentCriteria.setExcludedTagIdList(new ArrayList<>());
|
||||
}
|
||||
if (tagDtoList.isEmpty()) {
|
||||
// No tag found, the request must returns nothing
|
||||
documentCriteria.getTagIdList().add(Lists.newArrayList(UUID.randomUUID().toString()));
|
||||
@ -476,7 +480,11 @@ public class DocumentResource extends BaseResource {
|
||||
tagIdList.add(childrenTagDto.getId());
|
||||
}
|
||||
}
|
||||
documentCriteria.getTagIdList().add(tagIdList);
|
||||
if (params[0].startsWith("!")) {
|
||||
documentCriteria.getExcludedTagIdList().add(tagIdList);
|
||||
} else {
|
||||
documentCriteria.getTagIdList().add(tagIdList);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "after":
|
||||
|
@ -319,9 +319,9 @@ angular.module('docs').controller('Document', function ($scope, $rootScope, $tim
|
||||
*/
|
||||
$scope.extractNavigatedTag = function () {
|
||||
// Find the current tag in the search query
|
||||
var tagFound = /tag:([^ ]*)/.exec($scope.search);
|
||||
var tagFound = /(^| )tag:([^ ]*)/.exec($scope.search);
|
||||
if (tagFound) {
|
||||
tagFound = tagFound[1];
|
||||
tagFound = tagFound[2];
|
||||
// We search only for exact match
|
||||
$scope.navigatedTag = _.findWhere($scope.tags, { name: tagFound });
|
||||
} else {
|
||||
|
@ -209,7 +209,9 @@ public class TestDocumentResource extends BaseJerseyTest {
|
||||
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(1, searchDocuments("tag:super", document1Token));
|
||||
Assert.assertEquals(1, searchDocuments("!tag:super", document1Token));
|
||||
Assert.assertEquals(1, searchDocuments("tag:super tag:hr", document1Token));
|
||||
Assert.assertEquals(0, searchDocuments("tag:super !tag:hr", document1Token));
|
||||
Assert.assertEquals(1, searchDocuments("shared:yes", 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));
|
||||
|
Loading…
Reference in New Issue
Block a user