Lucene实战
导包
添加文章
addArticle.jsp <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>添加文章</title> </head> <body> <center> <h2>添加文章</h2> <form action="${pageContext.request.contextPath}/addArtical.action" method="post"> <table> <tr> <td>文章标题</td> <td> <input type="text" name="title"/> </td> </tr> <tr> <td>文章内容</td> <td> <textarea rows="20" cols="20" name="content"></textarea> </td> </tr> <tr> <td> <input type="submit" value="添加"> </td> <td> <input type="button" value="跳转至列表页面" onclick="window.location = '${pageContext.request.contextPath}/listArticle.jsp'"> </td> </tr> </table> </form> </center> </body> </html> |
addServlet.java package org.crdit.action; import java.io.IOException; import java.nio.file.Paths; import java.util.UUID; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.analysis.cn.smart.SmartChineseAnalyzer; import org.apache.lucene.document.Document; import org.apache.lucene.document.StringField; import org.apache.lucene.document.TextField; import org.apache.lucene.document.Field.Store; import org.apache.lucene.index.IndexWriter; import org.apache.lucene.index.IndexWriterConfig; import org.apache.lucene.index.IndexWriterConfig.OpenMode; import org.apache.lucene.store.Directory; import org.apache.lucene.store.FSDirectory; /** * Servlet implementation class AddServlet * 添加文章信息 */ @WebServlet("/addArtical.action") public class AddServlet extends HttpServlet { private static final long serialVersionUID = 1L; /** * @see HttpServlet#HttpServlet() */ public AddServlet() { super(); // TODO Auto-generated constructor stub } @Override protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try { //通过request设置请求编码信息,防止中文乱码 request.setCharacterEncoding("UTF-8"); //获取用户输入的信息 String title=request.getParameter("title"); String content=request.getParameter("content"); //指定索引所在目录 Directory directory=FSDirectory.open(Paths.get("E:\\Lucene\\Lucene_db\\artical_tb")); //词库分词 需要导jar包 lucene-analyzers-smartcn.jar Analyzer analyzer = new SmartChineseAnalyzer(); //创建IndexWriterConfig实例 指定添加索引的配置信息 IndexWriterConfig config=new IndexWriterConfig(analyzer); //如果索引不存在,则创建。存在,则追加。 config.setOpenMode(OpenMode.CREATE_OR_APPEND); //创建IndexWriter IndexWriter indexWriter=new IndexWriter(directory, config); //往索引库中添加记录 Lucene中一个document实例代表数据表中的一条记录 Document document=new Document(); /* *StringFiled:不会对关键字进行分词 *TextFiled:会对关键字进行分词 * * Store.YES:会将数据进行存储并分词 * Store.NO:不会将数据进行存储,不会分词,索引还是会创建。有索引,没有内容。 */ //通过UUID生成一个唯一的随机数 String articleId=UUID.randomUUID().toString(); document.add(new StringField("articleId",articleId , Store.YES)); document.add(new TextField("title", title, Store.YES)); document.add(new TextField("content", content, Store.YES)); document.add(new TextField("allArticle", "@allArticle", Store.YES)); indexWriter.addDocument(document); //提交事务 indexWriter.commit(); //关闭事务 indexWriter.close(); System.out.println("添加成功"); } catch (Exception e) { e.printStackTrace(); } //跳转至添加文章页面 request.getRequestDispatcher("/addArticle.jsp").forward(request, response); } } |
添加分页
添加pager.tld放到WEB-INF下
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE taglib PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.1//EN" "http://java.sun.com/j2ee/dtds/web-jsptaglibrary_1_1.dtd"> <taglib> <!-- 标签版本号 --> <tlibversion>1.0</tlibversion> <!-- JSP版本号 --> <jspversion>1.1</jspversion> <!-- 标签简称号 --> <shortname>checkLogon</shortname> <!-- URI地址,jsp页面可以通过引入该地址与标签进行关联 并找到标签处理类 --> <uri>myPager-tag</uri> <info> 我的分页标签,总共24种 </info> <tag> <!-- 指定标签名 --> <name>pager</name> <!-- 标签处理类 需要指定 包名+类名 --> <tagclass>org.crdit.pager.Pager</tagclass> <!-- 标签中的属性 --> <attribute> <!--声明属性名称 --> <name>pageIndex</name> <!-- 是否必填 --> <required>false</required> <!-- 是否支持EL表达式 --> <rtexprvalue>true</rtexprvalue> </attribute> <attribute> <name>pageSize</name> <required>false</required> <rtexprvalue>true</rtexprvalue> </attribute> <attribute> <name>totalNum</name> <required>false</required> <rtexprvalue>true</rtexprvalue> </attribute> <attribute> <name>submitUrl</name> <required>false</required> <rtexprvalue>true</rtexprvalue> </attribute> <attribute> <name>pageStyle</name> <required>false</required> <rtexprvalue>true</rtexprvalue> </attribute> </tag> </taglib> |
Pager.java package org.crdit.pager; import java.io.IOException; import javax.servlet.jsp.JspException; import javax.servlet.jsp.JspWriter; import javax.servlet.jsp.tagext.TagSupport; /** * @author crd * 创建标签处理类 */ public class Pager extends TagSupport { private int pageIndex; //当前页码 private int pageSize; //每一页显示的记录数 private int totalNum; //总记录数 private String submitUrl; //提交地址 private String pageStyle="";//样式 public int getPageIndex() { return pageIndex; } public void setPageIndex(int pageIndex) { if(pageIndex==0){ pageIndex = 1; } this.pageIndex = pageIndex; } public int getPageSize() { return pageSize; } public void setPageSize(int pageSize) { this.pageSize = pageSize; } public int getTotalNum() { return totalNum; } public void setTotalNum(int totalNum) { this.totalNum = totalNum; } public String getSubmitUrl() { return submitUrl; } public void setSubmitUrl(String submitUrl) { this.submitUrl = submitUrl; } public String getPageStyle() { return pageStyle; } public void setPageStyle(String pageStyle) { this.pageStyle = pageStyle; } @Override public int doStartTag() throws JspException { try { JspWriter jspWriter= this.pageContext.getOut(); //创建StringBuffer实例,用于拼装页码相关信息 StringBuffer sbf=new StringBuffer(); String jumpUrl; //判断总记录数是否大于0 if(totalNum>0){ //计算总共的页数 int totalPageNum=this.totalNum%this.pageSize==0?this.totalNum/this.pageSize:this.totalNum/this.pageSize+1; StringBuffer pager=new StringBuffer(); //如果当前在第一页 if(pageIndex==1){ pager.append("<span class='disabled'>上一页</span>"); //计算中间页码 calcMiddle(pager,totalPageNum); //如果总共就一页,那么下一页也不能点击 if(totalPageNum==1){ pager.append("<span class='disabled'>下一页</span>"); }else{ jumpUrl=this.submitUrl.replace("{0}", String.valueOf(this.pageIndex+1)); //可以点击下一页 pager.append("<a href='"+jumpUrl+"'>下一页</a>"); } //如果当前页码是尾页 }else if(this.pageIndex==totalPageNum){ jumpUrl=this.submitUrl.replace("{0}", String.valueOf(this.pageIndex-1)); //可以点击下一页 pager.append("<a href='"+jumpUrl+"'>上一页</a>"); //计算中间页码 calcMiddle(pager,totalPageNum); pager.append("<span class='disabled'>下一页</span>"); //当前页码既不是首页也不是尾页 }else{ jumpUrl=this.submitUrl.replace("{0}", String.valueOf(this.pageIndex-1)); //可以点击下一页 pager.append("<a href='"+jumpUrl+"'>上一页</a>"); //计算中间页码 calcMiddle(pager,totalPageNum); jumpUrl=this.submitUrl.replace("{0}", String.valueOf(this.pageIndex+1)); //可以点击下一页 pager.append("<a href='"+jumpUrl+"'>下一页</a>"); } sbf.append("<table align='center' class='"+pageStyle+"' style='width:100%;font-size:14px'> <tr><td>"+pager.toString()+"</td></tr>"); //定义开始记录号,每页显示10条 int startSize=(this.pageIndex-1)*this.pageSize+1; //定义结束记录号 int endSize=this.pageIndex==totalPageNum?totalNum:this.pageIndex*this.pageSize; sbf.append("<tr><td>总共<font color='red'>"+totalNum+"</font>条记录,当前显示"+startSize+"-"+endSize+"条记录</td></tr></table>"); }else{ sbf.append("<table align='center' class='"+pageStyle+"' style='width:100%;font-size:14px'><tr><td>总共<font color='red'>0</font>条记录,当前显示0-0条记录</td></tr></table>"); } jspWriter.write(sbf.toString()); } catch (IOException e) { e.printStackTrace(); } return super.doStartTag(); } /** * 计算中间页码 * @param pager * @param totalPageNum 总页码数 */ public void calcMiddle(StringBuffer pager,int totalPageNum) { String jumpUrl=""; //如果总页码数小于等于10 1 2 3 4 5 6 7 8 9 10 if(totalPageNum<=10){ for (int i = 1; i <=totalPageNum; i++) { //如果i等于当前页码,则不能点 if(i==this.pageIndex){ pager.append("<span class='current'>"+i+"</span>"); }else{ jumpUrl=this.submitUrl.replace("{0}",String.valueOf(i)); pager.append("<a href='"+jumpUrl+"'>"+i+"</a>"); } } }else{ //如果当前页码靠近首页 1 2 3 4 5 6 7 8 9 ... 100 if(pageIndex<=8){ for (int i = 1; i <=9; i++) { //如果i等于当前页码,则不能点 if(i==this.pageIndex){ pager.append("<span class='current'>"+i+"</span>"); }else{ jumpUrl=this.submitUrl.replace("{0}",String.valueOf(i)); pager.append("<a href='"+jumpUrl+"'>"+i+"</a>"); } } pager.append("..."); //拼装尾页 jumpUrl=this.submitUrl.replace("{0}",String.valueOf(totalPageNum)); pager.append("<a href='"+jumpUrl+"'>"+totalPageNum+"</a>"); //当前页码靠近尾页 }else if(pageIndex+8>=totalPageNum){ //拼装首页 jumpUrl=this.submitUrl.replace("{0}",String.valueOf(1)); pager.append("<a href='"+jumpUrl+"'>"+1+"</a>"); pager.append("..."); for (int i = totalPageNum-9; i <=totalPageNum; i++) { //如果i等于当前页码,则不能点 if(i==this.pageIndex){ pager.append("<span class='current'>"+i+"</span>"); }else{ jumpUrl=this.submitUrl.replace("{0}",String.valueOf(i)); pager.append("<a href='"+jumpUrl+"'>"+i+"</a>"); } } //当前页码靠中间 }else{ //拼装首页 jumpUrl=this.submitUrl.replace("{0}",String.valueOf(1)); pager.append("<a href='"+jumpUrl+"'>"+1+"</a>"); pager.append("..."); for (int i = this.pageIndex-4; i <=this.pageIndex+4; i++) { //如果i等于当前页码,则不能点 if(i==this.pageIndex){ pager.append("<span class='current'>"+i+"</span>"); }else{ jumpUrl=this.submitUrl.replace("{0}",String.valueOf(i)); pager.append("<a href='"+jumpUrl+"'>"+i+"</a>"); } } pager.append("..."); //拼装尾页 jumpUrl=this.submitUrl.replace("{0}",String.valueOf(totalPageNum)); pager.append("<a href='"+jumpUrl+"'>"+totalPageNum+"</a>"); } } } } |
添加样式文件 .digg { PADDING-RIGHT: 3px; PADDING-LEFT: 3px; PADDING-BOTTOM: 3px; MARGIN: 3px; PADDING-TOP: 3px; TEXT-ALIGN: center } .digg A { BORDER-RIGHT: #aaaadd 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #aaaadd 1px solid; PADDING-LEFT: 5px; PADDING-BOTTOM: 2px; MARGIN: 2px; BORDER-LEFT: #aaaadd 1px solid; COLOR: #000099; PADDING-TOP: 2px; BORDER-BOTTOM: #aaaadd 1px solid; TEXT-DECORATION: none } .digg A:hover { BORDER-RIGHT: #000099 1px solid; BORDER-TOP: #000099 1px solid; BORDER-LEFT: #000099 1px solid; COLOR: #000; BORDER-BOTTOM: #000099 1px solid } .digg A:active { BORDER-RIGHT: #000099 1px solid; BORDER-TOP: #000099 1px solid; BORDER-LEFT: #000099 1px solid; COLOR: #000; BORDER-BOTTOM: #000099 1px solid } .digg SPAN.current { BORDER-RIGHT: #000099 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #000099 1px solid; PADDING-LEFT: 5px; FONT-WEIGHT: bold; PADDING-BOTTOM: 2px; MARGIN: 2px; BORDER-LEFT: #000099 1px solid; COLOR: #fff; PADDING-TOP: 2px; BORDER-BOTTOM: #000099 1px solid; mso-para-margin-bottom:0.0000gd;text-align:left;">} .digg SPAN.disabled { BORDER-RIGHT: #eee 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #eee 1px solid; PADDING-LEFT: 5px; PADDING-BOTTOM: 2px; MARGIN: 2px; BORDER-LEFT: #eee 1px solid; COLOR: #ddd; PADDING-TOP: 2px; BORDER-BOTTOM: #eee 1px solid } /*CSS yahoo style pagination*/ .yahoo { PADDING-RIGHT: 3px; PADDING-LEFT: 3px; PADDING-BOTTOM: 3px; MARGIN: 3px; PADDING-TOP: 3px; TEXT-ALIGN: center } .yahoo A { BORDER-RIGHT: #fff 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #fff 1px solid; PADDING-LEFT: 5px; PADDING-BOTTOM: 2px; MARGIN: 2px; BORDER-LEFT: #fff 1px solid; COLOR: #000099; PADDING-TOP: 2px; BORDER-BOTTOM: #fff 1px solid; TEXT-DECORATION: underline } .yahoo A:hover { BORDER-RIGHT: #000099 1px solid; BORDER-TOP: #000099 1px solid; BORDER-LEFT: #000099 1px solid; COLOR: #000; BORDER-BOTTOM: #000099 1px solid } .yahoo A:active { BORDER-RIGHT: #000099 1px solid; BORDER-TOP: #000099 1px solid; BORDER-LEFT: #000099 1px solid; COLOR: #f00; BORDER-BOTTOM: #000099 1px solid } .yahoo SPAN.current { BORDER-RIGHT: #fff 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #fff 1px solid; PADDING-LEFT: 5px; FONT-WEIGHT: bold; PADDING-BOTTOM: 2px; MARGIN: 2px; BORDER-LEFT: #fff 1px solid; COLOR: #000; PADDING-TOP: 2px; BORDER-BOTTOM: #fff 1px solid; mso-para-margin-bottom:0.0000gd;text-align:left;">} .yahoo SPAN.disabled { BORDER-RIGHT: #eee 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #eee 1px solid; PADDING-LEFT: 5px; PADDING-BOTTOM: 2px; MARGIN: 2px; BORDER-LEFT: #eee 1px solid; COLOR: #ddd; PADDING-TOP: 2px; BORDER-BOTTOM: #eee 1px solid } /*CSS meneame style pagination*/ .meneame { PADDING-RIGHT: 3px; PADDING-LEFT: 3px; FONT-SIZE: 80%; PADDING-BOTTOM: 3px; MARGIN: 3px; COLOR: #ff6500; PADDING-TOP: 3px; TEXT-ALIGN: center } .meneame A { BORDER-RIGHT: #ff9600 1px solid; PADDING-RIGHT: 7px; BACKGROUND-POSITION: 50% bottom; BORDER-TOP: #ff9600 1px solid; PADDING-LEFT: 7px; BACKGROUND-IMAGE: url(meneame.jpg); PADDING-BOTTOM: 5px; BORDER-LEFT: #ff9600 1px solid; COLOR: #ff6500; MARGIN-RIGHT: 3px; PADDING-TOP: 5px; BORDER-BOTTOM: #ff9600 1px solid; TEXT-DECORATION: none } .meneame A:hover { BORDER-RIGHT: #ff9600 1px solid; BORDER-TOP: #ff9600 1px solid; BACKGROUND-IMAGE: none; BORDER-LEFT: #ff9600 1px solid; COLOR: #ff6500; BORDER-BOTTOM: #ff9600 1px solid; mso-para-margin-bottom:0.0000gd;text-align:left;">} .meneame A:active { BORDER-RIGHT: #ff9600 1px solid; BORDER-TOP: #ff9600 1px solid; BACKGROUND-IMAGE: none; BORDER-LEFT: #ff9600 1px solid; COLOR: #ff6500; BORDER-BOTTOM: #ff9600 1px solid; mso-para-margin-bottom:0.0000gd;text-align:left;">} .meneame SPAN.current { BORDER-RIGHT: #ff6500 1px solid; PADDING-RIGHT: 7px; BORDER-TOP: #ff6500 1px solid; PADDING-LEFT: 7px; FONT-WEIGHT: bold; PADDING-BOTTOM: 5px; BORDER-LEFT: #ff6500 1px solid; COLOR: #ff6500; MARGIN-RIGHT: 3px; PADDING-TOP: 5px; BORDER-BOTTOM: #ff6500 1px solid; mso-para-margin-bottom:0.0000gd;text-align:left;">} .meneame SPAN.disabled { BORDER-RIGHT: #ffe3c6 1px solid; PADDING-RIGHT: 7px; BORDER-TOP: #ffe3c6 1px solid; PADDING-LEFT: 7px; PADDING-BOTTOM: 5px; BORDER-LEFT: #ffe3c6 1px solid; COLOR: #ffe3c6; MARGIN-RIGHT: 3px; PADDING-TOP: 5px; BORDER-BOTTOM: #ffe3c6 1px solid } /*CSS flickr style pagination*/ .flickr { PADDING-RIGHT: 3px; PADDING-LEFT: 3px; PADDING-BOTTOM: 3px; MARGIN: 3px; PADDING-TOP: 3px; TEXT-ALIGN: center } .flickr A { BORDER-RIGHT: #dedfde 1px solid; PADDING-RIGHT: 6px; BACKGROUND-POSITION: 50% bottom; BORDER-TOP: #dedfde 1px solid; PADDING-LEFT: 6px; PADDING-BOTTOM: 2px; BORDER-LEFT: #dedfde 1px solid; COLOR: #0061de; MARGIN-RIGHT: 3px; PADDING-TOP: 2px; BORDER-BOTTOM: #dedfde 1px solid; TEXT-DECORATION: none } .flickr A:hover { BORDER-RIGHT: #000 1px solid; BORDER-TOP: #000 1px solid; BACKGROUND-IMAGE: none; BORDER-LEFT: #000 1px solid; COLOR: #fff; BORDER-BOTTOM: #000 1px solid; mso-para-margin-bottom:0.0000gd;text-align:left;">} .meneame A:active { BORDER-RIGHT: #000 1px solid; BORDER-TOP: #000 1px solid; BACKGROUND-IMAGE: none; BORDER-LEFT: #000 1px solid; COLOR: #fff; BORDER-BOTTOM: #000 1px solid; mso-para-margin-bottom:0.0000gd;text-align:left;">} .flickr SPAN.current { PADDING-RIGHT: 6px; PADDING-LEFT: 6px; FONT-WEIGHT: bold; PADDING-BOTTOM: 2px; COLOR: #ff0084; MARGIN-RIGHT: 3px; PADDING-TOP: 2px } .flickr SPAN.disabled { PADDING-RIGHT: 6px; PADDING-LEFT: 6px; PADDING-BOTTOM: 2px; COLOR: #adaaad; MARGIN-RIGHT: 3px; PADDING-TOP: 2px } /*CSS sabrosus style pagination*/ .sabrosus { PADDING-RIGHT: 3px; PADDING-LEFT: 3px; PADDING-BOTTOM: 3px; MARGIN: 3px; PADDING-TOP: 3px; TEXT-ALIGN: center } .sabrosus A { BORDER-RIGHT: #9aafe5 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #9aafe5 1px solid; PADDING-LEFT: 5px; PADDING-BOTTOM: 2px; BORDER-LEFT: #9aafe5 1px solid; COLOR: #2e6ab1; MARGIN-RIGHT: 2px; PADDING-TOP: 2px; BORDER-BOTTOM: #9aafe5 1px solid; TEXT-DECORATION: none } .sabrosus A:hover { BORDER-RIGHT: #2b66a5 1px solid; BORDER-TOP: #2b66a5 1px solid; BORDER-LEFT: #2b66a5 1px solid; COLOR: #000; BORDER-BOTTOM: #2b66a5 1px solid; mso-para-margin-bottom:0.0000gd;text-align:left;">} .pagination A:active { BORDER-RIGHT: #2b66a5 1px solid; BORDER-TOP: #2b66a5 1px solid; BORDER-LEFT: #2b66a5 1px solid; COLOR: #000; BORDER-BOTTOM: #2b66a5 1px solid; mso-para-margin-bottom:0.0000gd;text-align:left;">} .sabrosus SPAN.current { BORDER-RIGHT: navy 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: navy 1px solid; PADDING-LEFT: 5px; FONT-WEIGHT: bold; PADDING-BOTTOM: 2px; BORDER-LEFT: navy 1px solid; COLOR: #fff; MARGIN-RIGHT: 2px; PADDING-TOP: 2px; BORDER-BOTTOM: navy 1px solid; mso-para-margin-bottom:0.0000gd;text-align:left;">} .sabrosus SPAN.disabled { BORDER-RIGHT: #929292 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #929292 1px solid; PADDING-LEFT: 5px; PADDING-BOTTOM: 2px; BORDER-LEFT: #929292 1px solid; COLOR: #929292; MARGIN-RIGHT: 2px; PADDING-TOP: 2px; BORDER-BOTTOM: #929292 1px solid } /*CSS scott style pagination*/ .scott { PADDING-RIGHT: 3px; PADDING-LEFT: 3px; PADDING-BOTTOM: 3px; MARGIN: 3px; PADDING-TOP: 3px; TEXT-ALIGN: center } .scott A { BORDER-RIGHT: #ddd 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #ddd 1px solid; PADDING-LEFT: 5px; PADDING-BOTTOM: 2px; BORDER-LEFT: #ddd 1px solid; COLOR: #88af3f; MARGIN-RIGHT: 2px; PADDING-TOP: 2px; BORDER-BOTTOM: #ddd 1px solid; TEXT-DECORATION: none } .scott A:hover { BORDER-RIGHT: #85bd1e 1px solid; BORDER-TOP: #85bd1e 1px solid; BORDER-LEFT: #85bd1e 1px solid; COLOR: #638425; BORDER-BOTTOM: #85bd1e 1px solid; mso-para-margin-bottom:0.0000gd;text-align:left;">} .scott A:active { BORDER-RIGHT: #85bd1e 1px solid; BORDER-TOP: #85bd1e 1px solid; BORDER-LEFT: #85bd1e 1px solid; COLOR: #638425; BORDER-BOTTOM: #85bd1e 1px solid; mso-para-margin-bottom:0.0000gd;text-align:left;">} .scott SPAN.current { BORDER-RIGHT: #b2e05d 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #b2e05d 1px solid; PADDING-LEFT: 5px; FONT-WEIGHT: bold; PADDING-BOTTOM: 2px; BORDER-LEFT: #b2e05d 1px solid; COLOR: #fff; MARGIN-RIGHT: 2px; PADDING-TOP: 2px; BORDER-BOTTOM: #b2e05d 1px solid; mso-para-margin-bottom:0.0000gd;text-align:left;">} .scott SPAN.disabled { BORDER-RIGHT: #f3f3f3 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #f3f3f3 1px solid; PADDING-LEFT: 5px; PADDING-BOTTOM: 2px; BORDER-LEFT: #f3f3f3 1px solid; COLOR: #ccc; MARGIN-RIGHT: 2px; PADDING-TOP: 2px; BORDER-BOTTOM: #f3f3f3 1px solid } /*CSS quotes style pagination*/ .quotes { PADDING-RIGHT: 3px; PADDING-LEFT: 3px; PADDING-BOTTOM: 3px; MARGIN: 3px; PADDING-TOP: 3px; TEXT-ALIGN: center } .quotes A { BORDER-RIGHT: #ddd 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #ddd 1px solid; PADDING-LEFT: 5px; PADDING-BOTTOM: 2px; BORDER-LEFT: #ddd 1px solid; COLOR: #aaa; MARGIN-RIGHT: 2px; PADDING-TOP: 2px; BORDER-BOTTOM: #ddd 1px solid; TEXT-DECORATION: none } .quotes A:hover { BORDER-RIGHT: #a0a0a0 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #a0a0a0 1px solid; PADDING-LEFT: 5px; PADDING-BOTTOM: 2px; BORDER-LEFT: #a0a0a0 1px solid; MARGIN-RIGHT: 2px; PADDING-TOP: 2px; BORDER-BOTTOM: #a0a0a0 1px solid } .quotes A:active { BORDER-RIGHT: #a0a0a0 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #a0a0a0 1px solid; PADDING-LEFT: 5px; PADDING-BOTTOM: 2px; BORDER-LEFT: #a0a0a0 1px solid; MARGIN-RIGHT: 2px; PADDING-TOP: 2px; BORDER-BOTTOM: #a0a0a0 1px solid } .quotes SPAN.current { BORDER-RIGHT: #e0e0e0 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #e0e0e0 1px solid; PADDING-LEFT: 5px; FONT-WEIGHT: bold; PADDING-BOTTOM: 2px; BORDER-LEFT: #e0e0e0 1px solid; COLOR: #aaa; MARGIN-RIGHT: 2px; PADDING-TOP: 2px; BORDER-BOTTOM: #e0e0e0 1px solid; mso-para-margin-bottom:0.0000gd;text-align:left;">} .quotes SPAN.disabled { BORDER-RIGHT: #f3f3f3 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #f3f3f3 1px solid; PADDING-LEFT: 5px; PADDING-BOTTOM: 2px; BORDER-LEFT: #f3f3f3 1px solid; COLOR: #ccc; MARGIN-RIGHT: 2px; PADDING-TOP: 2px; BORDER-BOTTOM: #f3f3f3 1px solid } /*CSS black style pagination*/ .black { PADDING-RIGHT: 3px; PADDING-LEFT: 3px; FONT-SIZE: 80%; PADDING-BOTTOM: 10px; MARGIN: 3px; COLOR: #a0a0a0; PADDING-TOP: 10px; TEXT-ALIGN: center } .black A { BORDER-RIGHT: #909090 1px solid; PADDING-RIGHT: 5px; BACKGROUND-POSITION: 50% bottom; BORDER-TOP: #909090 1px solid; PADDING-LEFT: 5px; BACKGROUND-IMAGE: url(bar.gif); PADDING-BOTTOM: 2px; BORDER-LEFT: #909090 1px solid; COLOR: #c0c0c0; MARGIN-RIGHT: 3px; PADDING-TOP: 2px; BORDER-BOTTOM: #909090 1px solid; TEXT-DECORATION: none } .black A:hover { BORDER-RIGHT: #f0f0f0 1px solid; BORDER-TOP: #f0f0f0 1px solid; BACKGROUND-IMAGE: url(invbar.gif); BORDER-LEFT: #f0f0f0 1px solid; COLOR: #ffffff; BORDER-BOTTOM: #f0f0f0 1px solid; mso-para-margin-bottom:0.0000gd;text-align:left;">} .black A:active { BORDER-RIGHT: #f0f0f0 1px solid; BORDER-TOP: #f0f0f0 1px solid; BACKGROUND-IMAGE: url(invbar.gif); BORDER-LEFT: #f0f0f0 1px solid; COLOR: #ffffff; BORDER-BOTTOM: #f0f0f0 1px solid; mso-para-margin-bottom:0.0000gd;text-align:left;">} .black SPAN.current { BORDER-RIGHT: #ffffff 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #ffffff 1px solid; PADDING-LEFT: 5px; FONT-WEIGHT: bold; PADDING-BOTTOM: 2px; BORDER-LEFT: #ffffff 1px solid; COLOR: #ffffff; MARGIN-RIGHT: 3px; PADDING-TOP: 2px; BORDER-BOTTOM: #ffffff 1px solid; mso-para-margin-bottom:0.0000gd;text-align:left;">} .black SPAN.disabled { BORDER-RIGHT: #606060 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #606060 1px solid; PADDING-LEFT: 5px; PADDING-BOTTOM: 2px; BORDER-LEFT: #606060 1px solid; COLOR: #808080; MARGIN-RIGHT: 3px; PADDING-TOP: 2px; BORDER-BOTTOM: #606060 1px solid } /*CSS black2 style pagination*/ .black2 { PADDING-RIGHT: 7px; PADDING-LEFT: 7px; PADDING-BOTTOM: 7px; MARGIN: 3px; PADDING-TOP: 7px; TEXT-ALIGN: center } .black2 A { BORDER-RIGHT: #000000 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #000000 1px solid; PADDING-LEFT: 5px; PADDING-BOTTOM: 2px; MARGIN: 2px; BORDER-LEFT: #000000 1px solid; COLOR: #000000; PADDING-TOP: 2px; BORDER-BOTTOM: #000000 1px solid; TEXT-DECORATION: none } .black2 A:hover { BORDER-RIGHT: #000000 1px solid; BORDER-TOP: #000000 1px solid; BORDER-LEFT: #000000 1px solid; COLOR: #fff; BORDER-BOTTOM: #000000 1px solid; mso-para-margin-bottom:0.0000gd;text-align:left;">} .black2 A:active { BORDER-RIGHT: #000000 1px solid; BORDER-TOP: #000000 1px solid; BORDER-LEFT: #000000 1px solid; COLOR: #fff; BORDER-BOTTOM: #000000 1px solid; mso-para-margin-bottom:0.0000gd;text-align:left;">} .black2 SPAN.current { BORDER-RIGHT: #000000 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #000000 1px solid; PADDING-LEFT: 5px; FONT-WEIGHT: bold; PADDING-BOTTOM: 2px; MARGIN: 2px; BORDER-LEFT: #000000 1px solid; COLOR: #fff; PADDING-TOP: 2px; BORDER-BOTTOM: #000000 1px solid; mso-para-margin-bottom:0.0000gd;text-align:left;">} .black2 SPAN.disabled { BORDER-RIGHT: #eee 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #eee 1px solid; PADDING-LEFT: 5px; PADDING-BOTTOM: 2px; MARGIN: 2px; BORDER-LEFT: #eee 1px solid; COLOR: #ddd; PADDING-TOP: 2px; BORDER-BOTTOM: #eee 1px solid } /*CSS black-red style pagination*/ .black-red { FONT-SIZE: 11px; COLOR: #fff; FONT-FAMILY: Tahoma, Arial, Helvetica, Sans-serif; TEXT-ALIGN: center; } .black-red A { PADDING-RIGHT: 5px; PADDING-LEFT: 5px; PADDING-BOTTOM: 2px; MARGIN: 2px; COLOR: #fff; PADDING-TOP: 2px; TEXT-DECORATION: none } .black-red A:hover { COLOR: #fff; mso-para-margin-bottom:0.0000gd;text-align:left;">} .black-red A:active { COLOR: #fff; mso-para-margin-bottom:0.0000gd;text-align:left;">} .black-red SPAN.current { PADDING-RIGHT: 5px; PADDING-LEFT: 5px; FONT-WEIGHT: bold; PADDING-BOTTOM: 2px; MARGIN: 2px; COLOR: #fff; PADDING-TOP: 2px; mso-para-margin-bottom:0.0000gd;text-align:left;">} .black-red SPAN.disabled { PADDING-RIGHT: 5px; PADDING-LEFT: 5px; PADDING-BOTTOM: 2px; MARGIN: 2px; COLOR: #868686; PADDING-TOP: 2px; mso-para-margin-bottom:0.0000gd;text-align:left;">} /*CSS grayr style pagination*/ .grayr { PADDING-RIGHT: 2px; PADDING-LEFT: 2px; FONT-SIZE: 11px; PADDING-BOTTOM: 2px; PADDING-TOP: 2px; FONT-FAMILY: Tahoma, Arial, Helvetica, Sans-serif; TEXT-ALIGN: center; } .grayr A { PADDING-RIGHT: 5px; PADDING-LEFT: 5px; PADDING-BOTTOM: 2px; MARGIN: 2px; COLOR: #000; PADDING-TOP: 2px; TEXT-DECORATION: none } .grayr A:hover { COLOR: #000; mso-para-margin-bottom:0.0000gd;text-align:left;">} .grayr A:active { COLOR: #000; mso-para-margin-bottom:0.0000gd;text-align:left;">} .grayr SPAN.current { PADDING-RIGHT: 5px; PADDING-LEFT: 5px; FONT-WEIGHT: bold; PADDING-BOTTOM: 2px; MARGIN: 2px; COLOR: #303030; PADDING-TOP: 2px; mso-para-margin-bottom:0.0000gd;text-align:left;">} .grayr SPAN.disabled { PADDING-RIGHT: 5px; PADDING-LEFT: 5px; PADDING-BOTTOM: 2px; MARGIN: 2px; COLOR: #797979; PADDING-TOP: 2px; mso-para-margin-bottom:0.0000gd;text-align:left;">} /*CSS yellow style pagination*/ .yellow { PADDING-RIGHT: 7px; PADDING-LEFT: 7px; PADDING-BOTTOM: 7px; MARGIN: 3px; PADDING-TOP: 7px; TEXT-ALIGN: center } .yellow A { BORDER-RIGHT: #ccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #ccc 1px solid; PADDING-LEFT: 5px; PADDING-BOTTOM: 2px; MARGIN: 2px; BORDER-LEFT: #ccc 1px solid; COLOR: #000; PADDING-TOP: 2px; BORDER-BOTTOM: #ccc 1px solid; TEXT-DECORATION: none } .yellow A:hover { BORDER-RIGHT: #f0f0f0 1px solid; BORDER-TOP: #f0f0f0 1px solid; BORDER-LEFT: #f0f0f0 1px solid; COLOR: #000; BORDER-BOTTOM: #f0f0f0 1px solid } .yellow A:active { BORDER-RIGHT: #f0f0f0 1px solid; BORDER-TOP: #f0f0f0 1px solid; BORDER-LEFT: #f0f0f0 1px solid; COLOR: #000; BORDER-BOTTOM: #f0f0f0 1px solid } .yellow SPAN.current { BORDER-RIGHT: #d9d300 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #d9d300 1px solid; PADDING-LEFT: 5px; FONT-WEIGHT: bold; PADDING-BOTTOM: 2px; MARGIN: 2px; BORDER-LEFT: #d9d300 1px solid; COLOR: #fff; PADDING-TOP: 2px; BORDER-BOTTOM: #d9d300 1px solid; mso-para-margin-bottom:0.0000gd;text-align:left;">} .yellow SPAN.disabled { BORDER-RIGHT: #eee 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #eee 1px solid; PADDING-LEFT: 5px; PADDING-BOTTOM: 2px; MARGIN: 2px; BORDER-LEFT: #eee 1px solid; COLOR: #ddd; PADDING-TOP: 2px; BORDER-BOTTOM: #eee 1px solid } /*CSS jogger style pagination*/ .jogger { PADDING-RIGHT: 2px; PADDING-LEFT: 2px; PADDING-BOTTOM: 2px; MARGIN: 7px; PADDING-TOP: 2px; FONT-FAMILY: "Lucida Sans Unicode", "Lucida Grande", LucidaGrande, "Lucida Sans", Geneva, Verdana, sans-serif;TEXT-ALIGN: center; } .jogger A { PADDING-RIGHT: 0.64em; PADDING-LEFT: 0.64em; PADDING-BOTTOM: 0.43em; MARGIN: 2px; COLOR: #fff; PADDING-TOP: 0.5em; TEXT-DECORATION: none } .jogger A:hover { PADDING-RIGHT: 0.64em; PADDING-LEFT: 0.64em; PADDING-BOTTOM: 0.43em; MARGIN: 2px; COLOR: #fff; PADDING-TOP: 0.5em; mso-para-margin-bottom:0.0000gd;text-align:left;">} .jogger A:active { PADDING-RIGHT: 0.64em; PADDING-LEFT: 0.64em; PADDING-BOTTOM: 0.43em; MARGIN: 2px; COLOR: #fff; PADDING-TOP: 0.5em; mso-para-margin-bottom:0.0000gd;text-align:left;">} .jogger SPAN.current { PADDING-RIGHT: 0.64em; PADDING-LEFT: 0.64em; PADDING-BOTTOM: 0.43em; MARGIN: 2px; COLOR: #6d643c; PADDING-TOP: 0.5em; mso-para-margin-bottom:0.0000gd;text-align:left;">} .jogger SPAN.disabled { DISPLAY: none } /*CSS starcraft2 style pagination*/ .starcraft2 { PADDING-RIGHT: 3px; PADDING-LEFT: 3px; FONT-WEIGHT: bold; FONT-SIZE: 13.5pt; PADDING-BOTTOM: 3px; MARGIN: 3px; COLOR: #fff; PADDING-TOP: 3px; FONT-FAMILY: Arial; TEXT-ALIGN: center } .starcraft2 A { MARGIN: 2px; COLOR: #fa0; TEXT-DECORATION: none } .starcraft2 A:hover { COLOR: #fff; mso-para-margin-bottom:0.0000gd;text-align:left;">} .starcraft2 A:active { COLOR: #fff; mso-para-margin-bottom:0.0000gd;text-align:left;">} .starcraft2 SPAN.current { FONT-WEIGHT: bold; MARGIN: 2px; COLOR: #fff; mso-para-margin-bottom:0.0000gd;text-align:left;">} .starcraft2 SPAN.disabled { MARGIN: 2px; COLOR: #444; mso-para-margin-bottom:0.0000gd;text-align:left;">} /*CSS tres style pagination*/ .tres { PADDING-RIGHT: 7px; PADDING-LEFT: 7px; FONT-WEIGHT: bold; FONT-SIZE: 13.2pt; PADDING-BOTTOM: 7px; MARGIN: 3px; PADDING-TOP: 7px; FONT-FAMILY: Arial, Helvetica, sans-serif; TEXT-ALIGN: center } .tres A { BORDER-RIGHT: #d9d300 2px solid; PADDING-RIGHT: 5px; BORDER-TOP: #d9d300 2px solid; PADDING-LEFT: 5px; PADDING-BOTTOM: 2px; MARGIN: 2px; BORDER-LEFT: #d9d300 2px solid; COLOR: #fff; PADDING-TOP: 2px; BORDER-BOTTOM: #d9d300 2px solid; TEXT-DECORATION: none } .tres A:hover { BORDER-RIGHT: #ff0 2px solid; BORDER-TOP: #ff0 2px solid; BORDER-LEFT: #ff0 2px solid; COLOR: #000; BORDER-BOTTOM: #ff0 2px solid; mso-para-margin-bottom:0.0000gd;text-align:left;">} .tres A:active { BORDER-RIGHT: #ff0 2px solid; BORDER-TOP: #ff0 2px solid; BORDER-LEFT: #ff0 2px solid; COLOR: #000; BORDER-BOTTOM: #ff0 2px solid; mso-para-margin-bottom:0.0000gd;text-align:left;">} .tres SPAN.current { BORDER-RIGHT: #fff 2px solid; PADDING-RIGHT: 5px; BORDER-TOP: #fff 2px solid; PADDING-LEFT: 5px; FONT-WEIGHT: bold; PADDING-BOTTOM: 2px; MARGIN: 2px; BORDER-LEFT: #fff 2px solid; COLOR: #000; PADDING-TOP: 2px; BORDER-BOTTOM: #fff 2px solid } .tres SPAN.disabled { DISPLAY: none } /*CSS megas512 style pagination*/ .megas512 { PADDING-RIGHT: 3px; PADDING-LEFT: 3px; PADDING-BOTTOM: 3px; MARGIN: 3px; PADDING-TOP: 3px; TEXT-ALIGN: center } .megas512 A { BORDER-RIGHT: #dedfde 1px solid; PADDING-RIGHT: 6px; BACKGROUND-POSITION: 50% bottom; BORDER-TOP: #dedfde 1px solid; PADDING-LEFT: 6px; PADDING-BOTTOM: 2px; BORDER-LEFT: #dedfde 1px solid; COLOR: #99210b; MARGIN-RIGHT: 3px; PADDING-TOP: 2px; BORDER-BOTTOM: #dedfde 1px solid; TEXT-DECORATION: none } .megas512 A:hover { BORDER-RIGHT: #000 1px solid; BORDER-TOP: #000 1px solid; BACKGROUND-IMAGE: none; BORDER-LEFT: #000 1px solid; COLOR: #fff; BORDER-BOTTOM: #000 1px solid; mso-para-margin-bottom:0.0000gd;text-align:left;">} .megas512 A:active { BORDER-RIGHT: #000 1px solid; BORDER-TOP: #000 1px solid; BACKGROUND-IMAGE: none; BORDER-LEFT: #000 1px solid; COLOR: #fff; BORDER-BOTTOM: #000 1px solid; mso-para-margin-bottom:0.0000gd;text-align:left;">} .megas512 SPAN.current { PADDING-RIGHT: 6px; PADDING-LEFT: 6px; FONT-WEIGHT: bold; PADDING-BOTTOM: 2px; COLOR: #99210b; MARGIN-RIGHT: 3px; PADDING-TOP: 2px } .megas512 SPAN.disabled { PADDING-RIGHT: 6px; PADDING-LEFT: 6px; PADDING-BOTTOM: 2px; COLOR: #adaaad; MARGIN-RIGHT: 3px; PADDING-TOP: 2px } /*CSS technorati style pagination*/ .technorati { PADDING-RIGHT: 3px; PADDING-LEFT: 3px; PADDING-BOTTOM: 3px; MARGIN: 3px; PADDING-TOP: 3px; TEXT-ALIGN: center } .technorati A { BORDER-RIGHT: #ccc 1px solid; PADDING-RIGHT: 6px; BACKGROUND-POSITION: 50% bottom; BORDER-TOP: #ccc 1px solid; PADDING-LEFT: 6px; FONT-WEIGHT: bold; PADDING-BOTTOM: 2px; BORDER-LEFT: #ccc 1px solid; COLOR: rgb(66,97,222); MARGIN-RIGHT: 3px; PADDING-TOP: 2px; BORDER-BOTTOM: #ccc 1px solid; TEXT-DECORATION: none } .technorati A:hover { BACKGROUND-IMAGE: none; COLOR: #fff; mso-para-margin-bottom:0.0000gd;text-align:left;">} .technorati A:active { BACKGROUND-IMAGE: none; COLOR: #fff; mso-para-margin-bottom:0.0000gd;text-align:left;">} .technorati SPAN.current { PADDING-RIGHT: 6px; PADDING-LEFT: 6px; FONT-WEIGHT: bold; PADDING-BOTTOM: 2px; COLOR: #000; MARGIN-RIGHT: 3px; PADDING-TOP: 2px } .technorati SPAN.disabled { DISPLAY: none } /*CSS youtube style pagination*/ .youtube { PADDING-RIGHT: 6px; BORDER-TOP: #9c9a9c 1px dotted; PADDING-LEFT: 0px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; COLOR: #313031; PADDING-TOP: 4px; FONT-FAMILY: Arial, Helvetica, sans-serif; TEXT-ALIGN: center; } .youtube A { PADDING-RIGHT: 3px; PADDING-LEFT: 3px; FONT-WEIGHT: bold; PADDING-BOTTOM: 1px; MARGIN: 0px 1px; COLOR: #0030ce; PADDING-TOP: 1px; TEXT-DECORATION: underline } .youtube A:hover { } .youtube A:active { } .youtube SPAN.current { PADDING-RIGHT: 2px; PADDING-LEFT: 2px; PADDING-BOTTOM: 1px; COLOR: #000; PADDING-TOP: 1px; mso-para-margin-bottom:0.0000gd;text-align:left;">} .youtube SPAN.disabled { DISPLAY: none } /*CSS msdn style pagination*/ .msdn { PADDING-RIGHT: 6px; PADDING-LEFT: 0px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; COLOR: #313031; PADDING-TOP: 4px; FONT-FAMILY: Verdana,Tahoma,Arial,Helvetica,Sans-Serif; TEXT-ALIGN: right } .msdn A { BORDER-RIGHT: #b7d8ee 1px solid; PADDING-RIGHT: 6px; BORDER-TOP: #b7d8ee 1px solid; PADDING-LEFT: 5px; PADDING-BOTTOM: 4px; MARGIN: 0px 3px; BORDER-LEFT: #b7d8ee 1px solid; COLOR: #0030ce; PADDING-TOP: 5px; BORDER-BOTTOM: #b7d8ee 1px solid; TEXT-DECORATION: none } .msdn A:hover { BORDER-RIGHT: #b7d8ee 1px solid; BORDER-TOP: #b7d8ee 1px solid; BORDER-LEFT: #b7d8ee 1px solid; COLOR: #0066a7; BORDER-BOTTOM: #b7d8ee 1px solid; mso-para-margin-bottom:0.0000gd;text-align:left;">} .pagination A:active { BORDER-RIGHT: #b7d8ee 1px solid; BORDER-TOP: #b7d8ee 1px solid; BORDER-LEFT: #b7d8ee 1px solid; COLOR: #0066a7; BORDER-BOTTOM: #b7d8ee 1px solid; mso-para-margin-bottom:0.0000gd;text-align:left;">} .msdn SPAN.current { BORDER-RIGHT: #b7d8ee 1px solid; PADDING-RIGHT: 6px; BORDER-TOP: #b7d8ee 1px solid; PADDING-LEFT: 5px; FONT-WEIGHT: bold; PADDING-BOTTOM: 4px; MARGIN: 0px 3px; BORDER-LEFT: #b7d8ee 1px solid; COLOR: #444444; PADDING-TOP: 5px; BORDER-BOTTOM: #b7d8ee 1px solid; mso-para-margin-bottom:0.0000gd;text-align:left;">} .msdn SPAN.disabled { DISPLAY: none } /*CSS badoo style pagination*/ .badoo { PADDING-RIGHT: 0px; PADDING-LEFT: 0px; FONT-SIZE: 13px; PADDING-BOTTOM: 10px; COLOR: #48b9ef; PADDING-TOP: 10px; FONT-FAMILY: Arial, Helvetica, sans-serif; TEXT-ALIGN: center } .badoo A { BORDER-RIGHT: #f0f0f0 2px solid; PADDING-RIGHT: 5px; BORDER-TOP: #f0f0f0 2px solid; PADDING-LEFT: 5px; PADDING-BOTTOM: 2px; MARGIN: 0px 2px; BORDER-LEFT: #f0f0f0 2px solid; COLOR: #48b9ef; PADDING-TOP: 2px; BORDER-BOTTOM: #f0f0f0 2px solid; TEXT-DECORATION: none } .badoo A:hover { BORDER-RIGHT: #ff5a00 2px solid; BORDER-TOP: #ff5a00 2px solid; BORDER-LEFT: #ff5a00 2px solid; COLOR: #ff5a00; BORDER-BOTTOM: #ff5a00 2px solid } .badoo A:active { BORDER-RIGHT: #ff5a00 2px solid; BORDER-TOP: #ff5a00 2px solid; BORDER-LEFT: #ff5a00 2px solid; COLOR: #ff5a00; BORDER-BOTTOM: #ff5a00 2px solid } .badoo SPAN.current { BORDER-RIGHT: #ff5a00 2px solid; PADDING-RIGHT: 5px; BORDER-TOP: #ff5a00 2px solid; PADDING-LEFT: 5px; FONT-WEIGHT: bold; PADDING-BOTTOM: 2px; BORDER-LEFT: #ff5a00 2px solid; COLOR: #fff; PADDING-TOP: 2px; BORDER-BOTTOM: #ff5a00 2px solid; mso-para-margin-bottom:0.0000gd;text-align:left;">} .badoo SPAN.disabled { DISPLAY: none } /*CSS manu style pagination*/ .manu { PADDING-RIGHT: 3px; PADDING-LEFT: 3px; PADDING-BOTTOM: 3px; MARGIN: 3px; PADDING-TOP: 3px; TEXT-ALIGN: center } .manu A { BORDER-RIGHT: #eee 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #eee 1px solid; PADDING-LEFT: 5px; PADDING-BOTTOM: 2px; MARGIN: 2px; BORDER-LEFT: #eee 1px solid; COLOR: #036cb4; PADDING-TOP: 2px; BORDER-BOTTOM: #eee 1px solid; TEXT-DECORATION: none } .manu A:hover { BORDER-RIGHT: #999 1px solid; BORDER-TOP: #999 1px solid; BORDER-LEFT: #999 1px solid; COLOR: #666; BORDER-BOTTOM: #999 1px solid } .manu A:active { BORDER-RIGHT: #999 1px solid; BORDER-TOP: #999 1px solid; BORDER-LEFT: #999 1px solid; COLOR: #666; BORDER-BOTTOM: #999 1px solid } .manu .current { BORDER-RIGHT: #036cb4 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #036cb4 1px solid; PADDING-LEFT: 5px; FONT-WEIGHT: bold; PADDING-BOTTOM: 2px; MARGIN: 2px; BORDER-LEFT: #036cb4 1px solid; COLOR: #fff; PADDING-TOP: 2px; BORDER-BOTTOM: #036cb4 1px solid; mso-para-margin-bottom:0.0000gd;text-align:left;">} .manu .disabled { BORDER-RIGHT: #eee 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #eee 1px solid; PADDING-LEFT: 5px; PADDING-BOTTOM: 2px; MARGIN: 2px; BORDER-LEFT: #eee 1px solid; COLOR: #ddd; PADDING-TOP: 2px; BORDER-BOTTOM: #eee 1px solid } /*CSS green-black style pagination*/ .green-black { PADDING-RIGHT: 3px; PADDING-LEFT: 3px; PADDING-BOTTOM: 3px; MARGIN: 3px; PADDING-TOP: 3px; TEXT-ALIGN: center } .green-black A { BORDER-RIGHT: #2c2c2c 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #2c2c2c 1px solid; PADDING-LEFT: 5px; BACKGROUND: url(image1.gif) #2c2c2c; PADDING-BOTTOM: 2px; BORDER-LEFT: #2c2c2c 1px solid; COLOR: #fff; MARGIN-RIGHT: 2px; PADDING-TOP: 2px; BORDER-BOTTOM: #2c2c2c 1px solid; TEXT-DECORATION: none } .green-black A:hover { BORDER-RIGHT: #aad83e 1px solid; BORDER-TOP: #aad83e 1px solid; BACKGROUND: url(image2.gif) #aad83e; BORDER-LEFT: #aad83e 1px solid; COLOR: #fff; BORDER-BOTTOM: #aad83e 1px solid } .green-black A:active { BORDER-RIGHT: #aad83e 1px solid; BORDER-TOP: #aad83e 1px solid; BACKGROUND: url(image2.gif) #aad83e; BORDER-LEFT: #aad83e 1px solid; COLOR: #fff; BORDER-BOTTOM: #aad83e 1px solid } .green-black SPAN.current { BORDER-RIGHT: #aad83e 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #aad83e 1px solid; PADDING-LEFT: 5px; FONT-WEIGHT: bold; BACKGROUND: url(image2.gif) #aad83e; PADDING-BOTTOM: 2px; BORDER-LEFT: #aad83e 1px solid; COLOR: #fff; MARGIN-RIGHT: 2px; PADDING-TOP: 2px; BORDER-BOTTOM: #aad83e 1px solid } .green-black SPAN.disabled { BORDER-RIGHT: #f3f3f3 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #f3f3f3 1px solid; PADDING-LEFT: 5px; PADDING-BOTTOM: 2px; BORDER-LEFT: #f3f3f3 1px solid; COLOR: #ccc; MARGIN-RIGHT: 2px; PADDING-TOP: 2px; BORDER-BOTTOM: #f3f3f3 1px solid } /*CSS viciao style pagination*/ .viciao { MARGIN-TOP: 20px; MARGIN-BOTTOM: 10px } .viciao A { BORDER-RIGHT: #8db5d7 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #8db5d7 1px solid; PADDING-LEFT: 5px; PADDING-BOTTOM: 2px; BORDER-LEFT: #8db5d7 1px solid; COLOR: #000; MARGIN-RIGHT: 2px; PADDING-TOP: 2px; BORDER-BOTTOM: #8db5d7 1px solid; TEXT-DECORATION: none } .viciao A:hover { BORDER-RIGHT: red 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: red 1px solid; PADDING-LEFT: 5px; PADDING-BOTTOM: 2px; BORDER-LEFT: red 1px solid; MARGIN-RIGHT: 2px; PADDING-TOP: 2px; BORDER-BOTTOM: red 1px solid } .viciao A:active { BORDER-RIGHT: red 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: red 1px solid; PADDING-LEFT: 5px; PADDING-BOTTOM: 2px; BORDER-LEFT: red 1px solid; MARGIN-RIGHT: 2px; PADDING-TOP: 2px; BORDER-BOTTOM: red 1px solid } .viciao SPAN.current { BORDER-RIGHT: #e89954 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #e89954 1px solid; PADDING-LEFT: 5px; FONT-WEIGHT: bold; PADDING-BOTTOM: 2px; BORDER-LEFT: #e89954 1px solid; COLOR: #000; MARGIN-RIGHT: 2px; PADDING-TOP: 2px; BORDER-BOTTOM: #e89954 1px solid; mso-para-margin-bottom:0.0000gd;text-align:left;">} .viciao SPAN.disabled { BORDER-RIGHT: #ccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #ccc 1px solid; PADDING-LEFT: 5px; PADDING-BOTTOM: 2px; BORDER-LEFT: #ccc 1px solid; COLOR: #ccc; MARGIN-RIGHT: 2px; PADDING-TOP: 2px; BORDER-BOTTOM: #ccc 1px solid } /*CSS yahoo2 style pagination*/ .yahoo2 { PADDING-RIGHT: 3px; PADDING-LEFT: 3px; FONT-SIZE: 0.85em; PADDING-BOTTOM: 3px; MARGIN: 3px; PADDING-TOP: 3px; FONT-FAMILY: Tahoma,Helvetica,sans-serif; TEXT-ALIGN: center } .yahoo2 A { BORDER-RIGHT: #ccdbe4 1px solid; PADDING-RIGHT: 8px; BACKGROUND-POSITION: 50% bottom; BORDER-TOP: #ccdbe4 1px solid; PADDING-LEFT: 8px; PADDING-BOTTOM: 2px; BORDER-LEFT: #ccdbe4 1px solid; COLOR: #0061de; MARGIN-RIGHT: 3px; PADDING-TOP: 2px; BORDER-BOTTOM: #ccdbe4 1px solid; TEXT-DECORATION: none } .yahoo2 A:hover { BORDER-RIGHT: #2b55af 1px solid; BORDER-TOP: #2b55af 1px solid; BACKGROUND-IMAGE: none; BORDER-LEFT: #2b55af 1px solid; COLOR: #fff; BORDER-BOTTOM: #2b55af 1px solid; mso-para-margin-bottom:0.0000gd;text-align:left;">} .yahoo2 A:active { BORDER-RIGHT: #2b55af 1px solid; BORDER-TOP: #2b55af 1px solid; BACKGROUND-IMAGE: none; BORDER-LEFT: #2b55af 1px solid; COLOR: #fff; BORDER-BOTTOM: #2b55af 1px solid; mso-para-margin-bottom:0.0000gd;text-align:left;">} .yahoo2 SPAN.current { PADDING-RIGHT: 6px; PADDING-LEFT: 6px; FONT-WEIGHT: bold; PADDING-BOTTOM: 2px; COLOR: #000; MARGIN-RIGHT: 3px; PADDING-TOP: 2px } .yahoo2 SPAN.disabled { DISPLAY: none } .yahoo2 A.next { BORDER-RIGHT: #ccdbe4 2px solid; BORDER-TOP: #ccdbe4 2px solid; MARGIN: 0px 0px 0px 10px; BORDER-LEFT: #ccdbe4 2px solid; BORDER-BOTTOM: #ccdbe4 2px solid } .yahoo2 A.next:hover { BORDER-RIGHT: #2b55af 2px solid; BORDER-TOP: #2b55af 2px solid; BORDER-LEFT: #2b55af 2px solid; BORDER-BOTTOM: #2b55af 2px solid } .yahoo2 A.prev { BORDER-RIGHT: #ccdbe4 2px solid; BORDER-TOP: #ccdbe4 2px solid; MARGIN: 0px 10px 0px 0px; BORDER-LEFT: #ccdbe4 2px solid; BORDER-BOTTOM: #ccdbe4 2px solid } .yahoo2 A.prev:hover { BORDER-RIGHT: #2b55af 2px solid; BORDER-TOP: #2b55af 2px solid; BORDER-LEFT: #2b55af 2px solid; BORDER-BOTTOM: #2b55af 2px solid } |
添加文章实体类
package org.crdit.bean; public class Article { private String articleId; private String title; private String content; public String getArticleId() { return articleId; } public void setArticleId(String articleId) { this.articleId = articleId; } public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } public String getContent() { return content; } public void setContent(String content) { this.content = content; } } |
文章列表
listArticle.jsp <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!-- 引入c标签 --> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> <!-- 引入分页标签 --> <%@ taglib prefix="crd" uri="myPager-tag"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Insert title here</title> <!-- 引入分页样式 --> <link rel=stylesheet type=text/css href="${pageContext.request.contextPath}/css/pager.css"/> </head> <body> <center> <h2>文章列表</h2> <form action="${pageContext.request.contextPath}/listArticle.action" method="post"> 请输入查询关键字: <input type="text" name="keyword" value="${keyword}"/> <input type="submit" value="检索"/> <input type="button" value="跳转至添加文章页面" onclick="window.location = '${pageContext.request.contextPath}/addArticle.jsp'"/> </form> <c:choose> <c:when test="${empty articles}"> 未找到您想查询的记录! </c:when> <c:otherwise> <table border="1" style="width:100%;height:100%;"> <tr> <td width="20%">文章ID</td> <td width="20%">标题</td> <td width="50%">内容</td> <td width="10%">操作</td> </tr> <c:forEach items="${articles}" var="article"> <tr> <td>${article.articleId}</td> <td>${article.title}</td> <td>${article.content}</td> <td> <a href="${pageContext.request.contextPath}/deleteArticle.action?articleId=${article.articleId}"> 删除 </a> <a href="${pageContext.request.contextPath}/showUpdateArticle.action?articleId=${article.articleId}"> 更新 </a> </td> </tr> </c:forEach> </table> <!-- crd:标签前缀 pager:标签名字,在tld文件中指定 pageIndex(当前页码)、totalNum(总记录数)、pageSize(每页显示的记录)、submitUrl(提交地址)标签属性 --> <crd:pager pageIndex="${pageIndex}" totalNum="${totalNum}" pageSize="2" submitUrl="listArticle.action?pageIndex={0}&keyword=${keyword}" pageStyle="yellow"> </crd:pager> </c:otherwise> </c:choose> </center> </body> </html> |
ListServlet.java package org.crdit.action; import java.io.IOException; import java.nio.file.Paths; import java.util.ArrayList; import java.util.List; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.analysis.cn.smart.SmartChineseAnalyzer; import org.apache.lucene.document.Document; import org.apache.lucene.index.DirectoryReader; import org.apache.lucene.index.IndexReader; import org.apache.lucene.queryparser.classic.MultiFieldQueryParser; import org.apache.lucene.queryparser.classic.QueryParser; import org.apache.lucene.search.IndexSearcher; import org.apache.lucene.search.Query; import org.apache.lucene.search.ScoreDoc; import org.apache.lucene.search.TopDocs; import org.apache.lucene.search.highlight.Formatter; import org.apache.lucene.search.highlight.Fragmenter; import org.apache.lucene.search.highlight.Highlighter; import org.apache.lucene.search.highlight.QueryScorer; import org.apache.lucene.search.highlight.Scorer; import org.apache.lucene.search.highlight.SimpleFragmenter; import org.apache.lucene.search.highlight.SimpleHTMLFormatter; import org.apache.lucene.store.Directory; import org.apache.lucene.store.FSDirectory; import org.crdit.bean.Article; /** * Servlet implementation class ListServlet * 文章信息分页查询,并且达到高亮显示 */ @WebServlet("/listArticle.action") public class ListServlet extends HttpServlet { private static final long serialVersionUID = 1L; /** * @see HttpServlet#HttpServlet() */ public ListServlet() { super(); // TODO Auto-generated constructor stub } @Override protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try { //通过request设置请求编码信息,防止中文乱码 request.setCharacterEncoding("utf-8"); //获取用户输入的关键字 String keyword=request.getParameter("keyword"); request.setAttribute("keyword",keyword); String pageIndex=request.getParameter("pageIndex"); if(pageIndex==null || pageIndex.equals("")){ pageIndex="1"; } request.setAttribute("pageIndex", pageIndex); int pageSize=2; //指定索引所在目录 Directory directory=FSDirectory.open(Paths.get("E:\\Lucene\\Lucene_db\\artical_tb")); //DirectoryReader的open方法指定需要读取的索引库信息,并返回相应的实例 IndexReader indexReader=DirectoryReader.open(directory); //创建IndexSearcher实例,通过IndexSearcher实例进行全文检索 IndexSearcher indexSearcher = new IndexSearcher(indexReader); //词库分词 需要导jar包 lucene-analyzers-smartcn.jar Analyzer analyzer = new SmartChineseAnalyzer(); //创建QueryParser实例 通过MultiFieldQueryParser可以指定需要查询的多个字段以及分词器信息 QueryParser queryParser=new MultiFieldQueryParser((keyword==null||keyword.equals(""))?new String[]{"allArticle"}:new String[]{"title","content"}, analyzer); //通过queryParser实例得到query实例,并指定查询的关键字 Query query =queryParser.parse((keyword==null||keyword.equals(""))?"@allArticle":keyword); //通过格式器指定咋样对关键字进行处理 Formatter formatter=new SimpleHTMLFormatter("<font color='red'>", "</font>"); //通过Scorer包装query Scorer fragmentScorer=new QueryScorer(query); //创建高亮器 Highlighter highlighter=new Highlighter(formatter, fragmentScorer); //创建格式化片段 Fragmenter fragmenter=new SimpleFragmenter(10); //将格式化片段实例与高亮器关联,最终通过高亮器对文本信息进行处理 highlighter.setTextFragmenter(fragmenter); /*通过indexSearch进行检索,并指定两个参数 *第一个参数:封装查询的相关信息,比如查询的关键字、分词器,是否需要分词,或者需要分词的话,采取什么分词器 *第二个参数:最多只要多少条记录 * *查询数据,最终都封装在TopDocs的实例中 */ TopDocs topDocs=indexSearcher.search(query, 100); //通过topDocs获取匹配全部记录 ScoreDoc[] scoreDocs=topDocs.scoreDocs; //将总记录数存放在request中,便于页面中实现分页 int totalNum=scoreDocs.length; request.setAttribute("totalNum", totalNum); //定义查询的起始记录号以及结束的记录号 int startSize=(Integer.valueOf(pageIndex)-1)*pageSize; int endSize=Integer.valueOf(pageIndex)*pageSize>scoreDocs.length?scoreDocs.length:Integer.valueOf(pageIndex)*pageSize; //创建集合用于存储所有的文章信息 List<Article> articles= new ArrayList<>(); for (int i = startSize; i < endSize; i++) { //获取记录的id int id=scoreDocs[i].doc; //获取文章得分 float score=scoreDocs[i].score; Document document=indexSearcher.doc(id); String articleId= document.get("articleId"); String title= document.get("title"); String content= document.get("content"); String postTitle=highlighter.getBestFragment(analyzer, "title", title); String postContent=highlighter.getBestFragment(analyzer, "content", content); //创建Article 对象封装文章相关信息, Article article=new Article(); article.setArticleId(articleId); article.setTitle(postTitle==null?title:postTitle); article.setContent(postContent==null?content.length()<=20?content:content.substring(0,20)+"...":postContent); //将文章实例存放到集合中 articles.add(article); } //将集合存放到request中 request.setAttribute("articles", articles); } catch (Exception e) { e.printStackTrace(); } //跳转至列表页面 request.getRequestDispatcher("/listArticle.jsp").forward(request, response); } } |
更新文章
ShowUpdateServlet.java package org.crdit.action; import java.io.IOException; import java.nio.file.Paths; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.analysis.cn.smart.SmartChineseAnalyzer; import org.apache.lucene.document.Document; import org.apache.lucene.index.DirectoryReader; import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.Term; import org.apache.lucene.queryparser.classic.QueryParser; import org.apache.lucene.search.IndexSearcher; import org.apache.lucene.search.Query; import org.apache.lucene.search.ScoreDoc; import org.apache.lucene.search.TermQuery; import org.apache.lucene.search.TopDocs; import org.apache.lucene.store.Directory; import org.apache.lucene.store.FSDirectory; import org.crdit.bean.Article; /** * Servlet implementation class UpdateServlet * 跳转至更新文章页面 */ @WebServlet("/showUpdateArticle.action") public class ShowUpdateServlet extends HttpServlet { private static final long serialVersionUID = 1L; /** * @see HttpServlet#HttpServlet() */ public ShowUpdateServlet() { super(); // TODO Auto-generated constructor stub } /** * @see HttpServlet#service(HttpServletRequest request, HttpServletResponse response) */ protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub //获取文字id String articleId=request.getParameter("articleId"); //指定索引所在目录 Directory directory=FSDirectory.open(Paths.get("E:\\Lucene\\Lucene_db\\artical_tb")); //DirectoryReader的open方法指定需要读取的索引库信息,并返回相应的实例 IndexReader indexReader=DirectoryReader.open(directory); //创建IndexSearcher实例,通过IndexSearcher实例进行全文检索 IndexSearcher indexSearcher = new IndexSearcher(indexReader); TermQuery query=new TermQuery(new Term("articleId",articleId)); /*通过indexSearch进行检索,并指定两个参数 *第一个参数:封装查询的相关信息,比如查询的关键字、分词器,是否需要分词,或者需要分词的话,采取什么分词器 *第二个参数:最多只要多少条记录 * *查询数据,最终都封装在TopDocs的实例中 */ TopDocs topDocs=indexSearcher.search(query, 1); //通过topDocs获取匹配全部记录 ScoreDoc[] scoreDocs=topDocs.scoreDocs; ScoreDoc scoreDoc=scoreDocs[0]; //获取记录的id int id=scoreDoc.doc; //获取文章得分 float score=scoreDoc.score; Document document=indexSearcher.doc(id); String title= document.get("title"); String content= document.get("content"); //创建Article实例,封装文章相关信息 Article article=new Article(); article.setArticleId(articleId); article.setTitle(title); article.setContent(content); request.setAttribute("article", article); //跳转至更新文章页面 request.getRequestDispatcher("/updateArticle.jsp").forward(request, response);; } } |
updateArticle.jsp <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>更新文章</title> </head> <body> <center> <h2>更新文章</h2> <form action="${pageContext.request.contextPath}/updateArticle.action" method="post"> <input type="hidden" name="articleId" value="${article.articleId}"> <table> <tr> <td>文章标题</td> <td> <input type="text" name="title" value="${article.title}"/> </td> </tr> <tr> <td>文章内容</td> <td> <textarea rows="20" cols="20" name="content" > ${article.content} </textarea> </td> </tr> <tr> <td><input type="submit" value="更新"></td> <td> <input type="button" value="跳转至列表页面" onclick="window.location = '${pageContext.request.contextPath}/listArticle.jsp'"> </td> </tr> </table> </form> </center> </body> </html> |
UpdateServlet.java package org.crdit.action; import java.io.IOException; import java.nio.file.Paths; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.analysis.cn.smart.SmartChineseAnalyzer; import org.apache.lucene.document.Document; import org.apache.lucene.document.StringField; import org.apache.lucene.document.TextField; import org.apache.lucene.document.Field.Store; import org.apache.lucene.index.IndexWriter; import org.apache.lucene.index.IndexWriterConfig; import org.apache.lucene.index.Term; import org.apache.lucene.index.IndexWriterConfig.OpenMode; import org.apache.lucene.store.Directory; import org.apache.lucene.store.FSDirectory; /** * Servlet implementation class UpdateServlet * 更新文章 */ @WebServlet("/updateArticle.action") public class UpdateServlet extends HttpServlet { private static final long serialVersionUID = 1L; /** * @see HttpServlet#HttpServlet() */ public UpdateServlet() { super(); // TODO Auto-generated constructor stub } /** * @see HttpServlet#service(HttpServletRequest request, HttpServletResponse response) */ protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try { //设置编码,以防中文乱码 request.setCharacterEncoding("utf-8"); //获取文章信息(id title content) String articleId=request.getParameter("articleId"); String title=request.getParameter("title"); String content=request.getParameter("content"); //指定索引所在目录 Directory directory=FSDirectory.open(Paths.get("E:\\Lucene\\Lucene_db\\artical_tb")); //词库分词 需要导jar包 lucene-analyzers-smartcn.jar Analyzer analyzer = new SmartChineseAnalyzer(); //创建IndexWriterConfig实例 指定添加索引的配置信息 IndexWriterConfig config=new IndexWriterConfig(analyzer); //如果索引不存在,则创建。存在,则追加。 config.setOpenMode(OpenMode.CREATE_OR_APPEND); //创建IndexWriter IndexWriter indexWriter=new IndexWriter(directory, config); //往索引库中添加记录 Lucene中一个document实例代表数据表中的一条记录 Document document=new Document(); /* *StringFiled:不会对关键字进行分词 *TextFiled:会对关键字进行分词 * * Store.YES:会将数据进行存储并分词 * Store.NO:不会将数据进行存储,不会分词,索引还是会创建。有索引,没有内容。 */ document.add(new StringField("articleId", articleId, Store.YES)); document.add(new TextField("title", title, Store.YES)); document.add(new TextField("content", content, Store.YES)); document.add(new TextField("allArticle", "@allArticle", Store.YES)); //更新的原理:先删除之前的索引,再创建新的索引====删除与添加两个动作的合集 indexWriter.updateDocument(new Term("articleId",articleId), document); //提交事务 indexWriter.commit(); //关闭事务 indexWriter.close(); System.out.println("更新成功"); } catch (Exception e) { e.printStackTrace(); } //跳转至列表页面 request.getRequestDispatcher("/listArticle.jsp").forward(request, response); } } |
删除文章
DeleteServlet.java package org.crdit.action; import java.io.IOException; import java.nio.file.Paths; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.analysis.cn.smart.SmartChineseAnalyzer; import org.apache.lucene.index.IndexWriter; import org.apache.lucene.index.IndexWriterConfig; import org.apache.lucene.index.Term; import org.apache.lucene.index.IndexWriterConfig.OpenMode; import org.apache.lucene.store.Directory; import org.apache.lucene.store.FSDirectory; /** * Servlet implementation class DeleteServlet */ @WebServlet("/deleteArticle.action") public class DeleteServlet extends HttpServlet { private static final long serialVersionUID = 1L; /** * @see HttpServlet#HttpServlet() */ public DeleteServlet() { super(); // TODO Auto-generated constructor stub } /** * @see HttpServlet#service(HttpServletRequest request, HttpServletResponse response) */ protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try { //获取articleId String articleId=request.getParameter("articleId"); //指定索引所在目录 Directory directory=FSDirectory.open(Paths.get("E:\\Lucene\\Lucene_db\\artical_tb")); //词库分词 需要导jar包 lucene-analyzers-smartcn.jar Analyzer analyzer = new SmartChineseAnalyzer(); //创建IndexWriterConfig实例 指定添加索引的配置信息 IndexWriterConfig config=new IndexWriterConfig(analyzer); //如果索引不存在,则创建。存在,则追加。 config.setOpenMode(OpenMode.CREATE_OR_APPEND); //创建IndexWriter IndexWriter indexWriter=new IndexWriter(directory, config); //删除索引库中指定的索引 indexWriter.deleteDocuments(new Term("articleId",articleId)); //删除索引库中全部的索引 //indexWriter.deleteAll(); //提交事务 indexWriter.commit(); //关闭事务 indexWriter.close(); System.out.println("删除成功"); } catch (Exception e) { e.printStackTrace(); } //跳转至添加文章页面 request.getRequestDispatcher("/listArticle.jsp").forward(request, response);; } } |
项目地址:Lucene\code\03
Lucene实战的更多相关文章
- Lucene实战(第2版)》
<Lucene实战(第2版)>基于Apache的Lucene 3.0,从Lucene核心.Lucene应用.案例分析3个方面详细系统地介绍了Lucene,包括认识Lucene.建立索引.为 ...
- 3.2 Lucene实战:一个简单的小程序
在讲解Lucene索引和检索的原理之前,我们先来实战Lucene:一个简单的小程序! 一.索引小程序 首先,new一个java project,名字叫做LuceneIndex. 然后,在project ...
- Lucene实战构建索引
搭建lucene的步骤这里就不详细介绍了,无外乎就是下载相关jar包,在eclipse中新建java工程,引入相关的jar包即可 本文主要在没有剖析lucene的源码之前实战一下,通过实战来促进研究 ...
- 《Lucene实战(第2版)》 配书代码在IDEA下的编译方法
参考: hankcs http://www.hankcs.com/program/java/lucene-combat-2nd-edition-book-with-code-compiled-unde ...
- lucene实战(第二版)学习笔记
初识Lucene 构建索引 为应用程序添加搜索功能 Lucene的分析过程
- Lucene实战之初体验
前言 最早做非结构化数据搜索时用的还是lucene.net,一直说在学习java的同时把lucene这块搞一搞,这拖了2年多了,终于开始搞这块了. 开发环境 idea2016.lucene6.0.jd ...
- lucene实战--打分算法没有那么难!
作为一个开放源代码项目,Lucene从问世之后,引发了开放源代码社群的巨大反响,程序员们不仅使用它构建具体的全文检索应用,而且将之集成到各种系统软件中去,以及构建Web应用,甚至某些商业软件也采用了L ...
- Lucene实战之基于StandardAnalyzer读写索引
前言 使用lucene创建索引时如果指定了解析器,则需要读写都使用这个解析器,目前我发现也就是在处理中文这块比较麻烦,像你在使用solr时如果配置了ik分词,则需要把index清空重新创建才能继续搜索 ...
- Lucene实战之关键字匹配多个字段
前言 当我们输入关键字时希望可以支持筛选多个字段,这样搜索内容的覆盖率就会大一些. 匹配多个字段主要用 MultiFieldQueryParser类. 单一字段搜索 QueryParser parse ...
随机推荐
- List转为DataTable并可以导出为Excel
using com.jd120.Core.Utility; using System; using System.Collections.Generic; using System.Data; usi ...
- Hibernate课程 初探多对多映射2-4 测试
package com.ddwei.test; import org.hibernate.Session; import org.hibernate.Transaction; import com.d ...
- 账户密码提示 jq简单事件
$(".username").focus(function(){ if($(this).val()=="请输入用户名"){ $(this).val(" ...
- 什么是MongoDb
MongoDB是一个介于关系数据库和非关系数据库之间的产品,是非关系数据库当中功能最丰富,最像关系数据库的.他支持的数据结构非常松散,是类似json的bson格式,因此可以存储比较复杂的数据类型.Mo ...
- laravel的nginx配置
最近阅读laravel官方文档 发现了关于nginx的推荐配置 Nginx 如果你使用 Nginx ,在你的网站配置中加入下述代码将会转发所有的请求到 index.php 前端控制器. locatio ...
- three.js学习笔记--基础知识
基础知识 从去年开始就在计划中的three.js终于开始了 历史介绍 (摘自ijunfan1994的转载,感谢作者) OpenGL大概许多人都有所耳闻,它是最常用的跨平台图形库. WebGL是基于Op ...
- django orm 多对多自定义第三张表
# -*- coding: utf-8 -*-# Generated by Django 1.11.11 on 2018-09-02 08:07from __future__ import unico ...
- 自定义 Firefox TLS支持版本s
如果目前正在运行火狐26,你可能已经注意到,浏览器仅支持SSL 3.0和TLS 1.0,默认不开启TLS 1.1或TLS 1.2.另外我们知道Firefox 27 已经实现了对TLS 1.2的支持. ...
- Scikit Learn
Scikit Learn Scikit-Learn简称sklearn,基于 Python 语言的,简单高效的数据挖掘和数据分析工具,建立在 NumPy,SciPy 和 matplotlib 上.
- Jmeter入门6 参数化—CSV Data Set Config 通过文件导入数据
线程组循环次数大于1的时候,请求里每次提交的数据都相同.有的系统限制了不能提交相同数据,我们通过 CSV Data Set Config 加载csv文件数据. 1 创建一个文本文件,输入参数值保存为. ...