优化一下搜索
This commit is contained in:
parent
a32a1893cb
commit
d07d4a8c91
|
|
@ -538,7 +538,6 @@ db.getBookmarksTable = function(params) {
|
|||
sql += " ORDER BY bookmarks.click_count DESC, bookmarks.created_at DESC";
|
||||
}
|
||||
}
|
||||
console.log(sql);
|
||||
return new Promise(function(resolve, reject) {
|
||||
client.query(sql, (err, result) => {
|
||||
if (err) {
|
||||
|
|
@ -571,26 +570,17 @@ db.getBookmarksByTag = function(params) {
|
|||
var sql = "SELECT bookmarks.id, bookmarks.user_id, bookmarks.title, bookmarks.description, bookmarks.url, bookmarks.public, bookmarks.click_count, DATE_FORMAT(bookmarks.created_at, '%Y-%m-%d') as created_at, DATE_FORMAT(bookmarks.last_click, '%Y-%m-%d') as last_click FROM `tags_bookmarks`, `bookmarks` WHERE tags_bookmarks.tag_id = '" + tag_id + "' AND tags_bookmarks.bookmark_id = bookmarks.id ORDER BY bookmarks.click_count DESC, bookmarks.created_at DESC";
|
||||
|
||||
return new Promise(function(resolve, reject) {
|
||||
client.query(sql, (err, result) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
} else {
|
||||
sql += " LIMIT " + (params.currentPage - 1) * params.perPageItems + ", " + params.perPageItems;
|
||||
var totalItems = result.length;
|
||||
console.log(totalItems, sql);
|
||||
client.query(sql, (err, result) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
} else {
|
||||
var bookmarksData = {
|
||||
totalItems: totalItems,
|
||||
bookmarks: result,
|
||||
totalItems: result.length,
|
||||
bookmarks: result.slice((params.currentPage - 1) * params.perPageItems, params.currentPage * params.perPageItems),
|
||||
}
|
||||
resolve(bookmarksData);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
|
|
@ -641,22 +631,19 @@ db.getBookmarksSearch = function(params) {
|
|||
if (err) {
|
||||
reject(err);
|
||||
} else {
|
||||
|
||||
sql += " LIMIT " + (params.currentPage - 1) * params.perPageItems + ", " + params.perPageItems;
|
||||
var totalItems = result.length;
|
||||
client.query(sql, (err, result) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
} else {
|
||||
// 如果是全站搜索,默认有限显示其他用户的
|
||||
if (params.userRange == '2') {
|
||||
result.sort((a, b) => {
|
||||
return params.userId == a.user_id ? 1 : -1;
|
||||
})
|
||||
}
|
||||
var searchData = {
|
||||
totalItems: totalItems,
|
||||
bookmarks: result,
|
||||
totalItems: result.length,
|
||||
bookmarks: result.splice((params.currentPage - 1) * params.perPageItems, params.currentPage * params.perPageItems),
|
||||
}
|
||||
resolve(searchData);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -126,14 +126,13 @@ app.controller('searchCtr', ['$scope', '$state', '$stateParams', '$filter', '$wi
|
|||
.then((data) => {
|
||||
pubSubService.publish('EditCtr.inserBookmarsSuccess', data);
|
||||
if (data.title) {
|
||||
toastr.success('[ ' + data.title + ' ] 收藏成功,将自动重新更新书签!', "提示");
|
||||
toastr.success('[ ' + data.title + ' ] 收藏成功!', "提示");
|
||||
} else {
|
||||
toastr.error('[ ' + bookmark.title + ' ] 收藏失败', "提示");
|
||||
toastr.error('[ ' + bookmark.title + ' ] 收藏失败!', "提示");
|
||||
}
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log('favoriteBookmark err', err);
|
||||
toastr.error('[ ' + bookmark.title + ' ] 收藏失败' + JSON.stringify(err), "提示");
|
||||
toastr.error('[ ' + bookmark.title + ' ] 收藏失败,' + JSON.stringify(err), "提示");
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
<div class="ui segment js-tags">
|
||||
<div class="ui container" ng-show="!editMode">
|
||||
<div class="ui grid">
|
||||
<div class="two wide column js-tag-label" ng-class="" ng-mouseover="" ng-mouseleave="" ng-repeat="tag in tags">
|
||||
<div class="two wide column js-tag-label" ng-if="tag.cnt" ng-repeat="tag in tags">
|
||||
<div class="ui small label" ng-class="{green:tag.bookmarkClicked}" ng-click="getBookmarks(tag.id, 1)">
|
||||
{{ tag.name }}
|
||||
({{ tag.cnt || 0 }})
|
||||
|
|
|
|||
|
|
@ -254,7 +254,6 @@ api.get('/bookmarks', function(req, res) {
|
|||
db.getTags(userId)
|
||||
.then((tags) => db.getBookmarksNavigate(tags))
|
||||
.then((result) => {
|
||||
console.log('ddddddddddddd')
|
||||
var data = [];
|
||||
var tag = {
|
||||
id: result && result[0] && result[0].tag_id,
|
||||
|
|
@ -295,7 +294,6 @@ api.get('/bookmarks', function(req, res) {
|
|||
click: item.click,
|
||||
}
|
||||
})
|
||||
console.log(JSON.stringify(temp));
|
||||
res.json(data);
|
||||
})
|
||||
.catch((err) => console.log('bookmarks navigate err', err));
|
||||
|
|
|
|||
Loading…
Reference in New Issue