⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 searchresult.java

📁 tbuy1.1.5是在netbeans环境下用JSF技术编写的一个论坛tbuy1.1.5是在netbeans环境下用JSF技术编写的一个论坛
💻 JAVA
字号:
/* * 作者: 胡李青 * qq: 31703299 * Copyright (c) 2007 huliqing * 主页 http://www.tbuy.biz/ * 你可以免费使用该软件,未经许可请勿作用于任何商业目的,如有技术问题请与本人联系! */package biz.tbuy.bbs.bean;import biz.tbuy.bbs.SearchModel;import biz.tbuy.bbs.TopicAction;import biz.tbuy.bbs.TopicModel;import biz.tbuy.common.Utils;import biz.tbuy.common.page.DataPage;import biz.tbuy.common.page.PagedListDataModel;import biz.tbuy.share.StringFilter;import java.util.ArrayList;import java.util.List;import javax.faces.component.UIData;import javax.faces.model.DataModel;/** * @author huliqing * <p><b>qq:</b>31703299 * <p><b>E-mail:</b><a href="mailto:huliqing.cn@gmail.com">huliqing.cn@gmail.com</a> * <p><b>Homepage:</b><a href="http://www.tbuy.biz/">http://www.tbuy.biz/</a> */public class SearchResult extends BaseBean{    private SearchModel _searchModel;    // 查询条件    private DataModel _result; // 查询结果    private UIData _uiResult;  // ...    private int _pageSize = 20;        public SearchResult() {}    public void setSearchModel(SearchModel searchModel) {        _searchModel = searchModel;    }        public SearchModel getSearchModel() {        return _searchModel;    }        public void setResult(DataModel result) {        _result = result;    }        public DataModel getResult() {        if (_result == null) {            _result = new LocalDataModel(_pageSize);        }        return _result;    }        public void setUiResult(UIData uiResult) {        _uiResult = uiResult;    }        public UIData getUiResult() {        return _uiResult;    }        public void setPageSize(int pageSize) {        _pageSize = pageSize;    }        public int getPageSize() {        return _pageSize;    }        /** 获取是否允许BBS文章搜索 */    public boolean isSearchabled() {        return getBBSApplication().isArticleSearch();    }        // ------------------------------------------------------------search    public void search() {        if (!isSearchabled()) return;        _result = new LocalDataModel(_pageSize);        if (_result.getRowCount() == 0) {            Utils.addWarnMessage(getBundle(), "找不到符合要求的结果,请换个关键词试试!");        }    }        /**     * 截取topic中的content字串并并加亮相应关键字     * @param topic 原始主题     * @param sModel 查询条件     * @return topic 截取主体内容后的topic     */    private TopicModel subTopic(TopicModel topic, SearchModel sModel) {        String keyword = sModel.getKeyword();        String title = topic.getTitle();        String content = topic.getContent();        if (sModel.getByTitle())            title = StringFilter.IgnoreCaseSearch(topic.getTitle(), keyword);        if (sModel.getByContent()) {            int[] fin = StringFilter.findString(content, keyword);            if (fin[0] == -1 || fin[1] == -1) { // 主体内容中没有匹配的字符串                content = StringFilter.subString(content, 0, sModel.getLength());                content = StringFilter.clearBR(content);    // 去除换行换段符            } else {                 // 存在匹配字符则截取字段                if (fin[1] <= sModel.getLength()) {                    content = StringFilter.subString(content, 0, sModel.getLength());                } else {                    content = StringFilter.subString(content, fin[0], sModel.getLength());                }                // 去除换行符,并给关键字添加样式                content = StringFilter.clearBR(content);                content = StringFilter.IgnoreCaseSearch(content, keyword);            }        }        topic.setTitle(title);        topic.setContent(content + "...");        return topic;    }        // ------------------------------------------------------------page about    private  DataPage getDataPage(int startRow, int pageSize) {        int total = 0;        List<TopicModel> dataList = new ArrayList<TopicModel>();        total = TopicAction.searchTopicsTotal(_searchModel);        dataList = TopicAction.searchTopics(_searchModel, startRow, pageSize);        // 将搜索到的topics信息的主体内容进行截取        if (dataList != null && !dataList.isEmpty()) {            for (TopicModel topic : dataList) {                subTopic(topic, _searchModel);            }        }        return new DataPage(total, startRow, dataList);    }        private class LocalDataModel extends PagedListDataModel {        public  LocalDataModel(int pageSize) {             super(pageSize);        }        public DataPage fetchPage(int startRow,int pageSize) {             // call enclosing managed bean method to fetch the data              return getDataPage(startRow, pageSize);        }    }    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -