jeecms搜索用的是apache Lucene,要实现此功能得先去学习它。

直接上代码

package com.jeecms.cms.lucene;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date; import org.apache.lucene.index.IndexReader;
import org.apache.lucene.search.FieldCache;
import org.apache.lucene.search.FieldComparator;
import org.apache.lucene.search.FieldComparatorSource; public class LuceneContentComparatorSource extends FieldComparatorSource { private int lmId = 0;
public LuceneContentComparatorSource() {
}
public LuceneContentComparatorSource(int lmId) {
this.lmId = lmId;
}
@Override
public FieldComparator newComparator(String field, int allCounts, int newCount,
boolean reversed) throws IOException {
return new LuceneContentComparatorSource.LuceneContentFieldComparator(allCounts, field);
}
class LuceneContentFieldComparator extends FieldComparator{
private String[] values;
private String[] currentReaderValues;
private final String field;
private String bottom;
SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");
public LuceneContentFieldComparator(int numHits, String field) {
this.values = new String[numHits];
this.field = field;
}
@Override
public int compare(int slot1, int slot2) {
try {
if("releaseDate".equals(field)){
Date val1 = format.parse(this.values[slot1]);
Date val2 = format.parse(this.values[slot2]);
if(null == val1) {
if(null == val2) {
return 0;
}
return -1;
}
if(null == val2) {
return 1;
} if(val1.after(val2)) {
return 1;
}
if(val2.after(val1)) {
return -1;
}
}else if("channelIdArray".equals(field)){
if(this.values[slot1].equals(this.values[slot2])){
return 0;
}else if((lmId + "").equals(this.values[slot1])){
return 1;
}else if((lmId + "").equals(this.values[slot2])){
return -1;
}
}
} catch (Exception e) {
e.printStackTrace();
}
return 0;
}
@Override
public int compareBottom(int doc) throws IOException {
try {
if("releaseDate".equals(field)){
Date val2 = format.parse(this.currentReaderValues[doc]);
Date tempBottom = format.parse(this.bottom);
if (tempBottom == null) {
if (val2 == null) {
return 0;
}
return -1;
}
if (val2 == null) {
return 1;
}
if(val2.after(tempBottom)) {
return 1;
}
if(tempBottom.after(val2)) {
return -1;
}
}else if("channelIdArray".equals(field)){
if(this.bottom.equals(this.currentReaderValues[doc])){
return 0;
}else if((lmId + "").equals(this.bottom)){
return 1;
}else if((lmId + "").equals(this.currentReaderValues[doc])){
return -1;
}
}
} catch(Exception e) {
e.printStackTrace();
}
return 0;
}
@Override
public void copy(int slot, int doc) throws IOException {
this.values[slot] = this.currentReaderValues[doc]; }
@Override
public void setBottom(int bottom) {
this.bottom = this.values[bottom];
}
@Override
public void setNextReader(IndexReader reader, int arg1)
throws IOException {
this.currentReaderValues = FieldCache.DEFAULT.getStrings(reader, this.field);
}
@Override
public Comparable value(int slot) {
return this.values[slot];
} } }

我的需求是需呀根据栏目ID 与日期排序 所以以上代码就如此写的

至此 基本已经完成,之后只需要在 search方法中 传入 sort对象即可

//栏目排序类
SortField sortFieldLm = new SortField("channelIdArray", new LuceneContentComparatorSource(lmId), true);
//日期排序
SortField sortFieldDate = new SortField("releaseDate", new LuceneContentComparatorSource(), true);
Sort sort = new Sort ();
sort.setSort(sortFieldLm,sortFieldDate);
//排序类
TopDocs docs = searcher.search(query,null, pageNo * pageSize,sort);

jeecms搜索结果排序-二次开发的更多相关文章

  1. 原 JEECMS导入IDEA进行二次开发图文教程

    JEECMS导入IDEA进行二次开发图文教程 2017年05月15日 17:03:53 Swain_Ho 阅读数 3257    版权声明:本文为博主原创文章,未经博主允许不得转载. https:// ...

  2. 【Yom框架】漫谈个人框架的设计之二:新的IRepository接口+搜索和排序解耦(+基于Castle实现)

    经过了上篇IRepository和IRepository<T>的讨论[文章地址为:http://www.cnblogs.com/yomho/p/3296759.html] 我选择了IRep ...

  3. jeecms系统使用介绍——通过二次开发实现对word、pdf、txt等上传附件的全文检索

    转载请注明出处:http://blog.csdn.net/dongdong9223/article/details/76912307 本文出自[我是干勾鱼的博客] 之前在文章<基于Java的门户 ...

  4. 关于FlexPaper 2.1.2版本 二次开发 Logo 、打印、搜索、缩略图、添加按钮、js交互、右键菜单、书签等相关问题

    2015-03-02 更新文章,由于需求修改,更改了flexpaper插件,故增加第9.10.11小节,下载代码时请注意. 先废话几句.最近用到文档在线浏览功能,之前用的是print2flash(一个 ...

  5. FlexPaper二次开发问题及搜索高亮显示

    原文:FlexPaper二次开发问题及搜索高亮显示 最近有个需求,做一个IT知识库,类似于文库,说到文库肯定会用到在线浏览文档了,所有在网上翻阅了一下类似豆丁的在线浏览器插件的资料,将其进行了二次开发 ...

  6. 【IOS开发】搜索和排序(好友列表,通讯录的实现,searchbar)

    一.效果图: 二.概述 实现一个好友列表,可以分为男女两个选项,并且实现搜索和排序功能.我的数据是放在plist文件中. 三.代码简述 代码结构如图,首先自定义一个Cell. cell.h #impo ...

  7. Java实现 LeetCode 81 搜索旋转排序数组 II(二)

    81. 搜索旋转排序数组 II 假设按照升序排序的数组在预先未知的某个点上进行了旋转. ( 例如,数组 [0,0,1,2,2,5,6] 可能变为 [2,5,6,0,0,1,2] ). 编写一个函数来判 ...

  8. #研发解决方案介绍#基于ES的搜索+筛选+排序解决方案

    郑昀 基于胡耀华和王超的设计文档 最后更新于2014/12/3 关键词:ElasticSearch.Lucene.solr.搜索.facet.高可用.可伸缩.mongodb.SearchHub.商品中 ...

  9. Android VLC播放器二次开发1——程序结构分析

    最近因为一个新项目需要一个多媒体播放器,所以需要做个视频.音频.图片方面的播放器.也查阅了不少这方面的资料,如果要从头做一个播放器工作量太大了,而且难度也很大.所以最后选择了VLC作为基础,进行二次开 ...

随机推荐

  1. 【高精度】高精度数除以低精度数I

    问题 G: [高精度]高精度数除以低精度数I 时间限制: 1 Sec  内存限制: 512 MB提交: 173  解决: 71[提交] [状态] [讨论版] [命题人:] 题目描述 修罗王聚集了庞大的 ...

  2. 六. 异常处理9.finally块

    当异常被抛出,通常方法的执行将作一个陡峭的非线性的转向.依赖于方法是怎样编码的,异常甚至可以导致方法过早返回.这在一些方法中是一个问题.例如,如果一个方法打开一个文件项并关闭,然后退出,你不希望关闭文 ...

  3. 集合框架(04)HashMap

    集合Map的简单方法:该集合存储键值对,一对一对往里面存,而且要保证健的唯一性 1.添加 put(K key,V value) putAll(Map<? Extends k, ? extends ...

  4. Android中Context详解 ---- 你所不知道的Context(转)

    Android中Context详解 ---- 你所不知道的Context(转)                                               本文出处 :http://b ...

  5. 【转】Ehcache详细解读

    Ehcache 是现在最流行的纯Java开源缓存框架,配置简单.结构清晰.功能强大,最初知道它,是从Hibernate的缓存开始的.网上中文的EhCache材料 以简单介绍和配置方法居多,如果你有这方 ...

  6. 五个常用的Linux监控脚本代码

    bash中 2>&1 & 的解释 1.首先,bash中0,1,2三个数字分别代表STDIN_FILENO.STDOUT_FILENO.STDERR_FILENO,即标准输入(一般 ...

  7. 把e.printStackTrace的堆栈信息打印在log.error()中

    不要这样写: log.error(e);这样只是简单的记录下错误的类型,不能精确出错误出错在哪行 要写成:log.error(e.toString(),e);

  8. HTTP请求和响应2:方法(Method)

    方法表明了client希望server对资源运行的动作.经常使用的方法包含:GET.HEAD.POST.PUT.TRACE.OPTIONS和DELETE,每一个server能够实现这些方法中的部分或者 ...

  9. [Algorithms] Classify Mystery Items with the K-Nearest Neighbors Algorithm in JavaScript

    The k-nearest neighbors algorithm is used for classification of unknown items and involves calculati ...

  10. hdu 5284 wyh2000 and a string problem(没有算法,仅仅考思维,字符数组得开20万,不然太小了)

    代码: #include<cstdio> #include<cstring> using namespace std; char s[200000]; int main() { ...