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

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

?? postsearchquery.java

?? 解觖java技術中后臺無法上傳數給的情況
?? JAVA
字號:
/*
 * $Header: /cvsroot/mvnforum/mvnforum/src/com/mvnforum/search/post/PostSearchQuery.java,v 1.7 2006/04/14 17:05:27 minhnn Exp $
 * $Author: minhnn $
 * $Revision: 1.7 $
 * $Date: 2006/04/14 17:05:27 $
 *
 * ====================================================================
 *
 * Copyright (C) 2002-2006 by MyVietnam.net
 *
 * 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 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.
 *
 * 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 at MyVietnam net
 *
 * @author: Minh Nguyen  
 * @author: Dejan Krsmanovic dejan_krsmanovic@yahoo.com
 */
package com.mvnforum.search.post;

import java.io.IOException;
import java.sql.Timestamp;
import java.util.*;

import com.mvnforum.MVNForumConfig;
import com.mvnforum.auth.MVNForumPermission;
import com.mvnforum.db.*;
import com.mvnforum.search.CombineFilter;
import com.mvnforum.search.IntegerFilter;
import net.myvietnam.mvncore.exception.DatabaseException;
import net.myvietnam.mvncore.exception.ObjectNotFoundException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.document.Document;
import org.apache.lucene.index.Term;
import org.apache.lucene.queryParser.ParseException;
import org.apache.lucene.queryParser.QueryParser;
import org.apache.lucene.search.*;
import org.apache.lucene.store.Directory;

/**
 * This class is used for specifying query that should be searched for. Query
 * can contain keywords and further it can be filtered by specifying member
 * name of the author, forumID as well as date interval for searching.
 *
 * searchString contains one or more keywords. Each keyword can use wildcards.
 * ? for single character and * for multiple characters.
 * For specifying boolean operators AND and OR operators can be used.....
 *
 * For all available options consult Lucene documentation http://jakarta.apache.org/lucene
 *
 * @author Dejan Krsmanovic dejan_krsmanovic@yahoo.com
 */
public class PostSearchQuery
{
    private static Log log = LogFactory.getLog(PostSearchQuery.class);

    // constant for search by time
    public static final int SEARCH_ANY_DATE = 0;

    public static final int SEARCH_NEWER    = 1;
    public static final int SEARCH_OLDER    = 2;

    // constant for search by the post title/body
    public static final int SEARCH_ONLY_TITLE = 1;
    public static final int SEARCH_ONLY_BODY =  2;

    private int memberID = -1;
    private int forumId = 0;
    private boolean withAttachment = false;// currently doesnt use this variable, use minAttachmentCount

    // search with ignore attachment ( attachmentCount is negative )
    private int minAttachmentCount = -1;// or 0 should also be okie

    private String searchString = null;

    private Timestamp fromDate = null;
    private Timestamp toDate = null;

    private int hitCount = 0;
    private Collection searchResult = null;

    // 1|2 = 3;
    private int scopeInPost = SEARCH_ONLY_TITLE|SEARCH_ONLY_BODY;

    public PostSearchQuery() {
    }

    /**
     * Set name of the author that should be searched for
     * @param memberId
     */
    public void setMemberId(int memberId) {
        this.memberID = memberId;
    }

    /**
     * Id of forum where post belongs. Set to -1 if all forums should be searched
     * @param forumId
     */
    public void setForumId(int forumId) {
        this.forumId = forumId;
    }

    /**
     * Set string that should be searched for.
     * @param searchString
     */
    public void setSearchString(String searchString) {
        this.searchString = searchString;
    }

    public void setScopeInPost(int scopeInPost) {
        this.scopeInPost = scopeInPost;
    }

    public void setFromDate(Timestamp fromDate) {
        this.fromDate = fromDate;
    }

    public void setToDate(Timestamp toDate) {
        this.toDate = toDate;
    }

    /**
     *
     * @param withAttachment boolean
     * @deprecated use setMinAttachmentCount
     */
    public void setWithAttachment(boolean withAttachment) {
        this.withAttachment = withAttachment;
    }

    public void setMinAttachmentCount(int count) {
        this.minAttachmentCount = count;
    }

    // Note that with IndexSearcher, the directory is closed automatically
    protected IndexSearcher getSearcher(Directory directory) throws IOException {
        try {
            IndexSearcher searcher = new IndexSearcher(directory);
            return searcher;
        } catch (IOException ex) {
            // we throw new IOException because the original exception
            // contain sensitive directory information
            log.error("Cannot access the lucene search index for query. Please check if you have configed mvnForumHome properly. You can also go to Admin Zone to rebuild the Lucene index files.", ex);
            //@todo : localize me
            throw new IOException("Cannot access the lucene search index. Please report this error to web site Administrator (check mvnForumHome or rebuild Lucene index).");
        }
    }

    public void searchDocuments(int offset, int rowsToReturn, MVNForumPermission permission)
        throws IOException, DatabaseException, ObjectNotFoundException {

        // Now check if at least one of these input is present: key, member, attachment
        if ((searchString == null || searchString.equals("")) &&
            (memberID == -1) &&
            (minAttachmentCount < 1)) {
            // should throw an Exception here, if not, later call getPostResult() will return null
            return;
        }
        //Build the query
        BooleanQuery query = new BooleanQuery();
        try {
            Query topicBodyQuery = getTopicBodyQuery();
            if (topicBodyQuery != null) {
                query.add(topicBodyQuery, true, false);
                log.debug("topicBodyQuery = " + topicBodyQuery);
            }

            Query withAttachmentQuery = getWithAttachmentQuery();
            if (withAttachment) {
                query.add(withAttachmentQuery, true, false);
                log.debug("withAttachmentQuery = " + withAttachmentQuery);
            }

            Query categoryForumQuery = getCategoryForumQuery(permission);
            if (categoryForumQuery != null) {
                log.debug("categoryForumQuery = " + categoryForumQuery);
                query.add(categoryForumQuery, true, false);
            }

            Query memberQuery = getMemberQuery();
            if (memberQuery != null) {
                log.debug("memberQuery = " + memberQuery);
                query.add(memberQuery, true, false);
            }
        } catch (ParseException pe) {
            log.error("Cannot parse the search query", pe);
        }
        log.debug("booleanQuery = " + query);

        DateFilter dateFilter = null;
        //Add date filter if some of dates provided
        if (fromDate != null && toDate != null) {
            dateFilter = new DateFilter(PostIndexer.FIELD_POST_DATE, fromDate, toDate);
        } else if (fromDate != null) {
            dateFilter = DateFilter.After(PostIndexer.FIELD_POST_DATE, fromDate);
        } else if (toDate != null) {
            dateFilter = DateFilter.Before(PostIndexer.FIELD_POST_DATE, toDate);
        }

        IntegerFilter attachCountFilter = null;

        if ( minAttachmentCount > 0 ) {
            attachCountFilter = IntegerFilter.greaterThan(PostIndexer.FIELD_ATTACHMENT_COUNT, minAttachmentCount);
        }

        Filter filter = null;

        if (dateFilter != null) {
            if (attachCountFilter != null) {
                filter = new CombineFilter(dateFilter, attachCountFilter);
            } else {
                filter = dateFilter;
            }
        } else {
            filter = attachCountFilter;
        }

        //Now search the documents
        Directory directory = null;
        IndexSearcher searcher = null;
        try {
            directory = MVNForumConfig.getSearchPostIndexDir();
            searcher = getSearcher(directory);

            //If filter set then use it
            Hits postHits = null;
            if (filter != null) {
                postHits = searcher.search(query, filter);
            } else {
                postHits = searcher.search(query);
            }

            hitCount = postHits.length();
            searchResult = getPosts(postHits, offset, rowsToReturn);
        } catch (IOException ex) {
            throw ex;
        } finally {
            // NOTE that we don't close directory because searcher.close() already do that
            if (searcher != null) {
                try {
                    searcher.close();
                } catch (IOException ex) {
                    log.debug("Error closing Lucene IndexSearcher", ex);
                }
            }
        }
    }

    public int getHitCount() {
        return hitCount;
    }

    public Collection getPostResult() {
        if (searchResult == null) {
            //create an empty list, in case result is null
            searchResult = new ArrayList();
        }
        return searchResult;
    }

    private Collection getPosts(Hits postHits, int offset, int rowsToReturn)
        throws IOException, ObjectNotFoundException, DatabaseException {

        if (offset < 0) throw new IllegalArgumentException("The offset < 0 is not allowed.");
        if (rowsToReturn <= 0) throw new IllegalArgumentException("The rowsToReturn <= 0 is not allowed.");

        //int hitCount = getHitCount();
        ArrayList retValue = new ArrayList(hitCount);

        for (int i = offset; (i < offset + rowsToReturn) && (i < hitCount); i++) {
            Document postDocument = postHits.doc(i);
            int postID = Integer.parseInt(postDocument.get(PostIndexer.FIELD_POST_ID));
            PostBean postBean = DAOFactory.getPostDAO().getPost(postID);
            retValue.add(postBean);
        }
        return retValue;
    }

    private Query getTopicBodyQuery() throws ParseException {
        if (searchString == null || searchString.equals("")) {
            return null;
        }
        Analyzer analyzer = PostIndexer.getAnalyzer();
        BooleanQuery topicBodyQuery = new BooleanQuery();

        //add topic query
        Query topicQuery = QueryParser.parse(searchString,
                                             PostIndexer.FIELD_POST_TOPIC,
                                             analyzer);
        topicBodyQuery.add(topicQuery, false, false);

        //add body query
        Query bodyQuery = QueryParser.parse(searchString,
                                            PostIndexer.FIELD_POST_BODY,
                                            analyzer);
        if ( scopeInPost == SEARCH_ONLY_TITLE) {
            return topicQuery;
        } else if ( scopeInPost == SEARCH_ONLY_BODY){
            return bodyQuery;
        }
        topicBodyQuery.add(bodyQuery, false, false);

        return topicBodyQuery;
    }

    private Query getMemberQuery() {
        Query memberQuery = null;
        if (memberID > 0) {
            Term memberTerm = new Term(PostIndexer.FIELD_MEMBER_ID, String.valueOf(memberID));
            memberQuery = new TermQuery(memberTerm);
        }
        return memberQuery;
    }

    private Query getWithAttachmentQuery() {
        Query withAttachmentQuery = null;
        if (withAttachment) {
            Term withAttachmentTerm = new Term(PostIndexer.FIELD_WITH_ATTACHMENT, String.valueOf(withAttachment));
            withAttachmentQuery = new TermQuery(withAttachmentTerm);
        }
        return withAttachmentQuery;
    }

    private Query getCategoryForumQuery(MVNForumPermission permission) throws DatabaseException {
        BooleanQuery categoryForumQuery = new BooleanQuery();
        if (forumId == 0) {
            // search all forum
            Collection forumBeans = ForumCache.getInstance().getBeans();
            for (Iterator iter = forumBeans.iterator(); iter.hasNext(); ) {
                ForumBean forumBean = (ForumBean)iter.next();
                int currentForumID = forumBean.getForumID();
                if ((forumBean.getForumStatus() != ForumBean.FORUM_STATUS_DISABLED) &&
                    permission.canReadPost(currentForumID)) {

                    Term forumTerm = new Term(PostIndexer.FIELD_FORUM_ID, String.valueOf(currentForumID));
                    Query forumQuery = new TermQuery(forumTerm);
                    categoryForumQuery.add(forumQuery, false, false);
                }
            }
        } else if (forumId > 0) {
            // search in forum
            Term forumTerm = new Term(PostIndexer.FIELD_FORUM_ID, String.valueOf(forumId));
            Query forumQuery = new TermQuery(forumTerm);
            categoryForumQuery.add(forumQuery, true, false);
        } else if (forumId < 0) {
            // search in category
            int categoryID = -forumId;//category is the negative value of forumID in this case
            Collection forumBeans = ForumCache.getInstance().getBeans();
            for (Iterator iter = forumBeans.iterator(); iter.hasNext(); ) {
                ForumBean forumBean = (ForumBean)iter.next();
                if (forumBean.getCategoryID() == categoryID) {
                    int currentForumID = forumBean.getForumID();
                    if ((forumBean.getForumStatus() != ForumBean.FORUM_STATUS_DISABLED) &&
                        permission.canReadPost(currentForumID)) {

                        Term forumTerm = new Term(PostIndexer.FIELD_FORUM_ID, String.valueOf(currentForumID));
                        Query forumQuery = new TermQuery(forumTerm);
                        categoryForumQuery.add(forumQuery, false, false);
                    }
                }
            }
        }
        return categoryForumQuery;
    }
}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
国产麻豆精品久久一二三| 国产成人av电影| 欧美乱熟臀69xxxxxx| 亚洲女人****多毛耸耸8| 在线视频综合导航| 亚洲精品精品亚洲| 欧美日韩高清影院| 老司机一区二区| 精品久久久影院| 成人免费视频国产在线观看| 中文字幕亚洲电影| 欧美中文字幕一区| 精品一区二区三区免费视频| 在线观看国产日韩| 精彩视频一区二区三区| 中文字幕在线不卡视频| 在线观看视频一区二区欧美日韩| 日韩影院在线观看| 亚洲国产精品精华液ab| 欧美三级一区二区| 成人精品视频一区二区三区| 一区二区三区四区高清精品免费观看 | 成人不卡免费av| 日韩一区精品视频| 综合精品久久久| 国产人成亚洲第一网站在线播放| 欧美在线看片a免费观看| 麻豆成人91精品二区三区| 亚洲欧美综合在线精品| 欧美白人最猛性xxxxx69交| 99视频一区二区三区| 亚洲电影一级片| 亚洲乱码国产乱码精品精的特点| 久久久av毛片精品| 91精品中文字幕一区二区三区| 色网站国产精品| 96av麻豆蜜桃一区二区| 成人黄色av电影| 国产成人精品三级| 成人三级伦理片| 免费人成在线不卡| 午夜久久久影院| 美女视频网站久久| 久久精品二区亚洲w码| 亚洲h在线观看| 午夜视频久久久久久| 亚洲精品ww久久久久久p站| 亚洲蜜桃精久久久久久久| 欧美精品一区二区蜜臀亚洲| 久久蜜桃香蕉精品一区二区三区| 精品美女在线播放| 国产精品午夜免费| 亚洲综合一区二区精品导航| 亚洲精品久久7777| 美日韩黄色大片| 国产成人小视频| 欧美在线视频全部完| 91精品在线观看入口| 精品国产髙清在线看国产毛片| 在线日韩一区二区| 日韩欧美一级二级| 国产精品护士白丝一区av| 一级做a爱片久久| 国内精品国产成人| 国产成人av福利| aaa欧美日韩| 精品欧美一区二区久久| 国产精品全国免费观看高清| 香蕉成人啪国产精品视频综合网| 久久成人羞羞网站| 欧美中文字幕一区二区三区| 亚洲国产激情av| 毛片不卡一区二区| 欧洲激情一区二区| 中文字幕一区二区三区乱码在线| 日韩av电影免费观看高清完整版| va亚洲va日韩不卡在线观看| 欧美变态口味重另类| 蜜臀精品一区二区三区在线观看 | 欧美一区二区三区视频免费播放 | 婷婷成人激情在线网| 国产成人啪午夜精品网站男同| 91.com视频| 免费成人在线视频观看| 欧美mv日韩mv| 成人av免费观看| 综合网在线视频| 91精品国产综合久久精品性色| 亚洲一区二区三区在线播放| 不卡一区在线观看| 亚洲成年人网站在线观看| 日韩一级片在线观看| 国产·精品毛片| 一区二区三区中文在线观看| 欧美精品色综合| 国产一区二区三区黄视频| 久久久久久久精| 91麻豆国产福利精品| 亚洲国产美女搞黄色| 欧美国产精品久久| 国产欧美精品一区二区三区四区 | 国产精品国产自产拍高清av| 欧美精选一区二区| 欧美色成人综合| 色婷婷av一区| 成人91在线观看| 99视频一区二区| 高清不卡一二三区| 高清日韩电视剧大全免费| 麻豆国产精品官网| 精品一区精品二区高清| 久久99国产精品久久99果冻传媒 | 激情五月婷婷综合| 免费成人你懂的| 久久成人麻豆午夜电影| 国产成人综合亚洲网站| 成人性视频免费网站| 97久久精品人人澡人人爽| 97久久精品人人爽人人爽蜜臀| 99v久久综合狠狠综合久久| 99久久国产综合精品色伊| 91丨九色丨蝌蚪富婆spa| 色诱亚洲精品久久久久久| 色综合久久久久| 精品日韩在线一区| 亚洲国产精品精华液2区45| 亚洲私人影院在线观看| 天天免费综合色| 国产精品亚洲第一区在线暖暖韩国 | 欧美亚洲国产bt| 欧美伊人久久久久久久久影院| 欧美一级二级三级蜜桃| 国产清纯在线一区二区www| 国产精品无遮挡| 毛片不卡一区二区| 一本大道久久a久久精品综合| 日韩欧美色电影| 中文字幕中文在线不卡住| 日本中文字幕一区二区有限公司| 国产乱对白刺激视频不卡| 欧美网站一区二区| 3d动漫精品啪啪1区2区免费| 国产精品传媒视频| 国产激情精品久久久第一区二区| 欧美日韩一区在线| 一区二区在线观看视频| 国产伦精一区二区三区| 欧美色网一区二区| 一区二区三区色| 99精品欧美一区二区三区小说| 日韩亚洲欧美在线观看| 日韩精品亚洲专区| 欧美色精品在线视频| 亚洲一二三四久久| 欧美在线观看你懂的| 夜夜亚洲天天久久| 91免费版在线| 亚洲一区二区三区四区中文字幕 | 欧美色倩网站大全免费| 亚洲午夜免费视频| 欧美日韩午夜精品| 经典三级一区二区| 国产欧美精品国产国产专区 | 91丨九色丨黑人外教| 一区二区三区资源| 欧美另类久久久品| 国产精品综合视频| 亚洲欧美另类图片小说| 6080国产精品一区二区| 国产一区视频导航| 亚洲精品成人悠悠色影视| 欧美一区二区三区在线看| 成人一二三区视频| 亚洲国产成人av网| 国产精品女同互慰在线看| 在线观看av一区二区| 国产一区高清在线| 亚洲国产欧美在线| 国产精品久久久久婷婷| 日韩欧美视频在线| 色婷婷av一区| caoporm超碰国产精品| 极品尤物av久久免费看| 亚洲最大成人网4388xx| 日本一区二区三区四区在线视频| 欧美绝品在线观看成人午夜影视| 国产成人免费网站| 久久99蜜桃精品| 美女精品一区二区| 亚洲成av人片一区二区| 亚洲欧美日韩在线不卡| 国产精品福利在线播放| 欧美国产精品劲爆| 91在线视频在线| 99re这里只有精品首页| 成人午夜又粗又硬又大| 国产一区在线观看视频| 成人综合婷婷国产精品久久免费| 国产黄色精品网站| 成人免费视频视频|