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

📄 topiciso.java

📁 EasyJForum 是一个基于 Java 技术的免费社区论坛软件系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                    doc.add(new Field("content", tmpStr.replace('.',' '),
                                Field.Store.NO, Field.Index.TOKENIZED));
                    
                    writer.addDocument(doc);
                }
            }

            writer.optimize();
        }
        finally
        {
            if (writer != null)
                writer.close();
            if (dir != null)
                dir.close();
        }

        AppUtils.saveStringToFile(currentIdx, appPath + "WEB-INF/data/ejf.idx");
        long endTime = System.currentTimeMillis();
        logger.info("Time of index topics is:" + (endTime - startTime));
    }

    private String getAllowedBoards(UserInfo userinfo)
    {
        StringBuilder result = new StringBuilder(",");
        GroupVO aGroup = PageUtils.getGroupVO(userinfo);
        boolean isModerator = false;
        if (aGroup.groupID == 'A' || aGroup.groupID == 'M' || aGroup.groupID == 'S')
            isModerator = true;
        
        ArrayList<SectionVO> sections = CacheManager.getInstance().getSections();
        SectionVO aSection = null;
        BoardVO aBoard = null;
        
        for (int i=0; i<sections.size(); i++)
        {
            aSection = sections.get(i);
            if (aSection != null && aSection.boardList != null)
            {
                for (int j=0; j<aSection.boardList.size(); j++)
                {
                    aBoard = aSection.boardList.get(j);
                    if (aBoard.state == 'I' && !isModerator) continue;
                    if (aBoard.allowGroups != null && 
                            aBoard.allowGroups.indexOf(aGroup.groupID) >= 0)
                    {
                        result.append(aBoard.boardID).append(',');
                    }
                }
            }
        }
        return result.toString();
    }
    
    /**
     * 根据Tag关键字查询频道
     * @param aChannel 频道记录
     * @return ChannelVO 列表
     * @throws 无
     * @since 1.0
     */
    public Object[] queryTopics(String[] keys, String queryField, String userID,
                                String boardID, UserInfo userinfo,
                                int pageNo, int pageRows) throws Exception
    {
        Object[] result = new Object[2];
        if (searcher == null)
        {
            try
            {
                loadTopicsIndex();
                logger.info("Topic searcher initialized!");
            }
            catch(Exception ex)
            {
                throw new Exception("正在建立索引, 请稍后再执行查询。");
            }
        }

        QueryParser parser = new QueryParser(queryField, analyzer);
        BooleanQuery query = new BooleanQuery();
        for (int i=0; i<keys.length; i++)
        {
            query.add(parser.parse(keys[i]), BooleanClause.Occur.MUST);
        }
        if (userID != null && userID.length() > 0)
        {
            QueryParser user_parser = new QueryParser("userID", analyzer);
            query.add(user_parser.parse(userID), BooleanClause.Occur.MUST);
//            query.add(new WildcardQuery(new Term("userID", userID)), 
//                          BooleanClause.Occur.MUST);
        }
        if (boardID != null && boardID.length() > 0)
        {
            query.add(new TermQuery(new Term("boardID", boardID)), 
                          BooleanClause.Occur.MUST);
        }
        Hits hits = searcher.search(query);

        int recordCount = hits.length();
        if (recordCount > 0)
        {
            int startIdx = (pageNo-1) * pageRows;
            int endIdx = startIdx + pageRows;
            if (endIdx > recordCount)
                endIdx = recordCount;
                
            Document hitDoc = null;
            StringBuilder inSql = new StringBuilder(" (");
            HashMap<String,String> replyIDMap = new HashMap<String,String>();
            String topicID = null;
            String strReplyID = null;
            
            // Iterate through the results:
            for (int i = startIdx; i < endIdx; i++) 
            {
                hitDoc = hits.doc(i);
                topicID = hitDoc.get("topicID");
                if (inSql.length() > 2)
                    inSql.append(",");
                inSql.append(topicID);
                
                strReplyID = replyIDMap.get(topicID);
                if (strReplyID == null || strReplyID.length() == 0)
                    strReplyID = hitDoc.get("replyID");
                else
                    strReplyID = strReplyID + "," + hitDoc.get("replyID");
                //if (strReplyID == null)
                //    strReplyID = "0";
                replyIDMap.put(topicID, strReplyID);
            }
            inSql.append(")");
            hits = null;
            
            Connection conn = null;
            PreparedStatement pstmtQuery = null;
            ResultSet rs = null;
            try
            {
                String sql = adapter.Topic_Search + inSql.toString()
                           + " order by createTime DESC";
                
                String allowedBoards = this.getAllowedBoards(userinfo);
                
                conn = dbManager.getConnection();
                pstmtQuery = conn.prepareStatement(sql);
                rs = pstmtQuery.executeQuery();
                
                ArrayList<TopicInfo> topicList = new ArrayList<TopicInfo>();
                TopicInfo aTopic = null;
                String[] replyIDs = null;
                
                while(rs.next())
                {
                    topicID = rs.getString("topicID");
                    strReplyID = replyIDMap.get(topicID);
                    replyIDs = strReplyID.split(",");
                    for (int i=0; i<replyIDs.length; i++)
                    {
                        aTopic = new TopicInfo();
                        aTopic.topicID = topicID;
                        aTopic.sectionID = rs.getString("sectionID");
                        aTopic.boardID = rs.getString("boardID");
                        aTopic.visits = rs.getString("visits");
                        aTopic.replies = rs.getString("replies");
                        //aTopic.attaches = rs.getInt("attaches");
                        aTopic.isHidePost = rs.getString("isHidePost").charAt(0);
                        aTopic.state = rs.getString("state").charAt(0);
                        aTopic.createTime = AppUtils.formatSQLTimeStr(rs.getTimestamp("createTime"));
                        aTopic.lastPostUser = replyIDs[i]; // ReplyID

                        if (allowedBoards.indexOf("," + aTopic.boardID + ",") >= 0)
                        {
                            aTopic.title = rs.getString("title");
                            aTopic.userID = rs.getString("userID");
                            aTopic.nickname = rs.getString("nickname");
                            aTopic.reward = rs.getInt("reward");
                            aTopic.attachIcon = rs.getString("attachIcon");
                            aTopic.isDigest = rs.getString("isDigest").charAt(0);
                            aTopic.isSolved = rs.getString("isSolved").charAt(0);
                        }
                        else
                        {
                            aTopic.title = "您无权访问此主题";
                            aTopic.userID = "";
                            aTopic.nickname = "未知";
                            aTopic.reward = 0;
                            aTopic.attachIcon = "";
                            aTopic.isDigest = 'F';
                            aTopic.isSolved = 'F';
                        }
                        topicList.add(aTopic);
                    }
                }
                result[1] = topicList;
            }
            finally
            {
                dbManager.closeResultSet(rs);
                dbManager.closePStatement(pstmtQuery);
                dbManager.closeConnection(conn);
            }
            // Get result page code
            int pageCount = (recordCount - 1) / pageRows + 1;
            if (pageCount <= 1) return result;
            result[0] = 
                PageUtils.getPageHTMLStr(recordCount, pageNo, pageRows, 0);
        }
        return result;
    }

    protected void finalize() throws Throwable
    {
        try
        {
            if (searcher != null)
            {
                searcher.close();
                searcher = null;
            }
            if (dir != null)
            {
                dir.close();
                dir = null;
            }
        }
        finally
        {
            super.finalize();
        }
    }
    
}

⌨️ 快捷键说明

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