Skip to content

Commit

Permalink
站点添加站点logo、自定义首页视图;栏目添加自定义列表视图和内容视图;全文检索完善;全文检索添加按栏目id检索;添加留言板全文检索;cm…
Browse files Browse the repository at this point in the history
…s优化,将留言板和搜索与FrontController分离;
  • Loading branch information
think-gem committed Aug 14, 2013
1 parent e5c4fc8 commit b3131b7
Show file tree
Hide file tree
Showing 36 changed files with 1,551 additions and 817 deletions.
1,535 changes: 880 additions & 655 deletions bin/refresh-db/cms/jeesite.erm

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions bin/refresh-db/cms/jeesite_mysql.sql
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ CREATE TABLE cms_category
show_modes char(1) DEFAULT '0' COMMENT '展现方式(0:有子栏目显示栏目列表,无子栏目显示内容列表;1:首栏目内容列表;2:栏目第一条内容)',
allow_comment char(1) COMMENT '是否允许评论',
is_audit char(1) COMMENT '是否需要审核',
custom_list_view varchar(255) COMMENT '自定义列表视图',
custom_content_view varchar(255) COMMENT '自定义内容视图',
create_by bigint COMMENT '创建者',
create_date datetime COMMENT '创建时间',
update_by bigint COMMENT '更新者',
Expand Down Expand Up @@ -140,10 +142,13 @@ CREATE TABLE cms_site
id bigint NOT NULL AUTO_INCREMENT COMMENT '编号',
name varchar(100) NOT NULL COMMENT '站点名称',
title varchar(100) NOT NULL COMMENT '站点标题',
logo varchar(255) COMMENT '站点Logo',
domain varchar(255) COMMENT '站点域名',
description varchar(255) COMMENT '描述,填写有助于搜索引擎优化',
keywords varchar(255) COMMENT '关键字,填写有助于搜索引擎优化',
theme varchar(255) DEFAULT 'default' COMMENT '主题',
copyright text COMMENT '版权信息',
custom_index_view varchar(255) COMMENT '自定义站点首页视图',
create_by bigint COMMENT '创建者',
create_date datetime COMMENT '创建时间',
update_by bigint COMMENT '更新者',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.thinkgem.jeesite.common.filter;

import com.thinkgem.jeesite.common.utils.CacheUtils;

import net.sf.ehcache.CacheManager;
import net.sf.ehcache.constructs.web.filter.SimplePageCachingFilter;

/**
* 页面高速缓存过滤器
* @author ThinkGem
* @version 2013-8-5
*/
public class PageCachingFilter extends SimplePageCachingFilter {

@Override
protected CacheManager getCacheManager() {
return CacheUtils.getCacheManager();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ public void setId(Long id) {
@JoinColumn(name="category_id")
@NotFound(action = NotFoundAction.IGNORE)
@NotNull
@IndexedEmbedded
public Category getCategory() {
return category;
}
Expand Down Expand Up @@ -191,9 +192,9 @@ public void setPosid(String posid) {
this.posid = posid;
}

@OneToOne(mappedBy="article",cascade=CascadeType.ALL,optional=false)
@IndexedEmbedded
@OneToOne(mappedBy="article",cascade=CascadeType.ALL,optional=false)
@Valid
@IndexedEmbedded
public ArticleData getArticleData() {
return articleData;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;
import org.hibernate.annotations.Where;
import org.hibernate.search.annotations.Analyze;
import org.hibernate.search.annotations.Field;
import org.hibernate.search.annotations.Index;
import org.hibernate.search.annotations.Store;
import org.hibernate.validator.constraints.Length;

import com.google.common.collect.Lists;
Expand Down Expand Up @@ -64,6 +68,8 @@ public class Category extends DataEntity {
private String showModes; // 展现方式(0:有子栏目显示栏目列表,无子栏目显示内容列表;1:首栏目内容列表;2:栏目第一条内容)
private String allowComment;// 是否允许评论
private String isAudit; // 是否需要审核
private String customListView; // 自定义列表视图
private String customContentView; // 自定义内容视图

private List<Category> childList = Lists.newArrayList(); // 拥有子分类列表

Expand Down Expand Up @@ -262,6 +268,22 @@ public void setIsAudit(String isAudit) {
this.isAudit = isAudit;
}

public String getCustomListView() {
return customListView;
}

public void setCustomListView(String customListView) {
this.customListView = customListView;
}

public String getCustomContentView() {
return customContentView;
}

public void setCustomContentView(String customContentView) {
this.customContentView = customContentView;
}

@OneToMany(cascade = {CascadeType.PERSIST,CascadeType.MERGE,CascadeType.REMOVE},fetch=FetchType.LAZY,mappedBy="parent")
@Where(clause="del_flag='"+DEL_FLAG_NORMAL+"'")
@OrderBy(value="sort")
Expand Down Expand Up @@ -294,6 +316,13 @@ public static void sortList(List<Category> list, List<Category> sourcelist, Long
}
}
}

@Transient
@Field(index=Index.YES, analyze=Analyze.YES, store=Store.NO)
public String getIds() {
return (this.getParentIds() !=null ? this.getParentIds().replaceAll(",", " ") : "")
+ (this.getId() != null ? this.getId() : "");
}

@Transient
public boolean isRoot(){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,17 @@
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;
import org.hibernate.search.annotations.Analyze;
import org.hibernate.search.annotations.Analyzer;
import org.hibernate.search.annotations.DateBridge;
import org.hibernate.search.annotations.Field;
import org.hibernate.search.annotations.Index;
import org.hibernate.search.annotations.Indexed;
import org.hibernate.search.annotations.Resolution;
import org.hibernate.search.annotations.Store;
import org.hibernate.validator.constraints.Email;
import org.hibernate.validator.constraints.Length;
import org.wltea.analyzer.lucene.IKAnalyzer;

import com.thinkgem.jeesite.common.persistence.BaseEntity;
import com.thinkgem.jeesite.modules.sys.entity.User;
Expand All @@ -38,6 +47,7 @@
@Table(name = "cms_guestbook")
@DynamicInsert @DynamicUpdate
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
@Indexed @Analyzer(impl = IKAnalyzer.class)
public class Guestbook extends BaseEntity {

private static final long serialVersionUID = 1L;
Expand Down Expand Up @@ -82,6 +92,7 @@ public void setId(Long id) {
}

@Length(min=1, max=100)
@Field(index=Index.YES, analyze=Analyze.NO, store=Store.NO)
public String getType() {
return type;
}
Expand All @@ -90,7 +101,8 @@ public void setType(String type) {
this.type = type;
}

@Length(min=1, max=255)
@Length(min=1, max=2000)
@Field(index=Index.YES, analyze=Analyze.YES, store=Store.NO)
public String getContent() {
return content;
}
Expand All @@ -100,6 +112,7 @@ public void setContent(String content) {
}

@Length(min=1, max=100)
@Field(index=Index.YES, analyze=Analyze.YES, store=Store.NO)
public String getName() {
return name;
}
Expand Down Expand Up @@ -145,6 +158,8 @@ public void setIp(String ip) {
}

@NotNull
@Field(index=Index.YES, analyze=Analyze.NO, store=Store.NO)
@DateBridge(resolution = Resolution.DAY)
public Date getCreateDate() {
return createDate;
}
Expand All @@ -164,6 +179,7 @@ public void setReUser(User reUser) {
this.reUser = reUser;
}

@Field(index=Index.YES, analyze=Analyze.YES, store=Store.NO)
public String getReContent() {
return reContent;
}
Expand All @@ -181,6 +197,7 @@ public void setReDate(Date reDate) {
}

@Length(min=1, max=1)
@Field(index=Index.YES, analyze=Analyze.NO, store=Store.YES)
public String getDelFlag() {
return delFlag;
}
Expand Down
18 changes: 18 additions & 0 deletions src/main/java/com/thinkgem/jeesite/modules/cms/entity/Site.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,12 @@ public class Site extends DataEntity {
private Long id; // 编号
private String name; // 站点名称
private String title; // 站点标题
private String logo; // 站点logo
private String description;// 描述,填写有助于搜索引擎优化
private String keywords;// 关键字,填写有助于搜索引擎优化
private String theme; // 主题
private String copyright;// 版权信息
private String customIndexView;// 自定义首页视图文件

public Site() {
super();
Expand Down Expand Up @@ -80,6 +82,14 @@ public void setTitle(String title) {
this.title = title;
}

public String getLogo() {
return logo;
}

public void setLogo(String logo) {
this.logo = logo;
}

@Length(min=0, max=255)
public String getDescription() {
return description;
Expand Down Expand Up @@ -115,6 +125,14 @@ public void setCopyright(String copyright) {
this.copyright = copyright;
}

public String getCustomIndexView() {
return customIndexView;
}

public void setCustomIndexView(String customIndexView) {
this.customIndexView = customIndexView;
}

/**
* 获取默认站点ID
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.apache.lucene.search.BooleanQuery;
import org.apache.lucene.search.Sort;
import org.apache.lucene.search.TermQuery;
import org.apache.lucene.search.TermRangeQuery;
import org.apache.shiro.SecurityUtils;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;
Expand Down Expand Up @@ -170,13 +171,28 @@ public void createIndex(){
/**
* 全文检索
*/
public Page<Article> search(Page<Article> page, String q){
public Page<Article> search(Page<Article> page, String q, String categoryId, String beginDate, String endDate){

// 设置查询条件
BooleanQuery query = articleDao.getFullTextQuery(q, "title","keywords","description","articleData.content");

// 设置过滤条件
BooleanQuery queryFilter = articleDao.getFullTextQuery(new BooleanClause(
new TermQuery(new Term(Article.DEL_FLAG, Article.DEL_FLAG_NORMAL)), Occur.MUST));
List<BooleanClause> bcList = Lists.newArrayList();

bcList.add(new BooleanClause(new TermQuery(new Term(Article.DEL_FLAG, Article.DEL_FLAG_NORMAL)), Occur.MUST));
if (StringUtils.isNotBlank(categoryId)){
bcList.add(new BooleanClause(new TermQuery(new Term("category.ids", categoryId)), Occur.MUST));
}

if (StringUtils.isNotBlank(beginDate) && StringUtils.isNotBlank(endDate)) {
bcList.add(new BooleanClause(new TermRangeQuery("updateDate", beginDate.replaceAll("-", ""),
endDate.replaceAll("-", ""), true, true), Occur.MUST));
}

BooleanQuery queryFilter = articleDao.getFullTextQuery((BooleanClause[])bcList.toArray(new BooleanClause[bcList.size()]));

// System.out.println(queryFilter);

// 设置排序(默认相识度排序)
Sort sort = null;//new Sort(new SortField("updateDate", SortField.DOC, true));
// 全文检索
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public Page<Category> find(Page<Category> page, Category category) {
dc.createAlias("site", "site");
dc.add(Restrictions.eq("site.id", category.getSite().getId()));
}
if (category.getParent()!=null && category.getParent().getId()!=null){
if (category.getParent()!=null && category.getParent().getId()!=null && category.getParent().getId() > 0){
dc.createAlias("parent", "parent");
dc.add(Restrictions.eq("parent.id", category.getParent().getId()));
}
Expand All @@ -130,12 +130,12 @@ public Page<Category> find(Page<Category> page, Category category) {

@Transactional(readOnly = false)
public void save(Category category) {

category.setSite(new Site(Site.getCurrentSiteId()));
category.setParent(this.get(category.getParent().getId()));
String oldParentIds = category.getParentIds(); // 获取修改前的parentIds,用于更新子节点的parentIds
category.setParentIds(category.getParent().getParentIds()+category.getParent().getId()+",");
categoryDao.clear();
categoryDao.save(category);
categoryDao.clear(); categoryDao.save(category);
// 更新子节点 parentIds
List<Category> list = categoryDao.findByParentIdsLike("%,"+category.getId()+",%");
for (Category e : list){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,24 @@
*/
package com.thinkgem.jeesite.modules.cms.service;

import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.apache.lucene.index.Term;
import org.apache.lucene.search.BooleanClause;
import org.apache.lucene.search.BooleanQuery;
import org.apache.lucene.search.Sort;
import org.apache.lucene.search.TermQuery;
import org.apache.lucene.search.TermRangeQuery;
import org.apache.lucene.search.BooleanClause.Occur;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.google.common.collect.Lists;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.service.BaseService;
import com.thinkgem.jeesite.modules.cms.dao.GuestbookDao;
Expand Down Expand Up @@ -57,4 +67,50 @@ public void delete(Long id, Boolean isRe) {
guestbookDao.updateDelFlag(id, isRe!=null&&isRe?Guestbook.DEL_FLAG_AUDIT:Guestbook.DEL_FLAG_DELETE);
}

/**
* 更新索引
*/
public void createIndex(){
guestbookDao.createIndex();
}

/**
* 全文检索
*/
public Page<Guestbook> search(Page<Guestbook> page, String q, String beginDate, String endDate){

// 设置查询条件
BooleanQuery query = guestbookDao.getFullTextQuery(q, "name","content","reContent");

// 设置过滤条件
List<BooleanClause> bcList = Lists.newArrayList();

bcList.add(new BooleanClause(new TermQuery(new Term(Guestbook.DEL_FLAG, Guestbook.DEL_FLAG_NORMAL)), Occur.MUST));

if (StringUtils.isNotBlank(beginDate) && StringUtils.isNotBlank(endDate)) {
bcList.add(new BooleanClause(new TermRangeQuery("createDate", beginDate.replaceAll("-", ""),
endDate.replaceAll("-", ""), true, true), Occur.MUST));
}

bcList.add(new BooleanClause(new TermQuery(new Term("type", "1")), Occur.SHOULD));
bcList.add(new BooleanClause(new TermQuery(new Term("type", "2")), Occur.SHOULD));
bcList.add(new BooleanClause(new TermQuery(new Term("type", "3")), Occur.SHOULD));
bcList.add(new BooleanClause(new TermQuery(new Term("type", "4")), Occur.SHOULD));

BooleanQuery queryFilter = guestbookDao.getFullTextQuery((BooleanClause[])bcList.toArray(new BooleanClause[bcList.size()]));

System.out.println(queryFilter);

// 设置排序(默认相识度排序)
Sort sort = null;//new Sort(new SortField("updateDate", SortField.DOC, true));
// 全文检索
guestbookDao.search(page, query, queryFilter, sort);
// 关键字高亮
guestbookDao.keywordsHighlight(query, page.getList(), 30, "name");
guestbookDao.keywordsHighlight(query, page.getList(), 1300, "content");
guestbookDao.keywordsHighlight(query, page.getList(), 1300, "reContent");

return page;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ public List<Map<String, Object>> article(Map<String, Object> paramMap) {
List<Object> ps = Lists.newArrayList();

ql.append("select new map(max(c.id) as categoryId, max(c.name) as categoryName, max(cp.id) as categoryParentId, max(cp.name) as categoryParentName,");
ql.append(" count(*) as cnt, sum(a.hits) as hits, max(a.updateDate) as updateDate, max(o.id) as officeId, max(o.name) as officeName) ");
ql.append(" count(*) as cnt, (select count(*) from VisitLog vl where vl.category.id=c.id and vl.contentId>0 and vl.createDate between ? and ?) as hits,");
ql.append(" max(a.updateDate) as updateDate, max(o.id) as officeId, max(o.name) as officeName) ");
ql.append(" from Article a join a.category c join c.office o join c.parent cp where c.site.id = ");
ql.append(Site.getCurrentSiteId());

Expand All @@ -53,6 +54,8 @@ public List<Map<String, Object>> article(Map<String, Object> paramMap) {
endDate = DateUtils.addDays(DateUtils.addMonths(beginDate, 1), -1);
paramMap.put("endDate", DateUtils.formatDate(endDate, "yyyy-MM-dd"));
}
ps.add(beginDate);
ps.add(DateUtils.addDays(endDate, 1));

Long categoryId = StringUtils.toLong(paramMap.get("categoryId"));
if (categoryId > 0){
Expand Down
Loading

0 comments on commit b3131b7

Please sign in to comment.