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

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

?? searchmodel.java

?? 一個論壇程序的簡單實現
?? JAVA
字號:
/*
 * Copyright (c) 2003, 2004 Rafael Steil
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, 
 * with or without modification, are permitted provided 
 * that the following conditions are met:
 * 
 * 1) Redistributions of source code must retain the above 
 * copyright notice, this list of conditions and the 
 * following  disclaimer.
 * 2)  Redistributions in binary form must reproduce the 
 * above copyright notice, this list of conditions and 
 * the following disclaimer in the documentation and/or 
 * other materials provided with the distribution.
 * 3) Neither the name of "Rafael Steil" nor 
 * the names of its contributors may be used to endorse 
 * or promote products derived from this software without 
 * specific prior written permission.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT 
 * HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 
 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR 
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 
 * THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES 
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 
 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 
 * IN CONTRACT, STRICT LIABILITY, OR TORT 
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
 * 
 * This file creation date: 25/02/2004 - 19:32:42
 * The JForum Project
 * http://www.jforum.net
 */
package net.jforum.drivers.generic;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;

import net.jforum.JForum;
import net.jforum.SessionFacade;
import net.jforum.entities.Post;
import net.jforum.model.SearchData;
import net.jforum.util.preferences.SystemGlobals;

/**
 * @author Rafael Steil
 * @version $Id: SearchModel.java,v 1.12 2004/11/05 03:29:46 rafaelsteil Exp $
 */
public class SearchModel extends AutoKeys implements net.jforum.model.SearchModel	
{
	/** 
	 * @see net.jforum.model.SearchModel#search(net.jforum.model.SearchData)
	 */
	public List search(SearchData sd) throws Exception 
	{
		List l = new ArrayList();
		List topics = new ArrayList();
		
		// Check for the search cache
		if (!sd.getSearchStarted()) {
			if (sd.getTime() == null) {
				this.topicsByKeyword(sd);
			}
			else {
				this.topicsByTime(sd);
			}
		}
		
		StringBuffer criterias = new StringBuffer(256);
		if (sd.getForumId() != 0) {
			criterias.append(" AND t.forum_id = "+ sd.getForumId());
		}
		
		if (sd.getCategoryId() != 0) {
			criterias.append(" AND f.categories_id = "+ sd.getCategoryId());
		}
		
		if (sd.getOrderByField() == null || sd.getOrderByField().equals("")) {
			sd.setOrderByField("p.post_time");
		}
		
		String sql = SystemGlobals.getSql("SearchModel.searchBase");
		// Prepare the query
		sql = sql.replaceAll(":orderByField:", sd.getOrderByField());
		sql = sql.replaceAll(":orderBy:", sd.getOrderBy());
		sql = sql.replaceAll(":criterias:", criterias.toString());
		
		PreparedStatement p = JForum.getConnection().prepareStatement(sql);
		p.setString(1, SessionFacade.getUserSession().getSessionId());
		p.setString(2, SessionFacade.getUserSession().getSessionId());

		ResultSet rs = p.executeQuery();
		
		l = new TopicModel().fillTopicsData(rs);
		
		rs.close();
		p.close();
		
		return l;
	}
	
	// Find topics by time
	private void topicsByTime(SearchData sd) throws Exception
	{
		PreparedStatement p = JForum.getConnection().prepareStatement(SystemGlobals.getSql("SearchModel.searchByTime"));
		p.setString(1, SessionFacade.getUserSession().getSessionId());
		p.setTimestamp(2, new Timestamp(sd.getTime().getTime()));
		p.executeUpdate();
		p.close();
		
		this.selectTopicData();
	}
	
	// Given a set of keywords, find the topics
	private void topicsByKeyword(SearchData sd) throws Exception
	{
		PreparedStatement p = JForum.getConnection().prepareStatement(SystemGlobals.getSql("SearchModel.searchByWord"));

		HashMap eachWordMap = new HashMap();

		// Get the post ids to which the words are associated to
		for (int i = 0; i < sd.getKeywords().length; i++) {
			p.setString(1, "%" + sd.getKeywords()[i] + "%");
			
			HashSet postsIds = new HashSet();
			ResultSet rs = p.executeQuery();
			while (rs.next()) {
				postsIds.add(new Integer(rs.getInt("post_id")));
			}
			
			if (postsIds.size() > 0) {
				eachWordMap.put(sd.getKeywords()[i], postsIds);
			}
		}
		
		// [wordName] = { each, post, id }
		
		// If seach type is OR, then get all words
		// If it is AND, then we want only the ids common to all words
		// ( oooohhh.. really? that's soooo unlogic )
		HashSet postsIds = null;
		
		if (sd.getUseAllWords()) {
			for (Iterator iter = eachWordMap.values().iterator(); iter.hasNext(); ) {
				if (postsIds == null) {
					postsIds = new HashSet(eachWordMap.values().size());
					postsIds.addAll((HashSet)iter.next());
				}
				else {
					postsIds.retainAll((HashSet)iter.next());
				}
			}
		}
		else {
			postsIds = new HashSet();
			
			for (Iterator iter = eachWordMap.values().iterator(); iter.hasNext(); ) {
				postsIds.addAll((HashSet)iter.next());
			}
		}
		
		if (postsIds == null || postsIds.size() == 0) {
			return;
		}
		
		// Time to get ready to search for the topics ids 
		StringBuffer sb = new StringBuffer(1024);
		for (Iterator iter = postsIds.iterator(); iter.hasNext(); ) {
			sb.append(iter.next()).append(",");
		}
		sb.delete(sb.length() - 1, sb.length());

		// Search for the ids, inserting them in the helper table 
		String sql = SystemGlobals.getSql("SearchModel.insertTopicsIds");
		sql = sql.replaceAll(":posts:", sb.toString());
		p = JForum.getConnection().prepareStatement(sql);
		p.setString(1, SessionFacade.getUserSession().getSessionId());
		p.executeUpdate();
		
		// Now that we have the topics ids, it's time to make a copy from the 
		// topics table, to make the search faster ( damn, next version I'll 
		// remove the search functionality. Look for this code's size )
		this.selectTopicData();
		
		p.close();
	}
	
	private void selectTopicData() throws Exception
	{
		PreparedStatement p = JForum.getConnection().prepareStatement(SystemGlobals.getSql("SearchModel.selectTopicData"));
		p.setString(1, SessionFacade.getUserSession().getSessionId());
		p.setString(2, SessionFacade.getUserSession().getSessionId());
		p.executeUpdate();
		
		p.close();
	}
	
	public void insertSearchWords(Post post) throws Exception
	{
		PreparedStatement insert = this.getStatementForAutoKeys("SearchModel.insertWords");
		PreparedStatement existing = JForum.getConnection().prepareStatement(
						SystemGlobals.getSql("SearchModel.searchExistingWord"));
		
		PreparedStatement existingAssociation = JForum.getConnection().prepareStatement(
						SystemGlobals.getSql("SearchModel.searchExistingAssociation"));
		existingAssociation.setInt(2, post.getId());
		
		PreparedStatement wordToPost = JForum.getConnection().prepareStatement(
						SystemGlobals.getSql("SearchModel.associateWordToPost"));
		wordToPost.setInt(1, post.getId());
		
		String str = post.getText() +" "+ post.getSubject();
		String[] words = str.toLowerCase().replaceAll("[\\.\\\\\\/~^&\\(\\)-_+=!@#$%\"\'\\[\\]\\{\\}?<:>,*]", " ").split(" ");
						
		for (int i = 0; i < words.length; i++) {
			words[i] = words[i].trim();
			// Skip words less than 3 chars
			if (words[i].length() < 3) {
				continue;
			}
			
			// Verify if the current word is not in the database before proceeding
			int hash = words[i].hashCode();
			existing.setInt(1, hash);
			ResultSet rs = existing.executeQuery();

			if (!rs.next()) {
				// The word is not in the database. Insert it now
				insert.setInt(1, hash);
				insert.setString(2, words[i]);
				int wordId = this.executeAutoKeysQuery(insert);

				// Associate the current word to the post
				this.associateWordToPost(wordToPost, words[i], wordId, post);
			}
			else {
				// The word is already in the database ( jforum_search_words )
				// Check then if the current post is not already associated to the word
				int wordId = rs.getInt("word_id");
				existingAssociation.setInt(1, wordId);
				
				ResultSet rsa = existingAssociation.executeQuery();
				if (!rsa.next()) {
					// Assoacite the post to the word
					this.associateWordToPost(wordToPost, words[i], wordId, post);
				}
				rsa.close();
			}
			
			rs.close();
		}
		
		insert.close();
		existing.close();
		wordToPost.close();
	}
	
	private void associateWordToPost(PreparedStatement p, String word, int wordId, Post post) throws Exception
	{
		p.setInt(2, wordId);
		
		String subject = post.getSubject();
		int inSubject = 0;
		if (subject != null && !subject.equals("")) {
			inSubject = subject.indexOf(word) > -1 ? 1 : 0;
		}
		
		p.setInt(3, inSubject);
		p.executeUpdate();
	}

	/** 
	 * @see net.jforum.model.SearchModel#cleanSearch()
	 */
	public void cleanSearch() throws Exception
	{
		PreparedStatement p = JForum.getConnection().prepareStatement(SystemGlobals.getSql("SearchModel.cleanSearchTopics"));
		p.setString(1, SessionFacade.getUserSession().getSessionId());
		p.executeUpdate();
		
		p = JForum.getConnection().prepareStatement(SystemGlobals.getSql("SearchModel.cleanSearchResults"));
		p.setString(1, SessionFacade.getUserSession().getSessionId());
		p.executeUpdate();
		p.close();
	}
}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
日本午夜精品一区二区三区电影| 日韩一卡二卡三卡| 日韩成人免费电影| 夜夜爽夜夜爽精品视频| 国产精品久久久久久福利一牛影视 | 91免费在线播放| 国产精品456露脸| 青娱乐精品视频在线| 国产婷婷色一区二区三区四区| 99久久久精品| 成人久久视频在线观看| 九九热在线视频观看这里只有精品 | 夜夜嗨av一区二区三区中文字幕 | 亚洲麻豆国产自偷在线| 亚洲国产精品久久久久婷婷884| 福利一区在线观看| 亚洲色图.com| 欧美日韩在线一区二区| 亚洲福利一区二区| 欧美成人国产一区二区| 国内成人自拍视频| 欧美日韩在线播放一区| 日韩三级av在线播放| 亚洲午夜一区二区| 日本国产一区二区| 亚洲日韩欧美一区二区在线| 日韩高清不卡一区二区| 99久久99精品久久久久久| 国产精品素人一区二区| 日韩精品国产欧美| 欧美日韩在线播放三区四区| 麻豆久久一区二区| 午夜久久福利影院| 国产在线精品免费| 精品久久久久久最新网址| 亚洲美女电影在线| 97国产一区二区| 日本不卡123| 欧美精品视频www在线观看| 中文字幕av一区二区三区 | 午夜精品久久久久久久久久久| 亚洲成年人影院| 国产欧美1区2区3区| 久久国产精品无码网站| 91精品黄色片免费大全| 蜜臀久久99精品久久久久宅男 | 欧美日韩中文字幕一区| 欧美tk—视频vk| 欧美一二三在线| 国产亚洲精品免费| 五月激情丁香一区二区三区| 欧美影院午夜播放| 另类人妖一区二区av| 久久久一区二区三区| 欧美一区二区三区色| 欧美性生交片4| 欧美中文字幕一区二区三区| 色综合久久综合| 成人精品鲁一区一区二区| 成人性色生活片| 国产成人日日夜夜| 九一久久久久久| 亚洲人成小说网站色在线| 欧日韩精品视频| 久久精品国产一区二区三区免费看| 欧美一级视频精品观看| 欧美在线观看视频一区二区| 成人午夜视频网站| 日韩成人午夜精品| 国产精品色眯眯| 777午夜精品免费视频| 成人精品国产福利| 91视频一区二区| 中文字幕av资源一区| www.欧美.com| 久久99国产精品免费网站| 亚洲一区在线观看网站| 国产三区在线成人av| 在线播放日韩导航| 欧美调教femdomvk| 国产精品亚洲人在线观看| 在线不卡欧美精品一区二区三区| 一区二区三区四区蜜桃| 欧美视频在线不卡| 亚洲免费观看高清完整版在线 | 亚洲一区视频在线观看视频| 国产亚洲人成网站| 国产精品欧美一级免费| 一区二区在线电影| 国产在线看一区| 成人小视频在线观看| 欧美三级韩国三级日本一级| 91精品国产乱码| 国产精品―色哟哟| 国产精品一区二区你懂的| 99久精品国产| 欧美videossexotv100| 欧美精品一卡二卡| 色综合天天综合网天天看片| 成人免费视频一区| 色综合网站在线| 欧美精品777| 精品国产一区二区亚洲人成毛片 | 国产成人免费视| 亚洲大片精品永久免费| eeuss影院一区二区三区| 国产精品资源在线观看| 奇米色一区二区三区四区| 亚洲视频在线观看三级| 久久久久久麻豆| 久久青草国产手机看片福利盒子| 国产欧美精品在线观看| 一区二区三区四区高清精品免费观看 | 久久久精品一品道一区| 亚洲激情一二三区| 91老师片黄在线观看| 国产精品久久久久精k8 | 久久电影网电视剧免费观看| 亚洲少妇30p| 久久99精品国产.久久久久 | 免费观看在线色综合| 亚洲午夜精品17c| 麻豆精品在线视频| 国产一区二区视频在线| 夜夜爽夜夜爽精品视频| 成年人网站91| 911精品国产一区二区在线| 理论电影国产精品| 精品国产一区二区三区av性色| 欧美性一区二区| 久久视频一区二区| 久久嫩草精品久久久久| 欧美军同video69gay| 在线免费一区三区| 欧美草草影院在线视频| 久久久久久久电影| 亚洲免费高清视频在线| 日韩一级在线观看| 免费xxxx性欧美18vr| 成人av手机在线观看| 国产精品视频一二三| 99精品视频在线免费观看| 欧美激情自拍偷拍| 一个色妞综合视频在线观看| 亚洲高清免费视频| av毛片久久久久**hd| 精品久久久三级丝袜| 国产成人免费在线| 伊人夜夜躁av伊人久久| 不卡电影一区二区三区| 韩国精品一区二区| 久久蜜桃一区二区| 欧美日韩久久不卡| 成熟亚洲日本毛茸茸凸凹| 天天综合色天天综合色h| 国产目拍亚洲精品99久久精品| 欧美一级片免费看| 欧美精品视频www在线观看| 色综合天天视频在线观看| 狠狠色狠狠色综合| 欧美国产激情一区二区三区蜜月| 色香蕉成人二区免费| 午夜天堂影视香蕉久久| 欧美一区二区在线视频| 午夜精品福利视频网站| 宅男噜噜噜66一区二区66| 亚洲超碰精品一区二区| 精品国产成人在线影院| 91久久精品一区二区三| 午夜欧美大尺度福利影院在线看| 久久精品国产77777蜜臀| 91麻豆精品秘密| 国产精品色在线观看| 国产乱人伦偷精品视频免下载| 日韩一区二区电影网| 亚洲线精品一区二区三区八戒| 色狠狠桃花综合| 国产精品久久久爽爽爽麻豆色哟哟 | 色丁香久综合在线久综合在线观看| 精品国精品国产| 国产在线视频一区二区| 51精品国自产在线| 日本中文一区二区三区| 欧美午夜精品理论片a级按摩| 亚洲成人一区二区在线观看| 欧美三级资源在线| 依依成人精品视频| 欧美中文一区二区三区| 亚洲成av人片一区二区梦乃| 在线影院国内精品| 日韩avvvv在线播放| 欧美日韩一区二区三区免费看| 日韩中文字幕av电影| 欧美日韩一二区| 中文字幕在线免费不卡| 亚洲国产日韩av| 色老头久久综合| 久久久综合精品| 成人黄色免费短视频| 亚洲va中文字幕|