亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? postindexer.java

?? java servlet著名論壇源代碼
?? JAVA
字號:
/*
 * $Header: /cvsroot/mvnforum/mvnforum/src/com/mvnforum/search/PostIndexer.java,v 1.3 2004/07/02 19:21:42 minhnn Exp $
 * $Author: minhnn $
 * $Revision: 1.3 $
 * $Date: 2004/07/02 19:21:42 $
 *
 * ====================================================================
 *
 * Copyright (C) 2002-2004 by MyVietnam.net
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or any later version.
 *
 * All copyright notices regarding mvnForum MUST remain intact
 * in the scripts and in the outputted HTML.
 * The "powered by" text/logo with a link back to
 * http://www.mvnForum.com and http://www.MyVietnam.net in the
 * footer of the pages MUST remain visible when the pages
 * are viewed on the internet or intranet.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 * Support can be obtained from support forums at:
 * http://www.mvnForum.com/mvnforum/index
 *
 * Correspondence and Marketing Questions can be sent to:
 * info@MyVietnam.net
 *
 * @author: Minh Nguyen  minhnn@MyVietnam.net
 * @author: Dejan Krsmanovic dejan_krsmanovic@yahoo.com
 */
package com.mvnforum.search;

import java.io.IOException;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.document.*;
import org.apache.lucene.index.*;
import com.mvnforum.MVNForumConfig;
import com.mvnforum.db.PostBean;
import net.myvietnam.mvncore.exception.DatabaseException;
import net.myvietnam.mvncore.exception.SearchException;
import net.myvietnam.mvncore.util.DateUtil;
import net.myvietnam.mvncore.util.TimerUtil;

public class PostIndexer
{
    private static Log log = LogFactory.getLog(PostIndexer.class);

    //Field names (used for indexing)
    public static final String FIELD_POST_ID    = "postID";
    public static final String FIELD_THREAD_ID  = "threadID";
    public static final String FIELD_FORUM_ID   = "forumID";
    public static final String FIELD_MEMBER_ID  = "memberID";
    public static final String FIELD_POST_TOPIC = "postTopic";
    public static final String FIELD_POST_BODY  = "postBody";
    public static final String FIELD_POST_DATE  = "postDate";

    public static final String PROPERTY_SEARCH_PATH      = "search.path";
    public static final String PROPERTY_SEARCH_ANALYZER  = "search.analyzer.class";
    public static final String PROPERTY_SEARCH_AUTOINDEX = "search.autoindex";

    //Timer is used for scheduling jobs
    private static Analyzer analyzer;
    private static String searchIndexDir;

    private static long lastOptimizeTime = 0;

    static {
        searchIndexDir = MVNForumConfig.getSearchIndexDir();
        initializeAnalyzer();
    }

    public static void scheduleAddPostTask(PostBean postBean) {
        AddUpdatePostIndexTask task = new AddUpdatePostIndexTask(postBean, AddUpdatePostIndexTask.OPERATION_ADD);
        TimerUtil.getInstance().schedule(task, 0);
    }

    public static void scheduleUpdatePostTask(PostBean postBean) {
        AddUpdatePostIndexTask task = new AddUpdatePostIndexTask(postBean, AddUpdatePostIndexTask.OPERATION_UPDATE);
        TimerUtil.getInstance().schedule(task, 0);
    }

    public static void scheduleDeletePostTask(int objectID, int objectType) {
        DeletePostIndexTask task = new DeletePostIndexTask(objectID, objectType);
        TimerUtil.getInstance().schedule(task, 0);
    }

    public static void scheduleUpdateThreadTask(int threadID) {
        UpdateThreadTask task = new UpdateThreadTask(threadID);
        TimerUtil.getInstance().schedule(task, 0);
    }

    public static void scheduleRebuildIndexTask() throws DatabaseException {
        int maxPostID = 0;
        RebuildIndexTask task = new RebuildIndexTask(maxPostID);
        TimerUtil.getInstance().schedule(task, 0);
    }

    static Analyzer getAnalyzer() {
        return analyzer;
    }

    /**
     * This class will load analyzer when starting. If specified analyzer class
     * cannot be loaded then default analyzer will be used.
     */
    private static void initializeAnalyzer() {
        String analyzerClassName = "";
        //TODO Load property
        //PropertyManager.getProperty(PROPERTY_SEARCH_ANALYZER);
        if ( (analyzerClassName != null) || (analyzerClassName.equals("")) ) {
            //create standard analyzer
            //String[] stopWords = this.loadStopWords();
            analyzer = new StandardAnalyzer();
            log.debug("Using StandardAnalyzer for indexing");
        } else {
            //try to create specified analyzer
            try {
                analyzer = (Analyzer) Class.forName(analyzerClassName).newInstance();
            } catch (Exception e) {
                log.warn("Cannot load " + analyzerClassName + ". Loading StandardAnalyzer");
                analyzer = new StandardAnalyzer();
            }
        }
    }

    /**
     * This method is used for getting new IndexWriter. It can create new index
     * or add post to existing index. Creating new index will delete previous so it
     * should be used for rebuilding index.
     * @param create - true if new index should be created.
     *               - false for adding posts to existing index
     * @return IndexWriter object that is used for adding posts to index
     */
    static IndexWriter getIndexWriter(boolean create) throws SearchException {
        IndexWriter writer = null;

        //If create = false, we will create IndexWriter with false argument
        if (create == false) {
            try {
                writer = new IndexWriter(searchIndexDir, analyzer, false);
                writer.setUseCompoundFile(true);
                return writer;
            } catch (IOException e) {
                log.warn("Cannot open existed index. New index will be created.", e);
                //Ignore Exception. We will try to create index with true parameter
            }
        }
        // We are here in two cases: We wanted to create new index or because
        // index doesn't existed
        try {
            //This will create new index and delete existing
            writer = new IndexWriter(searchIndexDir, analyzer, true);
            writer.setUseCompoundFile(true);
            return writer;
        } catch (IOException e) {
            throw new SearchException("Error while creating index writer");
        }
    }

    /**
     * This method is used for adding single post to index
     * Note: this method doesnt close the writer
     * @param post A post that should be indexed
     * @param writer IndexWriter that is used for storing
     * @throws SearchException
     */
    static void doIndexPost(PostBean post, IndexWriter writer) throws SearchException {

        if (post == null) return;
        //Post must include topic and body. If not then we have nothing to index.
        if ( (post.getPostTopic() == null || post.getPostBody().equals("")) ||
            (post.getPostBody() == null || post.getPostBody().equals(""))) {
            return;
        }

        //Each post will be represented as a document
        Document postDocument = new Document();
        //Document has following fields that could be queried on
        postDocument.add(Field.Keyword(FIELD_POST_ID, Integer.toString(post.getPostID())));
        postDocument.add(Field.Keyword(FIELD_THREAD_ID, Integer.toString(post.getThreadID())));
        postDocument.add(Field.Keyword(FIELD_FORUM_ID, Integer.toString(post.getForumID())));
        postDocument.add(Field.Keyword(FIELD_MEMBER_ID, Integer.toString(post.getMemberID())));
        //document body and title is not stored since we can retrieve them from database
        postDocument.add(Field.UnStored(FIELD_POST_TOPIC, post.getPostTopic()));
        postDocument.add(Field.UnStored(FIELD_POST_BODY, post.getPostBody()));
        //add date field
        postDocument.add(Field.Keyword(FIELD_POST_DATE, DateField.dateToString(post.getPostCreationDate())));

        //now we have created document with fields so we can store it
        try {
            writer.addDocument(postDocument);
        } catch (IOException e) {
            log.error("PostIndexer.doIndexPost failed", e);
            throw new SearchException("Error writing new post to index");
        }
    }

    /**
     * Add single post to index
     * @param post
     * @throws SearchException
     */
    static void addPostToIndex(PostBean post) throws SearchException, IOException {
        IndexWriter writer = null;
        try {
            writer = getIndexWriter(false);
            if (writer == null) {
                log.warn("Cannot get the IndexWriter");
                return;
            }
            doIndexPost(post, writer);

            // now check if we should optimize index (each hour)
            long now = System.currentTimeMillis();
            long timeFromLastOptimize = now - lastOptimizeTime;
            if (timeFromLastOptimize > DateUtil.HOUR) {
                log.debug("writer.optimize() called in addPostToIndex");
                writer.optimize();
                lastOptimizeTime = now;
            }
        } catch (SearchException ex) {
            throw ex;
        } finally {
            try {
                if (writer != null) {
                    writer.close();
                }
            } catch (IOException e) {
            }
        }
    }

    /**
     * This method is used for deleting post from index.
     * @param postID id of the post that should be deleted
     * @throws SearchException
     */
    static void deletePostFromIndex(int postID) throws SearchException {
        IndexReader reader = null;
        try {
            reader = IndexReader.open(searchIndexDir);
            if (reader == null) {
                log.warn("Cannot get the IndexReader");
                return;
            }

            Term term = new Term(FIELD_POST_ID, String.valueOf(postID));
            int deletedCount = reader.delete(term);
            log.debug("deletePostFromIndex: deleted posts = " + deletedCount);
        } catch (IOException e) {
            throw new SearchException("Error trying to delete post with postID = " + postID);
        } finally {
            try {
                if (reader != null) {
                    reader.close();
                }
            } catch (IOException e) {
            }
        }
    }

    /**
     * This method is used for deleting all posts in a thread from index.
     * @param threadID id of the thread that should be deleted
     * @throws SearchException
     */
    static void deleteThreadFromIndex(int threadID) throws SearchException {
        IndexReader reader = null;
        try {
            reader = IndexReader.open(searchIndexDir);
            if (reader == null) {
                log.warn("Cannot get the IndexReader");
                return;
            }

            Term term = new Term(FIELD_THREAD_ID, String.valueOf(threadID));
            int deletedCount = reader.delete(term);
            log.debug("deleteThreadFromIndex: deleted posts = " + deletedCount);
        } catch (IOException e) {
            throw new SearchException("Error trying to delete posts in index with threadID = " + threadID);
        } finally {
            try {
                if (reader != null) {
                    reader.close();
                }
            } catch (IOException e) {
            }
        }
    }

    /**
     * This method is used for deleting all posts in a forum from index.
     * @param forumID id of the forum that should be deleted
     * @throws SearchException
     */
    static void deleteForumFromIndex(int forumID) throws SearchException {
        IndexReader reader = null;
        try {
            reader = IndexReader.open(searchIndexDir);
            if (reader == null) {
                log.warn("Cannot get the IndexReader");
                return;
            }

            Term term = new Term(FIELD_FORUM_ID, String.valueOf(forumID));
            int deletedCount = reader.delete(term);
            log.debug("deleteForumFromIndex: deleted posts = " + deletedCount);
        } catch (IOException e) {
            throw new SearchException("Error trying to delete posts in index with forumID = " + forumID);
        } finally {
            try {
                if (reader != null) {
                    reader.close();
                }
            } catch (IOException e) {
            }
        }
    }

}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
国产精品1区二区.| 粉嫩aⅴ一区二区三区四区五区| 欧美精品黑人性xxxx| 裸体一区二区三区| 综合久久综合久久| 日韩一区二区电影| 色天使色偷偷av一区二区| 加勒比av一区二区| 午夜精品免费在线| ㊣最新国产の精品bt伙计久久| 91精品国产综合久久福利| av网站免费线看精品| 精东粉嫩av免费一区二区三区| 亚洲男人天堂一区| 亚洲国产精品黑人久久久| 日韩免费视频一区二区| 欧美午夜影院一区| 91同城在线观看| 国产精品影视在线| 麻豆精品在线观看| 亚洲伊人伊色伊影伊综合网| 国产精品污网站| 欧美xfplay| 欧美色图在线观看| 色婷婷综合视频在线观看| 丁香六月综合激情| 精品系列免费在线观看| 奇米影视一区二区三区小说| 有坂深雪av一区二区精品| 国产精品美女久久久久久久久久久| 日韩视频中午一区| 琪琪久久久久日韩精品| 视频在线观看国产精品| 亚洲国产另类精品专区| 亚洲小说春色综合另类电影| 亚洲乱码国产乱码精品精小说| 国产精品视频一二三区| 中文子幕无线码一区tr| 久久女同精品一区二区| 精品国产一区二区在线观看| 日韩精品在线一区二区| 欧美大白屁股肥臀xxxxxx| 日韩视频免费观看高清在线视频| 欧美久久久久中文字幕| 欧美日韩成人在线| 欧美精品久久久久久久久老牛影院| 日本国产一区二区| 欧美色国产精品| 欧美日韩高清影院| 日韩精品在线网站| 国产女同互慰高潮91漫画| 欧美激情艳妇裸体舞| 亚洲欧洲在线观看av| 日韩码欧中文字| 一区二区三区视频在线看| 亚洲主播在线观看| 午夜精品福利久久久| 日韩一区欧美二区| 狠狠色综合播放一区二区| 国产精品乡下勾搭老头1| 成人福利视频网站| 日本高清不卡aⅴ免费网站| 欧美性一级生活| 欧美一级久久久久久久大片| 精品盗摄一区二区三区| 国产精品私房写真福利视频| 国产精品理伦片| 亚洲一二三区不卡| 精品中文字幕一区二区小辣椒| 成人18视频日本| 日本视频在线一区| 国产超碰在线一区| 欧日韩精品视频| 日韩欧美一卡二卡| 国产精品无码永久免费888| 亚洲最色的网站| 久久成人免费日本黄色| av一二三不卡影片| 欧美精品在欧美一区二区少妇| 精品少妇一区二区三区日产乱码| 日本一区二区三区高清不卡| 亚洲黄色免费电影| 国产乱码精品一区二区三区五月婷 | 毛片av一区二区三区| 国产成人午夜精品影院观看视频 | 成人福利视频网站| 欧美老女人第四色| 中文文精品字幕一区二区| 亚洲成人免费电影| 国产精品996| 69p69国产精品| 一区在线观看视频| 久久av资源网| 欧美中文字幕一区二区三区| 久久久久国产精品人| 亚洲男人的天堂在线观看| 奇米在线7777在线精品| 色婷婷av一区二区三区gif | 日韩一级片在线播放| 国产精品不卡一区二区三区| 日本午夜一本久久久综合| 色一情一伦一子一伦一区| 久久久www成人免费毛片麻豆| 免费成人美女在线观看.| 五月婷婷综合在线| 成人性色生活片| 欧美日韩一级片网站| 国产精品视频在线看| 美女尤物国产一区| 欧美性一二三区| 欧美极品另类videosde| 蜜臀av国产精品久久久久| 欧美午夜精品一区二区三区| 亚洲国产成人私人影院tom| 美腿丝袜亚洲色图| 337p亚洲精品色噜噜噜| 一区二区三区中文在线| 国产不卡视频在线播放| 精品国产欧美一区二区| 视频一区在线播放| 欧美视频中文字幕| 亚洲欧美色图小说| 99精品视频一区| 国产日韩欧美一区二区三区乱码| 蜜臀a∨国产成人精品| 91麻豆精品国产91久久久久久久久| 亚洲欧美一区二区在线观看| 国产成人av自拍| 国产色一区二区| 国产一区二区三区国产| 欧美一级高清片在线观看| 亚洲成av人片| 欧美日韩高清一区二区三区| 亚洲一区二区三区四区中文字幕| 99久久久久免费精品国产| 中文字幕av一区二区三区高 | 亚洲欧美一区二区久久| 91尤物视频在线观看| 亚洲欧洲精品一区二区三区| 成人美女视频在线观看18| 国产视频一区二区在线观看| 东方aⅴ免费观看久久av| 国产蜜臀97一区二区三区| 丁香啪啪综合成人亚洲小说| 美女看a上一区| 精品夜夜嗨av一区二区三区| 精品国产第一区二区三区观看体验| 男女男精品视频| 精品剧情在线观看| 韩国精品主播一区二区在线观看 | 国产尤物一区二区在线| 欧美成人bangbros| 国产成人午夜99999| 国产精品美女久久久久久久| 91一区二区在线| 亚洲一区二区3| 欧美肥妇free| 极品少妇xxxx精品少妇| 国产欧美精品一区aⅴ影院| 99re66热这里只有精品3直播| 一区二区三区日韩欧美精品| 欧美喷潮久久久xxxxx| 麻豆高清免费国产一区| 欧美极品美女视频| 欧美性受xxxx黑人xyx| 青青草原综合久久大伊人精品优势| 欧美成人国产一区二区| 国产成人鲁色资源国产91色综| 国产精品久久久久久福利一牛影视| 91视频免费观看| 日韩高清在线不卡| 亚洲国产精品传媒在线观看| 色婷婷综合视频在线观看| 麻豆精品视频在线观看免费| 国产亚洲女人久久久久毛片| 99久久精品免费看国产免费软件| 亚洲一卡二卡三卡四卡五卡| 精品精品国产高清a毛片牛牛| www.成人网.com| 日韩av一区二区三区四区| 国产精品素人一区二区| 欧美精品v国产精品v日韩精品| 国产一区二区三区蝌蚪| 亚洲国产wwwccc36天堂| 日韩精品一区二区三区蜜臀| 99久久久久免费精品国产| 麻豆精品国产传媒mv男同| 自拍偷拍亚洲欧美日韩| 日韩一区二区三区观看| 欧美视频中文字幕| 亚洲一区二区视频在线观看| 精品国产伦一区二区三区观看体验| av激情综合网| 免费人成黄页网站在线一区二区| 国产三级一区二区| 欧美亚洲综合在线| 国产aⅴ精品一区二区三区色成熟| 午夜激情久久久| 成人免费在线视频| 久久亚洲春色中文字幕久久久|