mirror of
https://gh-proxy.org/https://github.com/klinsmaya/VerticleSearchEngine.git
synced 2026-11-10 18:36:59 +08:00
basic publication recommend based on search key
This commit is contained in:
@@ -108,18 +108,7 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="tab-pane" id="tab2">
|
||||
<div class="alert alert-error">
|
||||
<strong>论文</strong> 收藏了XXX的用户,还收藏了。。。
|
||||
</div>
|
||||
<div class="alert alert-warning">
|
||||
<strong>论文</strong> 收藏了XXX的用户,还收藏了。。。
|
||||
</div>
|
||||
<div class="alert alert-success">
|
||||
<strong>论文</strong> 收藏了XXX的用户,还收藏了。。。
|
||||
</div>
|
||||
<div class="alert alert-info">
|
||||
<strong>论文</strong> 收藏了XXX的用户,还收藏了。。。
|
||||
</div>
|
||||
<button class="btn" type="button" id="recommend_btn" user="<%=loginName%>">Click</button>
|
||||
</div>
|
||||
<div class="tab-pane" id="tab3">
|
||||
<div class="tabbable">
|
||||
|
||||
@@ -6,6 +6,8 @@ $(function() {
|
||||
$('#user_paper_btn').remove();
|
||||
$('#share_history_btn').click(getUserGift($('#share_history_btn').attr("user")));
|
||||
$('#share_history_btn').remove();
|
||||
$('#recommend_btn').click(doRecommend($('#recommend_btn').attr("user")));
|
||||
$('#recommend_btn').remove();
|
||||
|
||||
// index.jsp
|
||||
leftSide();
|
||||
@@ -63,10 +65,10 @@ $(function() {
|
||||
showWordCloud();
|
||||
});
|
||||
|
||||
$('#related_btn').click(rightSide());
|
||||
$('#related_btn').click(relatedSide());
|
||||
$('#related_btn').remove();
|
||||
$('#related_btn').on("click", function(e) {
|
||||
rightSide();
|
||||
relatedSide();
|
||||
});
|
||||
|
||||
$('#rankpaper_btn').on("click", function(e) {
|
||||
@@ -162,6 +164,27 @@ function doRegister(user) {
|
||||
});
|
||||
}
|
||||
|
||||
function doRecommend(name) {
|
||||
$.ajax({
|
||||
type : 'GET',
|
||||
url : "recommend?user="+name,
|
||||
dataType : 'json',
|
||||
success : function(data) {
|
||||
var list = data.list;
|
||||
for (var i = 0; i < list.length; i ++) {
|
||||
$('#tab2').append('<div class="alert alert-error"><strong>论文推荐</strong><br />'
|
||||
+ '<span class="label label-important">关键词</span> ' + list[i].sk + '<br />'
|
||||
+'<span class="label label-info">Title</span><a href="academic?core=core1&key='+list[i].title+'">'+ list[i].title +'</a><br />'
|
||||
+'<a href="user?username='+list[i].author+'">'+list[i].author +'</a> 收藏于 '+list[i].date
|
||||
+'</div>');
|
||||
}
|
||||
},
|
||||
error : function(XmlHttpRequest, textStatus, errorThrown) {
|
||||
alert("recommend ajax error!");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function getUserAuthor(name) {
|
||||
$.ajax({
|
||||
type : 'GET',
|
||||
@@ -291,7 +314,7 @@ function history(action) {
|
||||
|
||||
}
|
||||
|
||||
function rightSide() {
|
||||
function relatedSide() {
|
||||
var field = $("#rfield").val();
|
||||
var place = $("#rplace").val();
|
||||
var name = $("#rname").val();
|
||||
|
||||
@@ -15,4 +15,5 @@ public interface UserDAO {
|
||||
public ArrayList<ResearcherModel> getUserAuthor(String name);
|
||||
public ArrayList<PublicationModel> getUserPaper(String name);
|
||||
|
||||
public ArrayList<PublicationModel> recommendPaper(String name);
|
||||
}
|
||||
|
||||
@@ -52,7 +52,8 @@ public class SearchDaoImpl implements SearchDAO {
|
||||
pst = (PreparedStatement) con.prepareStatement(query);
|
||||
rs = pst.executeQuery();
|
||||
while (rs.next()) {
|
||||
hot.add("("+rs.getString("count").toString()+") "+rs.getString("sk").toString());
|
||||
if (!rs.getString("sk").toString().equals("undefined"))
|
||||
hot.add("("+rs.getString("count").toString()+") "+rs.getString("sk").toString());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
@@ -80,7 +81,8 @@ public class SearchDaoImpl implements SearchDAO {
|
||||
pst = (PreparedStatement) con.prepareStatement(query);
|
||||
rs = pst.executeQuery();
|
||||
while (rs.next()) {
|
||||
newly.add(rs.getString("sk").toString());
|
||||
if (!rs.getString("sk").toString().equals("undefined"))
|
||||
newly.add(rs.getString("sk").toString());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
||||
@@ -3,6 +3,8 @@ package dcd.academic.DAO.impl;
|
||||
import java.sql.ResultSet;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import javax.rmi.CORBA.Tie;
|
||||
|
||||
import com.mysql.jdbc.Connection;
|
||||
import com.mysql.jdbc.PreparedStatement;
|
||||
|
||||
@@ -16,6 +18,103 @@ import dcd.academic.solrj.SolrjHelper;
|
||||
|
||||
public class UserDaoImpl implements UserDAO {
|
||||
|
||||
@Override
|
||||
public ArrayList<PublicationModel> recommendPaper(String name) {
|
||||
ArrayList<PublicationModel> list = new ArrayList<PublicationModel>();
|
||||
ArrayList<String> keys = getUserKeys(name);
|
||||
ArrayList<String> titles = getUserTitles(name);
|
||||
for (String key : keys) {
|
||||
String query = "select * from UserPaper where username<>? and sk=?;";
|
||||
Connection con = null;
|
||||
PreparedStatement pst = null;
|
||||
ResultSet rs = null;
|
||||
DBConnectionManage dbmanage = DBConnectionManage.getInstance();
|
||||
|
||||
try {
|
||||
con = dbmanage.getFreeConnection();
|
||||
pst = (PreparedStatement) con.prepareStatement(query);
|
||||
pst.setString(1, name);
|
||||
pst.setString(2, key);
|
||||
rs = pst.executeQuery();
|
||||
while (rs.next()) {
|
||||
if (!titles.contains(rs.getString("title").toString())) {
|
||||
PublicationModel model = new PublicationModel();
|
||||
model.setSk(key);
|
||||
model.setTitle(rs.getString("title").toString());
|
||||
model.setAuthor(rs.getString("username").toString());
|
||||
model.setDate(rs.getString("date").toString());
|
||||
list.add(model);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
dbmanage.closeConnection(con);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
private ArrayList<String> getUserTitles(String name) {
|
||||
ArrayList<String> list = new ArrayList<String>();
|
||||
String query = "select distinct title from UserPaper where username=?;";
|
||||
Connection con = null;
|
||||
PreparedStatement pst = null;
|
||||
ResultSet rs = null;
|
||||
DBConnectionManage dbmanage = DBConnectionManage.getInstance();
|
||||
|
||||
try {
|
||||
con = dbmanage.getFreeConnection();
|
||||
pst = (PreparedStatement) con.prepareStatement(query);
|
||||
pst.setString(1, name);
|
||||
rs = pst.executeQuery();
|
||||
while (rs.next()) {
|
||||
list.add(rs.getString("title").toString());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
dbmanage.closeConnection(con);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
private ArrayList<String> getUserKeys(String name) {
|
||||
ArrayList<String> list = new ArrayList<String>();
|
||||
String query = "SELECT distinct sk FROM userpaper where username =?;";
|
||||
Connection con = null;
|
||||
PreparedStatement pst = null;
|
||||
ResultSet rs = null;
|
||||
DBConnectionManage dbmanage = DBConnectionManage.getInstance();
|
||||
|
||||
try {
|
||||
con = dbmanage.getFreeConnection();
|
||||
pst = (PreparedStatement) con.prepareStatement(query);
|
||||
pst.setString(1, name);
|
||||
rs = pst.executeQuery();
|
||||
while (rs.next()) {
|
||||
list.add(rs.getString("sk").toString());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
dbmanage.closeConnection(con);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public User getUser(String username) {
|
||||
User user = new User();
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
package dcd.academic.action;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.opensymphony.xwork2.ActionSupport;
|
||||
|
||||
import dcd.academic.DAO.DAOfactory;
|
||||
import dcd.academic.model.PublicationModel;
|
||||
|
||||
public class RecommendAction extends ActionSupport {
|
||||
|
||||
private String user;
|
||||
|
||||
public ArrayList<PublicationModel> list = new ArrayList<PublicationModel>();
|
||||
|
||||
@Override
|
||||
public String execute() throws Exception {
|
||||
list = DAOfactory.getUserDAO().recommendPaper(user);
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
public String getUser() {
|
||||
return user;
|
||||
}
|
||||
|
||||
public void setUser(String user) {
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
public ArrayList<PublicationModel> getList() {
|
||||
return list;
|
||||
}
|
||||
|
||||
public void setList(ArrayList<PublicationModel> list) {
|
||||
this.list = list;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -27,7 +27,7 @@ public class SearchHistoryAction extends ActionSupport {
|
||||
SearchDAO dao = DAOfactory.getSearchDAO();
|
||||
Calendar cal = Calendar.getInstance();
|
||||
Date date = cal.getTime();
|
||||
if (sk.length() > 2 && sk != null) {
|
||||
if (!sk.equals("undefined") && sk != null) {
|
||||
dao.saveHistory(type, user, sk.toLowerCase(), date.toLocaleString());
|
||||
}
|
||||
|
||||
|
||||
@@ -73,5 +73,8 @@
|
||||
<action name="searchhistory" class="dcd.academic.action.SearchHistoryAction">
|
||||
<result type="json"></result>
|
||||
</action>
|
||||
<action name="recommend" class="dcd.academic.action.RecommendAction">
|
||||
<result type="json"></result>
|
||||
</action>
|
||||
</package>
|
||||
</struts>
|
||||
Reference in New Issue
Block a user