1
0
mirror of https://github.com/sismics/docs.git synced 2025-12-13 01:36:18 +00:00

Closes #305: exclude tags from search

This commit is contained in:
Benjamin Gamard
2019-05-03 15:35:47 +02:00
parent d654564f6b
commit 8b1c41ae1e
5 changed files with 41 additions and 3 deletions

View File

@@ -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":

View File

@@ -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 {

View File

@@ -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));