Solr开发文档
fmms
13年前
<p>Solr 是一种可供企业使用的、基于 Lucene 的搜索服务器,它支持层面搜索、命中醒目显示和多种输出格式。在这篇文章中,将介绍 Solr 并展示如何轻松地将其表现优异的全文本搜索功能加入到 Web 应用程序中。 </p> <p>开发环境: </p> <p>System:Windows </p> <p>WebBrowser:IE6+、Firefox3+ </p> <p>JDK:1.6+ </p> <p>JavaEE Server:tomcat5.0.2.8、tomcat6 </p> <p>IDE:eclipse、MyEclipse 8 </p> <p> </p> <p>开发依赖库: </p> <p>JavaEE 5、solr 3.4 </p> <h4>一、配置和安装solr</h4> <p>1、 首先去apache项目主页下载solr,下载地址 </p> <p><a href="/misc/goto?guid=4959517664371187663">http://labs.renren.com/apache-mirror//lucene/solr/3.4.0/</a> </p> <p>目前最新的是3.4的版本 </p> <p> </p> <p>2、 下载后解压目录如下 </p> <p><a href="https://simg.open-open.com/show/97b244fde354c31b62cc6a90e63ea78d.jpg"><img style="border-right-width:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;" title="clip_image002" border="0" alt="Solr开发文档" src="https://simg.open-open.com/show/d9fbcad16dee49c23c328fe850999913.jpg" width="95" height="158" /></a> </p> <p>client是一个ruby实现的示例,这个我们暂时不管 </p> <p>contrib有一些功能模块是需要的jar包 </p> <p>dist是打包发布好的工程war包 </p> <p>docs是帮助文档 </p> <p>example是示例,里面有打包部署好的solr工程示例和servlet容器jetty。如果你没有tomcat可以直接使用Jetty服务器部署你的solr示例。 </p> <p> </p> <p>3、 发布、部署solr示例 </p> <p>A、 利用自带的Jetty服务器 </p> <p>首先在dos命令中进入到下载好的solr解压的目录apache-solr-3.4.0的example目录 </p> <p>cd E:\JAR\solr\apache-solr-3.4.0\example </p> <p>然后利用java命令,启动jetty服务器。Java –jar start.jar </p> <p><a href="https://simg.open-open.com/show/e62c92438e585376f2d6ff61f4141ab0.jpg"><img style="border-right-width:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;" title="clip_image004" border="0" alt="Solr开发文档" src="https://simg.open-open.com/show/7ae211ccd31cd6bcd1600e8a24a4d41e.jpg" width="244" height="51" /></a> </p> <p>启动Jetty成功后,如果没有看到错误消息,你可以看到端口信息。 </p> <p><a href="https://simg.open-open.com/show/0c1402d19fe6d857edc16e7d7bbb9c60.jpg"><img style="border-right-width:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;" title="clip_image006" border="0" alt="Solr开发文档" src="https://simg.open-open.com/show/83fee3f523bb73a7ba2f520d7b48669f.jpg" width="244" height="25" /></a> </p> <p>如果你的端口冲突了,你可以到解压的solr示例包的example/etc的jetty.xml中,修改端口port信息。 </p> <p><Set name="port"> </p> <p><SystemProperty name="jetty.port" default="8983"/> </p> <p></Set> </p> <p> </p> <p>B、 利用tomcat发布solr示例 </p> <p>将下载的solr解压后,进入apache-solr-3.4.0\dist目录,将里面的solr.war放到D:\tomcat-6.0.28\webapps目录下,启动tomcat会自动解压。(当然,你也可以手动解压放到wabapps目录下) </p> <p>当然你也可以设置context指向你的solr工程,在D:\tomcat-6.0.28\conf\Catalina\localhost目录加入solr.xml配置,配置如下: </p> <div id="codeSnippetWrapper"> <div style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;" id="codeSnippet"> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;"><</span><span style="color:#800000;">Context</span> <span style="color:#ff0000;">docBase</span><span style="color:#0000ff;">="D:\solr.war"</span> <span style="color:#ff0000;">debug</span><span style="color:#0000ff;">="0"</span> <span style="color:#ff0000;">crossContext</span><span style="color:#0000ff;">="true"</span> <span style="color:#0000ff;">></span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#0000ff;"><</span><span style="color:#800000;">Environment</span> <span style="color:#ff0000;">name</span><span style="color:#0000ff;">="solr/home"</span> <span style="color:#ff0000;">type</span><span style="color:#0000ff;">="java.lang.String"</span> <span style="color:#ff0000;">value</span><span style="color:#0000ff;">="D:\solr"</span> <span style="color:#ff0000;">override</span><span style="color:#0000ff;">="true"</span> <span style="color:#0000ff;">/></span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;"></</span><span style="color:#800000;">Context</span><span style="color:#0000ff;">></span></pre> </div> </div> <p>上面的2步都是一样的,这样还没有完。启动后你可能会看到如下错误: </p> <p><a href="https://simg.open-open.com/show/7c2fe499d480fe513fac08919f3d84ef.jpg"><img title="201110211623517090.jpg" border="0" alt="201110211623517090.jpg" src="https://simg.open-open.com/show/ed11b62f771421b360dd2ed10ade8d8c.jpg" width="244" height="23" /></a> </p> <p>我们需要将一些配置和index库文件也放到解压好的solr工程下。我们到解压的apache-solr-3.4.0\example \solr目录下,将里面的conf和data目录copy到刚才我们部署的D:\tomcat-6.0.28\webapps\solr工程目录下。或是copy到你的solr.xml中的context指定的路径下工程目录中。 </p> <p>重启tomcat就ok了。 </p> <p> </p> <p>4、 这个时候你就可以访问<a href="/misc/goto?guid=4959517664508746622">http://localhost:8983/solr/admin/</a>你就可以看到如下界面: </p> <p><a href="https://simg.open-open.com/show/865fd22177b02878ac0d86a4384a0f6a.jpg"><img title="20111021162407344.jpg" border="0" alt="20111021162407344.jpg" src="https://simg.open-open.com/show/787acf0b1f4eb6fa5dad92337d138b10.jpg" width="244" height="163" /></a> </p> <p>在Query String中输入solr,点击Search就可以查询到相应的结果,结果以xml形式返回。当然你也可以设置返回数据类型为json。 </p> <p>在Query String中输入solr,点击Search就可以查询到相应的结果,结果以xml形式返回。当然你也可以设置返回数据类型为json。 </p> <div id="codeSnippetWrapper"> <div style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;" id="codeSnippet"> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;"><?</span><span style="color:#800000;">xml</span> <span style="color:#ff0000;">version</span><span style="color:#0000ff;">="1.0"</span> <span style="color:#ff0000;">encoding</span><span style="color:#0000ff;">="UTF-8"</span>?<span style="color:#0000ff;">></span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;"><</span><span style="color:#800000;">response</span><span style="color:#0000ff;">></span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;"><</span><span style="color:#800000;">lst</span> <span style="color:#ff0000;">name</span><span style="color:#0000ff;">="responseHeader"</span><span style="color:#0000ff;">></span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#0000ff;"><</span><span style="color:#800000;">int</span> <span style="color:#ff0000;">name</span><span style="color:#0000ff;">="status"</span><span style="color:#0000ff;">></span>0<span style="color:#0000ff;"></</span><span style="color:#800000;">int</span><span style="color:#0000ff;">></span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#0000ff;"><</span><span style="color:#800000;">int</span> <span style="color:#ff0000;">name</span><span style="color:#0000ff;">="QTime"</span><span style="color:#0000ff;">></span>0<span style="color:#0000ff;"></</span><span style="color:#800000;">int</span><span style="color:#0000ff;">></span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#0000ff;"><</span><span style="color:#800000;">lst</span> <span style="color:#ff0000;">name</span><span style="color:#0000ff;">="params"</span><span style="color:#0000ff;">></span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#0000ff;"><</span><span style="color:#800000;">str</span> <span style="color:#ff0000;">name</span><span style="color:#0000ff;">="indent"</span><span style="color:#0000ff;">></span>on<span style="color:#0000ff;"></</span><span style="color:#800000;">str</span><span style="color:#0000ff;">></span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#0000ff;"><</span><span style="color:#800000;">str</span> <span style="color:#ff0000;">name</span><span style="color:#0000ff;">="start"</span><span style="color:#0000ff;">></span>0<span style="color:#0000ff;"></</span><span style="color:#800000;">str</span><span style="color:#0000ff;">></span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#0000ff;"><</span><span style="color:#800000;">str</span> <span style="color:#ff0000;">name</span><span style="color:#0000ff;">="q"</span><span style="color:#0000ff;">></span>solr<span style="color:#0000ff;"></</span><span style="color:#800000;">str</span><span style="color:#0000ff;">></span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#0000ff;"><</span><span style="color:#800000;">str</span> <span style="color:#ff0000;">name</span><span style="color:#0000ff;">="version"</span><span style="color:#0000ff;">></span>2.2<span style="color:#0000ff;"></</span><span style="color:#800000;">str</span><span style="color:#0000ff;">></span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#0000ff;"><</span><span style="color:#800000;">str</span> <span style="color:#ff0000;">name</span><span style="color:#0000ff;">="rows"</span><span style="color:#0000ff;">></span>10<span style="color:#0000ff;"></</span><span style="color:#800000;">str</span><span style="color:#0000ff;">></span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#0000ff;"></</span><span style="color:#800000;">lst</span><span style="color:#0000ff;">></span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;"></</span><span style="color:#800000;">lst</span><span style="color:#0000ff;">></span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;"><</span><span style="color:#800000;">result</span> <span style="color:#ff0000;">name</span><span style="color:#0000ff;">="response"</span> <span style="color:#ff0000;">numFound</span><span style="color:#0000ff;">="1"</span> <span style="color:#ff0000;">start</span><span style="color:#0000ff;">="0"</span><span style="color:#0000ff;">></span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#0000ff;"><</span><span style="color:#800000;">doc</span><span style="color:#0000ff;">></span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#0000ff;"><</span><span style="color:#800000;">arr</span> <span style="color:#ff0000;">name</span><span style="color:#0000ff;">="cat"</span><span style="color:#0000ff;">><</span><span style="color:#800000;">str</span><span style="color:#0000ff;">></span>software<span style="color:#0000ff;"></</span><span style="color:#800000;">str</span><span style="color:#0000ff;">><</span><span style="color:#800000;">str</span><span style="color:#0000ff;">></span>search<span style="color:#0000ff;"></</span><span style="color:#800000;">str</span><span style="color:#0000ff;">></</span><span style="color:#800000;">arr</span><span style="color:#0000ff;">></span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#0000ff;"><</span><span style="color:#800000;">arr</span> <span style="color:#ff0000;">name</span><span style="color:#0000ff;">="features"</span><span style="color:#0000ff;">><</span><span style="color:#800000;">str</span><span style="color:#0000ff;">></span>Advanced Full-Text Search Capabilities using Lucene<span style="color:#0000ff;"></</span><span style="color:#800000;">str</span><span style="color:#0000ff;">><</span><span style="color:#800000;">str</span><span style="color:#0000ff;">></span>Optimized for High Volume Web Traffic<span style="color:#0000ff;"></</span><span style="color:#800000;">str</span><span style="color:#0000ff;">><</span><span style="color:#800000;">str</span><span style="color:#0000ff;">></span>Standards Based Open Interfaces - XML and HTTP<span style="color:#0000ff;"></</span><span style="color:#800000;">str</span><span style="color:#0000ff;">></span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#0000ff;"><</span><span style="color:#800000;">str</span><span style="color:#0000ff;">></span>Comprehensive HTML Administration Interfaces<span style="color:#0000ff;"></</span><span style="color:#800000;">str</span><span style="color:#0000ff;">><</span><span style="color:#800000;">str</span><span style="color:#0000ff;">></span>Scalability - Efficient Replication to other Solr Search Servers<span style="color:#0000ff;"></</span><span style="color:#800000;">str</span><span style="color:#0000ff;">><</span><span style="color:#800000;">str</span><span style="color:#0000ff;">></span>Flexible and Adaptable with XML configuration and Schema<span style="color:#0000ff;"></</span><span style="color:#800000;">str</span><span style="color:#0000ff;">><</span><span style="color:#800000;">str</span><span style="color:#0000ff;">></span>Good unicode support: h¨¦llo (hello with an accent over the e)<span style="color:#0000ff;"></</span><span style="color:#800000;">str</span><span style="color:#0000ff;">></</span><span style="color:#800000;">arr</span><span style="color:#0000ff;">></span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#0000ff;"><</span><span style="color:#800000;">str</span> <span style="color:#ff0000;">name</span><span style="color:#0000ff;">="id"</span><span style="color:#0000ff;">></span>SOLR1000<span style="color:#0000ff;"></</span><span style="color:#800000;">str</span><span style="color:#0000ff;">></span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#0000ff;"><</span><span style="color:#800000;">bool</span> <span style="color:#ff0000;">name</span><span style="color:#0000ff;">="inStock"</span><span style="color:#0000ff;">></span>true<span style="color:#0000ff;"></</span><span style="color:#800000;">bool</span><span style="color:#0000ff;">></span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#0000ff;"><</span><span style="color:#800000;">date</span> <span style="color:#ff0000;">name</span><span style="color:#0000ff;">="incubationdate_dt"</span><span style="color:#0000ff;">></span>2006-01-17T00:00:00Z<span style="color:#0000ff;"></</span><span style="color:#800000;">date</span><span style="color:#0000ff;">></span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#0000ff;"><</span><span style="color:#800000;">str</span> <span style="color:#ff0000;">name</span><span style="color:#0000ff;">="manu"</span><span style="color:#0000ff;">></span>Apache Software Foundation<span style="color:#0000ff;"></</span><span style="color:#800000;">str</span><span style="color:#0000ff;">></span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#0000ff;"><</span><span style="color:#800000;">str</span> <span style="color:#ff0000;">name</span><span style="color:#0000ff;">="name"</span><span style="color:#0000ff;">></span>Solr, the Enterprise Search Server<span style="color:#0000ff;"></</span><span style="color:#800000;">str</span><span style="color:#0000ff;">></span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#0000ff;"><</span><span style="color:#800000;">int</span> <span style="color:#ff0000;">name</span><span style="color:#0000ff;">="popularity"</span><span style="color:#0000ff;">></span>10<span style="color:#0000ff;"></</span><span style="color:#800000;">int</span><span style="color:#0000ff;">></span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#0000ff;"><</span><span style="color:#800000;">float</span> <span style="color:#ff0000;">name</span><span style="color:#0000ff;">="price"</span><span style="color:#0000ff;">></span>0.0<span style="color:#0000ff;"></</span><span style="color:#800000;">float</span><span style="color:#0000ff;">></span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#0000ff;"></</span><span style="color:#800000;">doc</span><span style="color:#0000ff;">></span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;"></</span><span style="color:#800000;">result</span><span style="color:#0000ff;">></span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;"></</span><span style="color:#800000;">response</span><span style="color:#0000ff;">></span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> </pre> </div> </div> <p> </p> <h4>二、Solr理论</h4> <p>1、 solr基础 </p> <p>因为 Solr 包装并扩展了 Lucene,所以它们使用很多相同的术语。更重要的是,Solr 创建的索引与 Lucene 搜索引擎库完全兼容。通过对 Solr 进行适当的配置,某些情况下可能需要进行编码,Solr 可以阅读和使用构建到其他 Lucene 应用程序中的索引。 </p> <p>在 Solr 和 Lucene 中,使用一个或多个 Document 来构建索引。Document 包括一个或多个 Field。Field 包括名称、内容以及告诉 Solr 如何处理内容的元数据。例如,Field 可以包含字符串、数字、布尔值或者日期,也可以包含你想添加的任何类型,只需用在solr的配置文件中进行相应的配置即可。Field 可以使用大量的选项来描述,这些选项告诉 Solr 在索引和搜索期间如何处理内容。现在,查看一下表 1 中列出的重要属性的子集: </p> <table border="1" cellspacing="0" cellpadding="0"> <tbody> <tr> <td valign="top" width="102"> <p>属性名称</p> </td> <td valign="top" width="466"> <p>描述</p> </td> </tr> <tr> <td valign="top" width="102"> <p>Indexed</p> </td> <td valign="top" width="466"> <p>Indexed Field 可以进行搜索和排序。你还可以在 indexed Field 上运行 Solr 分析过程,此过程可修改内容以改进或更改结果。</p> </td> </tr> <tr> <td valign="top" width="102"> <p>Stored</p> </td> <td valign="top" width="466"> <p>stored Field 内容保存在索引中。这对于检索和醒目显示内容很有用,但对于实际搜索则不是必需的。例如,很多应用程序存储指向内容位置的指针而不是存储实际的文件内容。</p> </td> </tr> </tbody> </table> <p> </p> <p>2、 solr索引操作 </p> <p>在 Solr 中,通过向部署在 servlet 容器中的 Solr Web 应用程序发送 HTTP 请求来启动索引和搜索。Solr 接受请求,确定要使用的适当 SolrRequestHandler,然后处理请求。通过 HTTP 以同样的方式返回响应。默认配置返回 Solr 的标准 XML 响应。你也可以配置 Solr 的备用响应格式,如json、csv格式的文本。 </p> <p>索引就是接受输入元数据(数据格式在schema.xml中进行配置)并将它们传递给 Solr,从而在 HTTP Post XML 消息中进行索引的过程。你可以向 Solr 索引 servlet 传递四个不同的索引请求: </p> <p>add/update 允许您向 Solr 添加文档或更新文档。直到提交后才能搜索到这些添加和更新。 </p> <p>commit 告诉 Solr,应该使上次提交以来所做的所有更改都可以搜索到。 </p> <p>optimize 重构 Lucene 的文件以改进搜索性能。索引完成后执行一下优化通常比较好。如果更新比较频繁,则应该在使用率较低的时候安排优化。一个索引无需优化也可以正常地运行。优化是一个耗时较多的过程。 </p> <p>delete 可以通过 id 或查询来指定。按 id 删除将删除具有指定 id 的文档;按查询删除将删除查询返回的所有文档。 </p> <p>Lucene中操作索引也有这几个步骤,但是没有更新。Lucene更新是先删除,然后添加索引。因为更新索引在一定情况下,效率没有先删除后添加的效率好。 </p> <p> </p> <p>3、 搜索 </p> <p>添加文档后,就可以搜索这些文档了。Solr 接受 HTTP GET 和 HTTP POST 查询消息。收到的查询由相应的 SolrRequestHandler 进行处理。 </p> <p>solr查询参数描述: </p> <table border="1" cellspacing="0" cellpadding="0" width="663"> <tbody> <tr> <td valign="top" width="78"> <p>参数</p> </td> <td valign="top" width="373"> <p>描述</p> </td> <td valign="top" width="210"> <p>示例</p> </td> </tr> <tr> <td valign="top" width="78"> <p>q</p> </td> <td valign="top" width="373"> <p>Solr 中用来搜索的查询。有关该语法的完整描述,请参阅 <a href="/misc/goto?guid=4959517664602649020">参考资料</a>。可以通过追加一个分号和已索引且未进行断词的字段(下面会进行解释)的名称来包含排序信息。默认的排序是 score desc,指按记分降序排序。</p> </td> <td valign="top" width="210"> <p>q=myField:Java AND otherField:developerWorks; date asc </p> <p>此查询搜索指定的两个字段,并根据一个日期字段对结果进行排序。</p> </td> </tr> <tr> <td valign="top" width="78"> <p>start</p> </td> <td valign="top" width="373"> <p>将初始偏移量指定到结果集中。可用于对结果进行分页。默认值为 0。</p> </td> <td valign="top" width="210"> <p>start=15 </p> <p>返回从第 15 个结果开始的结果。</p> </td> </tr> <tr> <td valign="top" width="78"> <p>rows</p> </td> <td valign="top" width="373"> <p>返回文档的最大数目。默认值为 10。</p> </td> <td valign="top" width="210"> <p>rows=25,返回25个结果集</p> </td> </tr> <tr> <td valign="top" width="78"> <p>fq</p> </td> <td valign="top" width="373"> <p>提供一个可选的筛选器查询。查询结果被限制为仅搜索筛选器查询返回的结果。筛选过的查询由 Solr 进行缓存。它们对提高复杂查询的速度非常有用。</p> </td> <td valign="top" width="210"> <p>任何可以用 q 参数传递的有效查询,排序信息除外。</p> </td> </tr> <tr> <td valign="top" width="78"> <p>hl</p> </td> <td valign="top" width="373"> <p>当 hl=true 时,在查询响应中醒目显示片段。默认为 false。参看醒目显示参数(见 <a href="/misc/goto?guid=4959517664691347584">参考资料</a>)。</p> </td> <td valign="top" width="210"> <p>hl=true</p> </td> </tr> <tr> <td valign="top" width="78"> <p>fl</p> </td> <td valign="top" width="373"> <p>作为逗号分隔的列表指定文档结果中应返回的 Field 集。默认为 “*”,指所有的字段。“score” 指还应返回记分。</p> </td> <td valign="top" width="210"> <p>*,score</p> </td> </tr> <tr> <td valign="top" width="78"> <p>sort</p> </td> <td valign="top" width="373"> <p>排序,对查询结果进行排序,<a href="/misc/goto?guid=4959517664782886727">参考</a></p> </td> <td valign="top" width="210"> <p>sort=date asc,price desc</p> </td> </tr> </tbody> </table> <p> </p> <p>4、 solr模式 </p> <p>上面有提到schema.xml这个配置,这个配置可以在你下载solr包的安装解压目录的apache-solr-3.4.0\example\solr\conf中找到,它就是solr模式关联的文件。打开这个配置文件,你会发现有详细的注释。 </p> <p>模式组织主要分为三个重要配置 </p> <p>types 部分是一些常见的可重用定义,定义了 Solr(和 Lucene)如何处理 Field。也就是添加到索引中的xml文件属性中的类型,如int、text、date等 </p> <p>fileds是你添加到索引文件中出现的属性名称,而声明类型就需要用到上面的types </p> <p>其他配置有 </p> <p>uniqueKey 唯一键,这里配置的是上面出现的fileds,一般是id、url等不重复的。在更新、删除的时候可以用到。 </p> <p>defaultSearchField默认搜索属性,如q=solr就是默认的搜索那个字段 </p> <p>solrQueryParser查询转换模式,是并且还是或者(and/or) </p> <p><b>schema</b><b>配置类型</b> </p> <div id="codeSnippetWrapper"> <div style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;" id="codeSnippet"> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;"><</span><span style="color:#800000;">fieldType</span> <span style="color:#ff0000;">name</span><span style="color:#0000ff;">="text"</span> <span style="color:#ff0000;">class</span><span style="color:#0000ff;">="solr.TextField"</span> <span style="color:#ff0000;">positionIncrementGap</span><span style="color:#0000ff;">="100"</span><span style="color:#0000ff;">></span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#0000ff;"><</span><span style="color:#800000;">analyzer</span> <span style="color:#ff0000;">type</span><span style="color:#0000ff;">="index"</span><span style="color:#0000ff;">></span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#0000ff;"><</span><span style="color:#800000;">tokenizer</span> <span style="color:#ff0000;">class</span><span style="color:#0000ff;">="solr.WhitespaceTokenizerFactory"</span> <span style="color:#0000ff;">/></span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#0000ff;"><</span><span style="color:#800000;">filter</span> <span style="color:#ff0000;">class</span><span style="color:#0000ff;">="solr.StopFilterFactory"</span> <span style="color:#ff0000;">ignoreCase</span><span style="color:#0000ff;">="true"</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#ff0000;">words</span><span style="color:#0000ff;">="stopwords.txt"</span> <span style="color:#0000ff;">/></span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#0000ff;"><</span><span style="color:#800000;">filter</span> <span style="color:#ff0000;">class</span><span style="color:#0000ff;">="solr.WordDelimiterFilterFactory"</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#ff0000;">generateWordParts</span><span style="color:#0000ff;">="1"</span> <span style="color:#ff0000;">generateNumberParts</span><span style="color:#0000ff;">="1"</span> <span style="color:#ff0000;">catenateWords</span><span style="color:#0000ff;">="1"</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#ff0000;">catenateNumbers</span><span style="color:#0000ff;">="1"</span> <span style="color:#ff0000;">catenateAll</span><span style="color:#0000ff;">="0"</span> <span style="color:#0000ff;">/></span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#0000ff;"><</span><span style="color:#800000;">filter</span> <span style="color:#ff0000;">class</span><span style="color:#0000ff;">="solr.LowerCaseFilterFactory"</span> <span style="color:#0000ff;">/></span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#0000ff;"><</span><span style="color:#800000;">filter</span> <span style="color:#ff0000;">class</span><span style="color:#0000ff;">="solr.EnglishPorterFilterFactory"</span> <span style="color:#ff0000;">protected</span><span style="color:#0000ff;">="protwords.txt"</span> <span style="color:#0000ff;">/></span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#0000ff;"><</span><span style="color:#800000;">filter</span> <span style="color:#ff0000;">class</span><span style="color:#0000ff;">="solr.RemoveDuplicatesTokenFilterFactory"</span> <span style="color:#0000ff;">/></span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#0000ff;"></</span><span style="color:#800000;">analyzer</span><span style="color:#0000ff;">></span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#0000ff;"><</span><span style="color:#800000;">analyzer</span> <span style="color:#ff0000;">type</span><span style="color:#0000ff;">="query"</span><span style="color:#0000ff;">></span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#0000ff;"><</span><span style="color:#800000;">tokenizer</span> <span style="color:#ff0000;">class</span><span style="color:#0000ff;">="solr.WhitespaceTokenizerFactory"</span> <span style="color:#0000ff;">/></span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#0000ff;"><</span><span style="color:#800000;">filter</span> <span style="color:#ff0000;">class</span><span style="color:#0000ff;">="solr.SynonymFilterFactory"</span> <span style="color:#ff0000;">synonyms</span><span style="color:#0000ff;">="synonyms.txt"</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#ff0000;">ignoreCase</span><span style="color:#0000ff;">="true"</span> <span style="color:#ff0000;">expand</span><span style="color:#0000ff;">="true"</span> <span style="color:#0000ff;">/></span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#0000ff;"><</span><span style="color:#800000;">filter</span> <span style="color:#ff0000;">class</span><span style="color:#0000ff;">="solr.StopFilterFactory"</span> <span style="color:#ff0000;">ignoreCase</span><span style="color:#0000ff;">="true"</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#ff0000;">words</span><span style="color:#0000ff;">="stopwords.txt"</span> <span style="color:#0000ff;">/></span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#0000ff;"><</span><span style="color:#800000;">filter</span> <span style="color:#ff0000;">class</span><span style="color:#0000ff;">="solr.WordDelimiterFilterFactory"</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#ff0000;">generateWordParts</span><span style="color:#0000ff;">="1"</span> <span style="color:#ff0000;">generateNumberParts</span><span style="color:#0000ff;">="1"</span> <span style="color:#ff0000;">catenateWords</span><span style="color:#0000ff;">="0"</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#ff0000;">catenateNumbers</span><span style="color:#0000ff;">="0"</span> <span style="color:#ff0000;">catenateAll</span><span style="color:#0000ff;">="0"</span> <span style="color:#0000ff;">/></span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#0000ff;"><</span><span style="color:#800000;">filter</span> <span style="color:#ff0000;">class</span><span style="color:#0000ff;">="solr.LowerCaseFilterFactory"</span> <span style="color:#0000ff;">/></span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#0000ff;"><</span><span style="color:#800000;">filter</span> <span style="color:#ff0000;">class</span><span style="color:#0000ff;">="solr.EnglishPorterFilterFactory"</span> <span style="color:#ff0000;">protected</span><span style="color:#0000ff;">="protwords.txt"</span> <span style="color:#0000ff;">/></span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#0000ff;"><</span><span style="color:#800000;">filter</span> <span style="color:#ff0000;">class</span><span style="color:#0000ff;">="solr.RemoveDuplicatesTokenFilterFactory"</span> <span style="color:#0000ff;">/></span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#0000ff;"></</span><span style="color:#800000;">analyzer</span><span style="color:#0000ff;">></span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;"></</span><span style="color:#800000;">fieldType</span><span style="color:#0000ff;">></span></pre> </div> </div> <p>上面就是一个type了,然后你在fields配置field的时候就可以用这个type。 </p> <p> </p> <p>首先,上面的fieldType的配置中有两个analyzer,它是分词器。主要把我们的数据进行分割成一个个的词语。词干提取、停止词删除以及相似的操作都被应用于标记,然后才进行索引和搜索,导致使用相同类型的标记。 </p> <p>上面的应用程序的 Solr 的fieldType配置按以下步骤进行设置: </p> <p>Ø 根据空白进行断词,然后删除所有的公共词(StopFilterFactory) </p> <p>Ø 使用破折号处理特殊的大小写、大小写转换等等。(WordDelimiterFilterFactory);将所有条目处理为小写(LowerCaseFilterFactory) </p> <p>Ø 使用 Porter Stemming 算法进行词干提取(EnglishPorterFilterFactory) </p> <p>Ø 删除所有的副本(RemoveDuplicatesTokenFilterFactory) </p> <p>Schema属性、字段 </p> <div id="codeSnippetWrapper"> <div style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;" id="codeSnippet"> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;"><</span><span style="color:#800000;">field</span> <span style="color:#ff0000;">name</span><span style="color:#0000ff;">="id"</span> <span style="color:#ff0000;">type</span><span style="color:#0000ff;">="string"</span> <span style="color:#ff0000;">indexed</span><span style="color:#0000ff;">="true"</span> <span style="color:#ff0000;">stored</span><span style="color:#0000ff;">="true"</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#ff0000;">required</span><span style="color:#0000ff;">="true"</span> <span style="color:#0000ff;">/></span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;"><</span><span style="color:#800000;">field</span> <span style="color:#ff0000;">name</span><span style="color:#0000ff;">="sku"</span> <span style="color:#ff0000;">type</span><span style="color:#0000ff;">="text_en_splitting_tight"</span> <span style="color:#ff0000;">indexed</span><span style="color:#0000ff;">="true"</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#ff0000;">stored</span><span style="color:#0000ff;">="true"</span> <span style="color:#ff0000;">omitNorms</span><span style="color:#0000ff;">="true"</span> <span style="color:#0000ff;">/></span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;"><</span><span style="color:#800000;">field</span> <span style="color:#ff0000;">name</span><span style="color:#0000ff;">="name"</span> <span style="color:#ff0000;">type</span><span style="color:#0000ff;">="text_general"</span> <span style="color:#ff0000;">indexed</span><span style="color:#0000ff;">="true"</span> <span style="color:#ff0000;">stored</span><span style="color:#0000ff;">="true"</span> <span style="color:#0000ff;">/></span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;"><</span><span style="color:#800000;">field</span> <span style="color:#ff0000;">name</span><span style="color:#0000ff;">="alphaNameSort"</span> <span style="color:#ff0000;">type</span><span style="color:#0000ff;">="alphaOnlySort"</span> <span style="color:#ff0000;">indexed</span><span style="color:#0000ff;">="true"</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#ff0000;">stored</span><span style="color:#0000ff;">="false"</span> <span style="color:#0000ff;">/></span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;"><</span><span style="color:#800000;">field</span> <span style="color:#ff0000;">name</span><span style="color:#0000ff;">="manu"</span> <span style="color:#ff0000;">type</span><span style="color:#0000ff;">="text_general"</span> <span style="color:#ff0000;">indexed</span><span style="color:#0000ff;">="true"</span> <span style="color:#ff0000;">stored</span><span style="color:#0000ff;">="true"</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#ff0000;">omitNorms</span><span style="color:#0000ff;">="true"</span> <span style="color:#0000ff;">/></span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;"><</span><span style="color:#800000;">field</span> <span style="color:#ff0000;">name</span><span style="color:#0000ff;">="cat"</span> <span style="color:#ff0000;">type</span><span style="color:#0000ff;">="string"</span> <span style="color:#ff0000;">indexed</span><span style="color:#0000ff;">="true"</span> <span style="color:#ff0000;">stored</span><span style="color:#0000ff;">="true"</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#ff0000;">multiValued</span><span style="color:#0000ff;">="true"</span> <span style="color:#0000ff;">/></span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;"><</span><span style="color:#800000;">field</span> <span style="color:#ff0000;">name</span><span style="color:#0000ff;">="features"</span> <span style="color:#ff0000;">type</span><span style="color:#0000ff;">="text_general"</span> <span style="color:#ff0000;">indexed</span><span style="color:#0000ff;">="true"</span> <span style="color:#ff0000;">stored</span><span style="color:#0000ff;">="true"</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#ff0000;">multiValued</span><span style="color:#0000ff;">="true"</span> <span style="color:#0000ff;">/></span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;"><</span><span style="color:#800000;">field</span> <span style="color:#ff0000;">name</span><span style="color:#0000ff;">="includes"</span> <span style="color:#ff0000;">type</span><span style="color:#0000ff;">="text_general"</span> <span style="color:#ff0000;">indexed</span><span style="color:#0000ff;">="true"</span> <span style="color:#ff0000;">stored</span><span style="color:#0000ff;">="true"</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#ff0000;">termVectors</span><span style="color:#0000ff;">="true"</span> <span style="color:#ff0000;">termPositions</span><span style="color:#0000ff;">="true"</span> <span style="color:#ff0000;">termOffsets</span><span style="color:#0000ff;">="true"</span> <span style="color:#0000ff;">/></span></pre> </div> </div> <p>属性是在添加索引、查询的时候必须的配置,如果你不加这些配置。是无法完成索引的创建的。 </p> <p>首先id属性是未经分析的字符串类型,是可以索引、存储的,并且是唯一的。 </p> <p>sku是一个经过分词器分析出来的英文切割的类型字符,可以索引、存储、不要存储规范 </p> <p>multiValued 属性是一个特殊的例子,指 Document 可以拥有一个相同名称添加了多次的 Field。 </p> <p>omitNorms 属性告诉 Solr(和 Lucene)不要存储规范。 </p> <p>介绍一下字段声明下方的 <dynamicField> 声明。动态字段是一些特殊类型的字段,可以在任何时候将这些字段添加到任何文档中,由字段声明定义它们的属性。动态字段和普通字段之间的关键区别在于前者不需要在 schema.xml 中提前声明名称。Solr 将名称声明中的 glob-like 模式应用到所有尚未声明的引入的字段名称,并根据其 <dynamicField> 声明定义的语义来处理字段。例如,<dynamicField name="*_i" type="sint" indexed="true" stored="true"/> 指一个 myRating_i 字段被 Solr 处理为 sint,尽管并未将其声明为字段。这种处理比较方便,例如,当需要用户定义待搜索内容的时候。 </p> <p> </p> <p>5、 索引配置 </p> <p>Solr 性能因素,来了解与各种更改相关的性能权衡。 </p> <p>表 1 概括了可控制 Solr 索引处理的各种因素: </p> <table border="1" cellspacing="0" cellpadding="0" width="692"> <tbody> <tr> <td valign="top" width="116"> <p>因素</p> </td> <td valign="top" width="574"> <p>描述</p> </td> </tr> <tr> <td valign="top" width="116"> <p>useCompoundFile</p> </td> <td valign="top" width="574"> <p>通过将很多 Lucene 内部文件整合到单一一个文件来减少使用中的文件的数量。这可有助于减少 Solr 使用的文件句柄数目,代价是降低了性能。除非是应用程序用完了文件句柄,否则 false 的默认值应该就已经足够。</p> </td> </tr> <tr> <td valign="top" width="116"> <p>mergeFactor</p> </td> <td valign="top" width="574"> <p>决定低水平的 Lucene 段被合并的频率。较小的值(最小为 2)使用的内存较少但导致的索引时间也更慢。较大的值可使索引时间变快但会牺牲较多的内存。</p> </td> </tr> <tr> <td valign="top" width="116"> <p>maxBufferedDocs</p> </td> <td valign="top" width="574"> <p>在合并内存中文档和创建新段之前,定义所需索引的最小文档数。段 是用来存储索引信息的 Lucene 文件。较大的值可使索引时间变快但会牺牲较多的内存。</p> </td> </tr> <tr> <td valign="top" width="116"> <p>maxMergeDocs</p> </td> <td valign="top" width="574"> <p>控制可由 Solr 合并的 Document 的最大数。较小的值 (< 10,000) 最适合于具有大量更新的应用程序。</p> </td> </tr> <tr> <td valign="top" width="116"> <p>maxFieldLength</p> </td> <td valign="top" width="574"> <p>对于给定的 Document,控制可添加到 Field 的最大条目数,进而截断该文档。如果文档可能会很大,就需要增加这个数值。然而,若将这个值设置得过高会导致内存不足错误。</p> </td> </tr> <tr> <td valign="top" width="116"> <p>unlockOnStartup</p> </td> <td valign="top" width="574"> <p>unlockOnStartup 告知 Solr 忽略在多线程环境中用来保护索引的锁定机制。在某些情况下,索引可能会由于不正确的关机或其他错误而一直处于锁定,这就妨碍了添加和更新。将其设置为 true 可以禁用启动锁定,进而允许进行添加和更新。</p> </td> </tr> </tbody> </table> <p> </p> <p>6、 查询处理配置 </p> <p><maxBooleanClauses> 标记定义了可组合在一起形成一个查询的子句数量的上限。对于大多数应用程序而言,默认的 1024 就应该已经足够;然而,如果应用程序大量使用了通配符或范围查询,增加这个限值将能避免当值超出时,抛出 TooManyClausesException。 </p> <p>若应用程序预期只会检索 Document 上少数几个 Field,那么可以将 <enableLazyFieldLoading> 属性设置为 true。懒散加载的一个常见场景大都发生在应用程序返回和显示一系列搜索结果的时候,用户常常会单击其中的一个来查看存储在此索引中的原始文档。初始的显示常常只需要显示很短的一段信息。若考虑到检索大型 Document 的代价,除非必需,否则就应该避免加载整个文档。 </p> <p><query> 部分负责定义与在 Solr 中发生的事件相关的几个选项。Searcher 的 Java 类来处理 Query 实例。要改进这一设计和显著提高性能,把这些新的 Searcher 联机以便为现场用户提供查询服务之前,先对它们进行 “热身”。<query> 部分中的 <listener> 选项定义 newSearcher 和 firstSearcher 事件,您可以使用这些事件来指定实例化新搜索程序或第一个搜索程序时应该执行哪些查询。如果应用程序期望请求某些特定的查询,那么在创建新搜索程序或第一个搜索程序时就应该反注释这些部分并执行适当的查询。 </p> <p>solrconfig.xml 文件的剩余部分,除 <admin> 之外,涵盖了与 缓存、复制 和 扩展或定制 Solr 有关的项目。admin 部分让您可以定制管理界面。有关配置 admin 节的更多信息,请参看solrconfig.xml 文件中的注释。 </p> <p> </p> <p>7、 监视、记录和统计数据 </p> <p>用于监视、记录和统计数据的 Solr 管理选项 </p> <table border="1" cellspacing="0" cellpadding="0" width="757"> <tbody> <tr> <td valign="top" width="116"> <p>菜单名</p> </td> <td valign="top" width="217"> <p>URL</p> </td> <td valign="top" width="422"> <p>描述</p> </td> </tr> <tr> <td valign="top" width="116"> <p>Statistics</p> </td> <td valign="top" width="217"> <p><a href="/misc/goto?guid=4959517664869142455">http://localhost:8080/solr/admin/stats.jsp</a></p> </td> <td valign="top" width="422"> <p>Statistics 管理页提供了与 Solr 性能相关的很多有用的统计数据。这些数据包括: </p> <p>关于何时加载索引以及索引中有多少文档的信息。 </p> <p>关于用来服务查询的 SolrRequestHandler 的有用信息。 </p> <p>涵盖索引过程的数据,包括添加、删除、提交等的数量。 </p> <p>缓存实现和 hit/miss/eviction 信息</p> </td> </tr> <tr> <td valign="top" width="116"> <p>Info</p> </td> <td valign="top" width="217"> <p><a href="/misc/goto?guid=4959517664954555153">http://localhost:8080/solr/admin/registry.jsp</a></p> </td> <td valign="top" width="422"> <p>有关正在运行的 Solr 的版本以及在当前实现中进行查询、更新和缓存所使用的类的详细信息。此外,还包括文件存于 Solr subversion 存储库的何处的信息以及对该文件功能的一个简要描述。</p> </td> </tr> <tr> <td valign="top" width="116"> <p>Distribution</p> </td> <td valign="top" width="217"> <p><a href="/misc/goto?guid=4959517665034084859">http://localhost:8080/solr/admin/distributiondump.jsp</a></p> </td> <td valign="top" width="422"> <p>显示与索引发布和复制有关的信息。更多信息,请参见 “发布和复制” 一节。</p> </td> </tr> <tr> <td valign="top" width="116"> <p>Ping</p> </td> <td valign="top" width="217"> <p><a href="/misc/goto?guid=4959517665115465007">http://localhost:8080/solr/admin/ping</a></p> </td> <td valign="top" width="422"> <p>向服务器发出 ping 请求,包括在 solrconfig.xml 文件的 admin 部分定义的请求。</p> </td> </tr> <tr> <td valign="top" width="116"> <p>Logging</p> </td> <td valign="top" width="217"> <p><a href="/misc/goto?guid=4959517665204516228">http://localhost:8080/solr/admin/logging.jsp</a></p> </td> <td valign="top" width="422"> <p>让您可以动态更改当前应用程序的日志记录等级。更改日志记录等级对于调试在执行过程中可能出现的问题非常有用。</p> </td> </tr> <tr> <td valign="top" width="116"> <p>properties</p> </td> <td valign="top" width="217"> <p>http: //localhost:8080/solr/admin/get-properties.jsp</p> </td> <td valign="top" width="422"> <p>显示当前系统正在使用的所有 Java 系统属性。Solr 支持通过命令行的系统属性替换。有关实现此特性的更多信息,请参见 solrconfig.xml 文件。</p> </td> </tr> <tr> <td valign="top" width="116"> <p>Thread dump</p> </td> <td valign="top" width="217"> <p>http://localhost:8080/solr/admin/threaddump.jsp</p> </td> <td valign="top" width="422"> <p>thread dump 选项显示了在 JVM 中运行的所有线程的堆栈跟踪信息。</p> </td> </tr> </tbody> </table> <p> </p> <p>8、 智能缓存 </p> <p>智能缓存是让 Solr 得以成为引人瞩目的搜索服务器的一个关键性能特征。Solr 提供了四种不同的缓存类型,所有四种类型都可在 solrconfig.xml 的 <query> 部分中配置。solrconfig.xml 文件中所用的标记名列出了这些缓存类型: </p> <table border="1" cellspacing="0" cellpadding="0" width="771"> <tbody> <tr> <td valign="top" width="153"> <p>缓存标记名</p> </td> <td valign="top" width="309"> <p>描述</p> </td> <td valign="top" width="307"> <p>能否自热</p> </td> </tr> <tr> <td valign="top" width="153"> <p>filterCache</p> </td> <td valign="top" width="309"> <p>通过存储一个匹配给定查询的文档 id 的无序集,过滤器让 Solr 能够有效提高查询的性能。缓存这些过滤器意味着对 Solr 的重复调用可以导致结果集的快速查找。更常见的场景是缓存一个过滤器,然后再发起后续的精炼查询,这种查询能使用过滤器来限制要搜索的文档数。</p> </td> <td valign="top" width="307"> <p>可以</p> </td> </tr> <tr> <td valign="top" width="153"> <p>queryResultCache</p> </td> <td valign="top" width="309"> <p>为查询、排序条件和所请求文档的数量缓存文档 id 的有序 集合。</p> </td> <td valign="top" width="307"> <p>可以</p> </td> </tr> <tr> <td valign="top" width="153"> <p>documentCache</p> </td> <td valign="top" width="309"> <p>缓存 Lucene Document,使用内部 Lucene 文档 id(以便不与 Solr 惟一 id 相混淆)。由于 Lucene 的内部 Document id 可以因索引操作而更改,这种缓存不能自热。</p> </td> <td valign="top" width="307"> <p>不可以</p> </td> </tr> <tr> <td valign="top" width="153"> <p>Named caches</p> </td> <td valign="top" width="309"> <p>命名缓存是用户定义的缓存,可被 Solr 定制插件 所使用。</p> </td> <td valign="top" width="307"> <p>可以, </p> <p>如果实现了 org.apache.solr.search.CacheRegenerator 的话。</p> </td> </tr> </tbody> </table> <p>每个缓存声明都接受最多四个属性: </p> <p>class 是缓存实现的 Java 名。 </p> <p>size 是最大的条目数。 </p> <p>initialSize 是缓存的初始大小。 </p> <p>autoWarmCount 是取自旧缓存以预热新缓存的条目数。如果条目很多,就意味着缓存的 hit 会更多,只不过需要花更长的预热时间。 </p> <h4> </h4> <h4>三、利用SolrJ操作solr API,完成index操作</h4> <p>使用SolrJ操作Solr会比利用httpClient来操作Solr要简单。SolrJ是封装了httpClient方法,来操作solr的API的。SolrJ底层还是通过使用httpClient中的方法来完成Solr的操作。 </p> <p>1、 首先,你需要添加如下jar包 </p> <p><a href="https://simg.open-open.com/show/4e7b49c669c341974b628333fef703d9.jpg"><img title="d3.jpg" border="0" alt="d3.jpg" src="https://simg.open-open.com/show/c2c4b6bb612b156c55cc5610c365b146.jpg" width="193" height="93" /></a> </p> <p>其中apache-solr-solrj-3.4.0.jar、slf4j-api-1.6.1.jar可以在下载的apache-solr-3.4.0的压缩包中的dist中能找到。 </p> <p> </p> <p>2、 其次,建立一个简单的测试类,完成Server对象的相关方法的测试工作,代码如下: </p> <div id="codeSnippetWrapper"> <div style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;" id="codeSnippet"> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">package</span> com.hoo.test;</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> </pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">import</span> java.io.IOException;</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">import</span> java.net.MalformedURLException;</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">import</span> java.util.ArrayList;</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">import</span> java.util.Collection;</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">import</span> java.util.List;</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">import</span> org.apache.solr.client.solrj.SolrQuery;</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">import</span> org.apache.solr.client.solrj.SolrServer;</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">import</span> org.apache.solr.client.solrj.SolrServerException;</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">import</span> org.apache.solr.client.solrj.impl.CommonsHttpSolrServer;</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">import</span> org.apache.solr.client.solrj.response.QueryResponse;</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">import</span> org.apache.solr.client.solrj.response.UpdateResponse;</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">import</span> org.apache.solr.common.SolrDocumentList;</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">import</span> org.apache.solr.common.SolrInputDocument;</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">import</span> org.apache.solr.common.params.ModifiableSolrParams;</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">import</span> org.apache.solr.common.params.SolrParams;</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">import</span> org.junit.After;</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">import</span> org.junit.Before;</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">import</span> org.junit.Test;</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">import</span> com.hoo.entity.Index;</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> </pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;">/**</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * <b>function:</b> Server TestCase</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * @author hoojo</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * @createDate 2011-10-19 下午01:49:07</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * @file ServerTest.java</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * @package com.hoo.test</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * @project SolrExample</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * @blog http://blog.csdn.net/IBM_hoojo</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * @email hoojo_@126.com</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * @version 1.0</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> */</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">public</span> <span style="color:#0000ff;">class</span> ServerTest {</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> </pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#0000ff;">private</span> SolrServer server;</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#0000ff;">private</span> CommonsHttpSolrServer httpServer;</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> </pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#0000ff;">private</span> <span style="color:#0000ff;">static</span> <span style="color:#0000ff;">final</span> String DEFAULT_URL = <span style="color:#006080;">"http://localhost:8983/solr/"</span>;</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> </pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> @Before</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">void</span> init() {</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#0000ff;">try</span> {</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> server = <span style="color:#0000ff;">new</span> CommonsHttpSolrServer(DEFAULT_URL);</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> httpServer = <span style="color:#0000ff;">new</span> CommonsHttpSolrServer(DEFAULT_URL);</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> } <span style="color:#0000ff;">catch</span> (MalformedURLException e) {</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> e.printStackTrace();</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> }</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> }</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> </pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> @After</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">void</span> destory() {</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> server = null;</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> httpServer = null;</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> System.runFinalization();</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> System.gc();</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> }</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> </pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">final</span> <span style="color:#0000ff;">void</span> fail(Object o) {</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> System.out.println(o);</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> }</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> </pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#008000;">/**</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * <b>function:</b> 测试是否创建server对象成功</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * @author hoojo</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * @createDate 2011-10-21 上午09:48:18</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> */</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> @Test</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">void</span> server() {</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> fail(server);</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> fail(httpServer);</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> }</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> </pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#008000;">/**</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * <b>function:</b> 根据query参数查询索引</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * @author hoojo</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * @createDate 2011-10-21 上午10:06:39</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * @param query</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> */</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">void</span> query(String query) {</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> SolrParams params = <span style="color:#0000ff;">new</span> SolrQuery(query);</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> </pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#0000ff;">try</span> {</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> QueryResponse response = server.query(params);</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> </pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> SolrDocumentList list = response.getResults();</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#0000ff;">for</span> (<span style="color:#0000ff;">int</span> i = 0; i < list.size(); i++) {</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> fail(list.get(i));</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> }</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> } <span style="color:#0000ff;">catch</span> (SolrServerException e) {</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> e.printStackTrace();</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> } </pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> }</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">}</pre> </div> </div> <p>测试运行server case方法,如果成功创建对象,那你就成功的链接到。 </p> <p>注意:在运行本方法之前,请启动你的solr官方自动的项目。<a href="/misc/goto?guid=4959517665303119413">http://localhost:8983/solr/</a>保证能够成功访问这个工程。因为接下来的所有工作都是围绕这个solr工程完成的。如果你现在还不知道,怎么部署、发布官方solr工程,请参考前面的具体章节。 </p> <p> </p> <p>3、 Server的有关配置选项参数,server是CommonsHttpSolrServer的实例 </p> <div id="codeSnippetWrapper"> <div style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;" id="codeSnippet"> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">server.setSoTimeout(1000); <span style="color:#008000;">// socket read timeout </span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">server.setConnectionTimeout(100); </pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">server.setDefaultMaxConnectionsPerHost(100); </pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">server.setMaxTotalConnections(100); </pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">server.setFollowRedirects(false); <span style="color:#008000;">// defaults to false </span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;">// allowCompression defaults to false. </span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;">// Server side must support gzip or deflate for this to have any effect. </span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">server.setAllowCompression(true); </pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">server.setMaxRetries(1); <span style="color:#008000;">// defaults to 0. > 1 not recommended. </span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> </pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;">//sorlr J 目前使用二进制的格式作为默认的格式。对于solr1.2的用户通过显示的设置才能使用XML格式。</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">server.setParser(<span style="color:#0000ff;">new</span> XMLResponseParser());</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> </pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;">//二进制流输出格式</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;">//server.setRequestWriter(new BinaryRequestWriter());</span></pre> </div> </div> <p> </p> <p>4、 利用SolrJ完成Index Document的添加操作 </p> <div id="codeSnippetWrapper"> <div style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;" id="codeSnippet"> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;">/**</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * <b>function:</b> 添加doc文档</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * @author hoojo</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * @createDate 2011-10-21 上午09:49:10</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> */</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">@Test</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">public</span> <span style="color:#0000ff;">void</span> addDoc() {</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#008000;">//创建doc文档</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> SolrInputDocument doc = <span style="color:#0000ff;">new</span> SolrInputDocument();</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> doc.addField(<span style="color:#006080;">"id"</span>, 1);</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> doc.addField(<span style="color:#006080;">"name"</span>, <span style="color:#006080;">"Solr Input Document"</span>);</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> doc.addField(<span style="color:#006080;">"manu"</span>, <span style="color:#006080;">"this is SolrInputDocument content"</span>);</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> </pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#0000ff;">try</span> {</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#008000;">//添加一个doc文档</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> UpdateResponse response = server.add(doc);</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> fail(server.commit());<span style="color:#008000;">//commit后才保存到索引库</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> fail(response);</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> fail(<span style="color:#006080;">"query time:"</span> + response.getQTime());</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> fail(<span style="color:#006080;">"Elapsed Time:"</span> + response.getElapsedTime());</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> fail(<span style="color:#006080;">"status:"</span> + response.getStatus());</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> } <span style="color:#0000ff;">catch</span> (SolrServerException e) {</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> e.printStackTrace();</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> } <span style="color:#0000ff;">catch</span> (IOException e) {</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> e.printStackTrace();</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> }</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> query(<span style="color:#006080;">"name:solr"</span>);</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">}</pre> </div> </div> <p>在apache-solr-3.4.0\example\solr\conf目录下的schema.xml中可以找到有关于field属性的配置,schema.xml中的field就和上面Document文档中的field(id、name、manu)对应。如果出现 ERROR:unknown field 'xxxx'就表示你设置的这个field在schema.xml中不存在。如果一定要使用这个field,请你在schema.xml中进行filed 元素的配置。具体请参考前面的章节。 </p> <p>注意:在schema.xml中配置了uniqueKey为id,就表示id是唯一的。如果在添加Document的时候,id重复添加。那么后面添加的相同id的doc会覆盖前面的doc,类似于update更新操作,而不会出现重复的数据。 </p> <p> </p> <p>5、 利用SolrJ添加多个Document,即添加文档集合 </p> <div id="codeSnippetWrapper"> <div style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;" id="codeSnippet"> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;">/**</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * <b>function:</b> 添加docs文档集合</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * @author hoojo</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * @createDate 2011-10-21 上午09:55:01</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> */</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">@Test</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">public</span> <span style="color:#0000ff;">void</span> addDocs() {</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> Collection<SolrInputDocument> docs = <span style="color:#0000ff;">new</span> ArrayList<SolrInputDocument>();</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> </pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> SolrInputDocument doc = <span style="color:#0000ff;">new</span> SolrInputDocument();</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> doc.addField(<span style="color:#006080;">"id"</span>, 2);</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> doc.addField(<span style="color:#006080;">"name"</span>, <span style="color:#006080;">"Solr Input Documents 1"</span>);</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> doc.addField(<span style="color:#006080;">"manu"</span>, <span style="color:#006080;">"this is SolrInputDocuments 1 content"</span>);</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> </pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> docs.add(doc);</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> </pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> doc = <span style="color:#0000ff;">new</span> SolrInputDocument();</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> doc.addField(<span style="color:#006080;">"id"</span>, 3);</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> doc.addField(<span style="color:#006080;">"name"</span>, <span style="color:#006080;">"Solr Input Documents 2"</span>);</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> doc.addField(<span style="color:#006080;">"manu"</span>, <span style="color:#006080;">"this is SolrInputDocuments 3 content"</span>);</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> </pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> docs.add(doc);</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> </pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#0000ff;">try</span> {</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#008000;">//add docs</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> UpdateResponse response = server.add(docs);</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#008000;">//commit后才保存到索引库</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> fail(server.commit());</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> fail(response);</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> } <span style="color:#0000ff;">catch</span> (SolrServerException e) {</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> e.printStackTrace();</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> } <span style="color:#0000ff;">catch</span> (IOException e) {</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> e.printStackTrace();</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> }</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> query(<span style="color:#006080;">"solr"</span>);</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">}</pre> </div> </div> <p>就是添加一个List集合 </p> <p> </p> <p>6、 添加JavaEntity Bean,这个需要先创建一个JavaBean,然后来完成添加操作; </p> <p>JavaBean:Index的代码 </p> <div id="codeSnippetWrapper"> <div style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;" id="codeSnippet"> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">package</span> com.hoo.entity;</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> </pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">import</span> org.apache.solr.client.solrj.beans.Field;</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> </pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;">/**</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * <b>function:</b> JavaEntity Bean;Index需要添加相关的Annotation注解,便于告诉solr哪些属性参与到index中</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * @author hoojo</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * @createDate 2011-10-19 下午05:33:27</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * @file Index.java</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * @package com.hoo.entity</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * @project SolrExample</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * @blog http://blog.csdn.net/IBM_hoojo</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * @email hoojo_@126.com</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * @version 1.0</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> */</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">public</span> <span style="color:#0000ff;">class</span> Index {</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#008000;">//@Field setter方法上添加Annotation也是可以的</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#0000ff;">private</span> String id;</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> @Field</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#0000ff;">private</span> String name;</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> @Field</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#0000ff;">private</span> String manu;</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> @Field</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#0000ff;">private</span> String[] cat;</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> </pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> @Field</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#0000ff;">private</span> String[] features;</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> @Field</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#0000ff;">private</span> <span style="color:#0000ff;">float</span> price;</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> @Field</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#0000ff;">private</span> <span style="color:#0000ff;">int</span> popularity;</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> @Field</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#0000ff;">private</span> <span style="color:#0000ff;">boolean</span> inStock;</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> </pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#0000ff;">public</span> String getId() {</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#0000ff;">return</span> id;</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> }</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> </pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> @Field</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">void</span> setId(String id) {</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#0000ff;">this</span>.id = id;</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> }</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#008000;">//getter、setter方法</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> </pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#0000ff;">public</span> String toString() {</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#0000ff;">return</span> <span style="color:#0000ff;">this</span>.id + <span style="color:#006080;">"#"</span> + <span style="color:#0000ff;">this</span>.name + <span style="color:#006080;">"#"</span> + <span style="color:#0000ff;">this</span>.manu + <span style="color:#006080;">"#"</span> + <span style="color:#0000ff;">this</span>.cat;</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> }</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">}</pre> </div> </div> <p>注意上面的属性是和在apache-solr-3.4.0\example\solr\conf目录下的schema.xml中可以找到有关于 field属性的配置对应的。如果你Index JavaBean中出现的属性在schema.xml的field配置无法找到,那么出出现unknown filed错误。 </p> <p>添加Bean完成doc添加操作 </p> <div id="codeSnippetWrapper"> <div style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;" id="codeSnippet"> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;">/**</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * <b>function:</b> 添加JavaEntity Bean</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * @author hoojo</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * @createDate 2011-10-21 上午09:55:37</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> */</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">@Test</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">public</span> <span style="color:#0000ff;">void</span> addBean() {</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#008000;">//Index需要添加相关的Annotation注解,便于告诉solr哪些属性参与到index中</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> Index index = <span style="color:#0000ff;">new</span> Index();</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> index.setId(<span style="color:#006080;">"4"</span>);</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> index.setName(<span style="color:#006080;">"add bean index"</span>);</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> index.setManu(<span style="color:#006080;">"index bean manu"</span>);</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> index.setCat(<span style="color:#0000ff;">new</span> String[] { <span style="color:#006080;">"a1"</span>, <span style="color:#006080;">"b2"</span> });</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> </pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#0000ff;">try</span> {</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#008000;">//添加Index Bean到索引库</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> UpdateResponse response = server.addBean(index);</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> fail(server.commit());<span style="color:#008000;">//commit后才保存到索引库</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> fail(response);</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> } <span style="color:#0000ff;">catch</span> (SolrServerException e) {</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> e.printStackTrace();</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> } <span style="color:#0000ff;">catch</span> (IOException e) {</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> e.printStackTrace();</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> }</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> queryAll();</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">}</pre> </div> </div> <p> </p> <p>7、 添加Bean集合 </p> <div id="codeSnippetWrapper"> <div style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;" id="codeSnippet"> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;">/**</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * <b>function:</b> 添加Entity Bean集合到索引库</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * @author hoojo</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * @createDate 2011-10-21 上午10:00:55</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> */</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">@Test</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">public</span> <span style="color:#0000ff;">void</span> addBeans() {</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> Index index = <span style="color:#0000ff;">new</span> Index();</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> index.setId(<span style="color:#006080;">"6"</span>);</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> index.setName(<span style="color:#006080;">"add beans index 1"</span>);</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> index.setManu(<span style="color:#006080;">"index beans manu 1"</span>);</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> index.setCat(<span style="color:#0000ff;">new</span> String[] { <span style="color:#006080;">"a"</span>, <span style="color:#006080;">"b"</span> });</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> </pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> List<Index> indexs = <span style="color:#0000ff;">new</span> ArrayList<Index>();</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> indexs.add(index);</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> </pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> index = <span style="color:#0000ff;">new</span> Index();</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> index.setId(<span style="color:#006080;">"5"</span>);</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> index.setName(<span style="color:#006080;">"add beans index 2"</span>);</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> index.setManu(<span style="color:#006080;">"index beans manu 2"</span>);</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> index.setCat(<span style="color:#0000ff;">new</span> String[] { <span style="color:#006080;">"aaa"</span>, <span style="color:#006080;">"bbbb"</span> });</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> indexs.add(index);</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#0000ff;">try</span> {</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#008000;">//添加索引库</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> UpdateResponse response = server.addBeans(indexs);</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> fail(server.commit());<span style="color:#008000;">//commit后才保存到索引库</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> fail(response);</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> } <span style="color:#0000ff;">catch</span> (SolrServerException e) {</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> e.printStackTrace();</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> } <span style="color:#0000ff;">catch</span> (IOException e) {</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> e.printStackTrace();</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> }</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> queryAll();</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">}</pre> </div> </div> <p> </p> <p>8、 删除索引Document </p> <div id="codeSnippetWrapper"> <div style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;" id="codeSnippet"> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;">/**</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * <b>function:</b> 删除索引操作</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * @author hoojo</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * @createDate 2011-10-21 上午10:04:28</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> */</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">@Test</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">public</span> <span style="color:#0000ff;">void</span> remove() {</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#0000ff;">try</span> {</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#008000;">//删除id为1的索引</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> server.deleteById(<span style="color:#006080;">"1"</span>);</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> server.commit();</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> query(<span style="color:#006080;">"id:1"</span>);</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> </pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#008000;">//根据id集合,删除多个索引</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> List<String> ids = <span style="color:#0000ff;">new</span> ArrayList<String>();</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> ids.add(<span style="color:#006080;">"2"</span>);</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> ids.add(<span style="color:#006080;">"3"</span>);</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> server.deleteById(ids);</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> server.commit(true, true);</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> query(<span style="color:#006080;">"id:3 id:2"</span>);</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> </pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#008000;">//删除查询到的索引信息</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> server.deleteByQuery(<span style="color:#006080;">"id:4 id:6"</span>);</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> server.commit(true, true);</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> queryAll();</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> </pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> } <span style="color:#0000ff;">catch</span> (SolrServerException e) {</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> e.printStackTrace();</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> } <span style="color:#0000ff;">catch</span> (IOException e) {</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> e.printStackTrace();</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> }</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">}</pre> </div> </div> <p> </p> <p>9、 查询索引 </p> <div id="codeSnippetWrapper"> <div style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;" id="codeSnippet"> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;">/**</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * <b>function:</b> 查询所有索引信息</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * @author hoojo</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * @createDate 2011-10-21 上午10:05:38</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> */</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">@Test</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">public</span> <span style="color:#0000ff;">void</span> queryAll() {</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> ModifiableSolrParams params = <span style="color:#0000ff;">new</span> ModifiableSolrParams();</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#008000;">// 查询关键词,*:*代表所有属性、所有值,即所有index</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> params.set(<span style="color:#006080;">"q"</span>, <span style="color:#006080;">"*:*"</span>);</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#008000;">// 分页,start=0就是从0开始,,rows=5当前返回5条记录,第二页就是变化start这个值为5就可以了。</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> params.set(<span style="color:#006080;">"start"</span>, 0);</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> params.set(<span style="color:#006080;">"rows"</span>, Integer.MAX_VALUE);</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> </pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#008000;">// 排序,,如果按照id 排序,,那么将score desc 改成 id desc(or asc)</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> params.set(<span style="color:#006080;">"sort"</span>, <span style="color:#006080;">"score desc"</span>);</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> </pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#008000;">// 返回信息 * 为全部 这里是全部加上score,如果不加下面就不能使用score</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> params.set(<span style="color:#006080;">"fl"</span>, <span style="color:#006080;">"*,score"</span>);</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> </pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#0000ff;">try</span> {</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> QueryResponse response = server.query(params);</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> </pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> SolrDocumentList list = response.getResults();</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#0000ff;">for</span> (<span style="color:#0000ff;">int</span> i = 0; i < list.size(); i++) {</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> fail(list.get(i));</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> }</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> } <span style="color:#0000ff;">catch</span> (SolrServerException e) {</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> e.printStackTrace();</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> }</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">}</pre> </div> </div> <p> </p> <p>10、 其他和Server有关方法 </p> <div id="codeSnippetWrapper"> <div style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;" id="codeSnippet"> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;">/**</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * <b>function:</b> 其他server相关方法测试</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * @author hoojo</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * @createDate 2011-10-21 上午10:02:03</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> */</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">@Test</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">public</span> <span style="color:#0000ff;">void</span> otherMethod() {</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> fail(server.getBinder());</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#0000ff;">try</span> {</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> fail(server.optimize());<span style="color:#008000;">//合并索引文件,可以优化索引、提供性能,但需要一定的时间</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> fail(server.ping());<span style="color:#008000;">//ping服务器是否连接成功</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> </pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> Index index = <span style="color:#0000ff;">new</span> Index();</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> index.setId(<span style="color:#006080;">"299"</span>);</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> index.setName(<span style="color:#006080;">"add bean index199"</span>);</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> index.setManu(<span style="color:#006080;">"index bean manu199"</span>);</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> index.setCat(<span style="color:#0000ff;">new</span> String[] { <span style="color:#006080;">"a199"</span>, <span style="color:#006080;">"b199"</span> });</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> </pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> UpdateResponse response = server.addBean(index);</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> fail(<span style="color:#006080;">"response: "</span> + response);</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> </pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> queryAll();</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#008000;">//回滚掉之前的操作,rollback addBean operation</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> fail(<span style="color:#006080;">"rollback: "</span> + server.rollback());</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#008000;">//提交操作,提交后无法回滚之前操作;发现addBean没有成功添加索引</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> fail(<span style="color:#006080;">"commit: "</span> + server.commit());</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> queryAll();</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> } <span style="color:#0000ff;">catch</span> (SolrServerException e) {</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> e.printStackTrace();</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> } <span style="color:#0000ff;">catch</span> (IOException e) {</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> e.printStackTrace();</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> }</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">}</pre> </div> </div> <p> </p> <p>11、 文档查询 </p> <div id="codeSnippetWrapper"> <div style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;" id="codeSnippet"> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;">/**</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * <b>function:</b> query 基本用法测试</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * @author hoojo</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * @createDate 2011-10-20 下午04:44:28</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> */</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">@Test</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">public</span> <span style="color:#0000ff;">void</span> queryCase() {</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#008000;">//AND 并且</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> SolrQuery params = <span style="color:#0000ff;">new</span> SolrQuery(<span style="color:#006080;">"name:apple AND manu:inc"</span>);</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> </pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#008000;">//OR 或者</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> params.setQuery(<span style="color:#006080;">"name:apple OR manu:apache"</span>);</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#008000;">//空格 等同于 OR</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> params.setQuery(<span style="color:#006080;">"name:server manu:dell"</span>);</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> </pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#008000;">//params.setQuery("name:solr - manu:inc");</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#008000;">//params.setQuery("name:server + manu:dell");</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> </pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#008000;">//查询name包含solr apple</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> params.setQuery(<span style="color:#006080;">"name:solr,apple"</span>);</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#008000;">//manu不包含inc</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> params.setQuery(<span style="color:#006080;">"name:solr,apple NOT manu:inc"</span>);</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> </pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#008000;">//50 <= price <= 200</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> params.setQuery(<span style="color:#006080;">"price:[50 TO 200]"</span>);</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> params.setQuery(<span style="color:#006080;">"popularity:[5 TO 6]"</span>);</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#008000;">//params.setQuery("price:[50 TO 200] - popularity:[5 TO 6]");</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#008000;">//params.setQuery("price:[50 TO 200] + popularity:[5 TO 6]");</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> </pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#008000;">//50 <= price <= 200 AND 5 <= popularity <= 6</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> params.setQuery(<span style="color:#006080;">"price:[50 TO 200] AND popularity:[5 TO 6]"</span>);</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> params.setQuery(<span style="color:#006080;">"price:[50 TO 200] OR popularity:[5 TO 6]"</span>);</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> </pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#008000;">//过滤器查询,可以提高性能 filter 类似多个条件组合,如and</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#008000;">//params.addFilterQuery("id:VA902B");</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#008000;">//params.addFilterQuery("price:[50 TO 200]");</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#008000;">//params.addFilterQuery("popularity:[* TO 5]");</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#008000;">//params.addFilterQuery("weight:*");</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#008000;">//0 < popularity < 6 没有等于</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#008000;">//params.addFilterQuery("popularity:{0 TO 6}");</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> </pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#008000;">//排序</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> params.addSortField(<span style="color:#006080;">"id"</span>, ORDER.asc);</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> </pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#008000;">//分页:start开始页,rows每页显示记录条数</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#008000;">//params.add("start", "0");</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#008000;">//params.add("rows", "200");</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#008000;">//params.setStart(0);</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#008000;">//params.setRows(200);</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> </pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#008000;">//设置高亮</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> params.setHighlight(true); <span style="color:#008000;">// 开启高亮组件</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> params.addHighlightField(<span style="color:#006080;">"name"</span>);<span style="color:#008000;">// 高亮字段</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> params.setHighlightSimplePre(<span style="color:#006080;">"<font color='red'>"</span>);<span style="color:#008000;">//标记,高亮关键字前缀</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> params.setHighlightSimplePost(<span style="color:#006080;">"</font>"</span>);<span style="color:#008000;">//后缀</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> params.setHighlightSnippets(1);<span style="color:#008000;">//结果分片数,默认为1</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> params.setHighlightFragsize(1000);<span style="color:#008000;">//每个分片的最大长度,默认为100</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> </pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#008000;">//分片信息</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> params.setFacet(true)</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> .setFacetMinCount(1)</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> .setFacetLimit(5)<span style="color:#008000;">//段</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> .addFacetField(<span style="color:#006080;">"name"</span>)<span style="color:#008000;">//分片字段</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> .addFacetField(<span style="color:#006080;">"inStock"</span>); </pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> </pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#008000;">//params.setQueryType("");</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> </pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#0000ff;">try</span> {</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> QueryResponse response = server.query(params);</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> </pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#008000;">/*List<Index> indexs = response.getBeans(Index.class);</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> for (int i = 0; i < indexs.size(); i++) {</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> fail(indexs.get(i));</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> }*/</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> </pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#008000;">//输出查询结果集</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> SolrDocumentList list = response.getResults();</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> fail(<span style="color:#006080;">"query result nums: "</span> + list.getNumFound());</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#0000ff;">for</span> (<span style="color:#0000ff;">int</span> i = 0; i < list.size(); i++) {</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> fail(list.get(i));</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> }</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> </pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#008000;">//输出分片信息</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> List<FacetField> facets = response.getFacetFields();</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#0000ff;">for</span> (FacetField facet : facets) {</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> fail(facet);</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> List<Count> facetCounts = facet.getValues();</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#0000ff;">for</span> (FacetField.Count count : facetCounts) {</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> System.out.println(count.getName() + <span style="color:#006080;">": "</span> + count.getCount());</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> }</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> }</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> } <span style="color:#0000ff;">catch</span> (SolrServerException e) {</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> e.printStackTrace();</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> } </pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">}</pre> </div> </div> <p> </p> <p>12、 分片查询、统计 </p> <div id="codeSnippetWrapper"> <div style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;" id="codeSnippet"> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;">/**</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * <b>function:</b> 分片查询, 可以统计关键字及出现的次数、或是做自动补全提示</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * @author hoojo</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * @createDate 2011-10-20 下午04:54:25</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> */</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">@Test</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">public</span> <span style="color:#0000ff;">void</span> facetQueryCase() {</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> SolrQuery params = <span style="color:#0000ff;">new</span> SolrQuery(<span style="color:#006080;">"*:*"</span>);</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> </pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#008000;">//排序</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> params.addSortField(<span style="color:#006080;">"id"</span>, ORDER.asc);</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> </pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> params.setStart(0);</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> params.setRows(200);</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> </pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#008000;">//Facet为solr中的层次分类查询</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#008000;">//分片信息</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> params.setFacet(true)</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> .setQuery(<span style="color:#006080;">"*:*"</span>)</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> .setFacetMinCount(1)</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> .setFacetLimit(5)<span style="color:#008000;">//段</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#008000;">//.setFacetPrefix("electronics", "cat")</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> .setFacetPrefix(<span style="color:#006080;">"cor"</span>)<span style="color:#008000;">//查询manu、name中关键字前缀是cor的</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> .addFacetField(<span style="color:#006080;">"manu"</span>)</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> .addFacetField(<span style="color:#006080;">"name"</span>);<span style="color:#008000;">//分片字段</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> </pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#0000ff;">try</span> {</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> QueryResponse response = server.query(params);</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> </pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#008000;">//输出查询结果集</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> SolrDocumentList list = response.getResults();</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> fail(<span style="color:#006080;">"Query result nums: "</span> + list.getNumFound());</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> </pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#0000ff;">for</span> (<span style="color:#0000ff;">int</span> i = 0; i < list.size(); i++) {</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> fail(list.get(i));</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> }</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> </pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> fail(<span style="color:#006080;">"All facet filed result: "</span>);</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#008000;">//输出分片信息</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> List<FacetField> facets = response.getFacetFields();</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#0000ff;">for</span> (FacetField facet : facets) {</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> fail(facet);</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> List<Count> facetCounts = facet.getValues();</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#0000ff;">for</span> (FacetField.Count count : facetCounts) {</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#008000;">//关键字 - 出现次数</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> fail(count.getName() + <span style="color:#006080;">": "</span> + count.getCount());</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> }</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> }</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> </pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> fail(<span style="color:#006080;">"Search facet [name] filed result: "</span>);</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#008000;">//输出分片信息</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> FacetField facetField = response.getFacetField(<span style="color:#006080;">"name"</span>);</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> List<Count> facetFields = facetField.getValues();</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#0000ff;">for</span> (Count count : facetFields) {</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#008000;">//关键字 - 出现次数</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> fail(count.getName() + <span style="color:#006080;">": "</span> + count.getCount());</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> }</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> } <span style="color:#0000ff;">catch</span> (SolrServerException e) {</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> e.printStackTrace();</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> } </pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">}</pre> </div> </div> <p>分片查询在某些统计关键字的时候还是很有用的,可以统计关键字出现的次数,可以通过统计的关键字来搜索相关文档的信息。 </p> <p> </p> <h4>四、Document文档和JavaBean相互转换</h4> <p>这里转换的Bean是一个简单的User对象 </p> <div id="codeSnippetWrapper"> <div style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;" id="codeSnippet"> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">package</span> com.hoo.entity;</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> </pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">import</span> java.io.Serializable;</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">import</span> org.apache.solr.client.solrj.beans.Field;</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> </pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;">/**</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * <b>function:</b> User Entity Bean;所有被添加Annotation @Field 注解的属性将参与index操作</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * @author hoojo</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * @createDate 2011-10-19 下午04:16:00</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * @file User.java</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * @package com.hoo.entity</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * @project SolrExample</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * @blog http://blog.csdn.net/IBM_hoojo</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * @email hoojo_@126.com</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * @version 1.0</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> */</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">public</span> <span style="color:#0000ff;">class</span> User <span style="color:#0000ff;">implements</span> Serializable {</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> </pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#008000;">/**</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * @author Hoojo</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> */</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#0000ff;">private</span> <span style="color:#0000ff;">static</span> <span style="color:#0000ff;">final</span> <span style="color:#0000ff;">long</span> serialVersionUID = 8606788203814942679L;</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> </pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#008000;">//@Field</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#0000ff;">private</span> <span style="color:#0000ff;">int</span> id;</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> @Field</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#0000ff;">private</span> String name;</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> @Field</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#0000ff;">private</span> <span style="color:#0000ff;">int</span> age;</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> </pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#008000;">/**</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * 可以给某个属性重命名,likes就是solr index的属性;在solrIndex中将显示like为likes</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> */</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> @Field(<span style="color:#006080;">"likes"</span>)</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#0000ff;">private</span> String[] like;</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> @Field</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#0000ff;">private</span> String address;</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> @Field</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#0000ff;">private</span> String sex;</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> @Field</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#0000ff;">private</span> String remark;</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">int</span> getId() {</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#0000ff;">return</span> id;</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> }</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> </pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#008000;">//setter 方法上面也可以</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> @Field</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">void</span> setId(<span style="color:#0000ff;">int</span> id) {</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#0000ff;">this</span>.id = id;</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> }</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#0000ff;">public</span> String getName() {</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#0000ff;">return</span> name;</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> }</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#008000;">//getter、setter</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> </pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> @Override</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#0000ff;">public</span> String toString() {</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#0000ff;">return</span> <span style="color:#0000ff;">this</span>.id + <span style="color:#006080;">"#"</span> + <span style="color:#0000ff;">this</span>.name + <span style="color:#006080;">"#"</span> + <span style="color:#0000ff;">this</span>.age + <span style="color:#006080;">"#"</span> + <span style="color:#0000ff;">this</span>.like + <span style="color:#006080;">"#"</span> + <span style="color:#0000ff;">this</span>.address + <span style="color:#006080;">"#"</span> + <span style="color:#0000ff;">this</span>.sex + <span style="color:#006080;">"#"</span> + <span style="color:#0000ff;">this</span>.remark;</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> }</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">}</pre> </div> </div> <p> </p> <p>测试类代码如下 </p> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">package</span> com.hoo.test;</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> </pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">import</span> org.apache.solr.client.solrj.beans.DocumentObjectBinder;</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">import</span> org.apache.solr.common.SolrDocument;</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">import</span> org.apache.solr.common.SolrDocumentList;</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">import</span> org.apache.solr.common.SolrInputDocument;</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">import</span> org.apache.solr.common.SolrInputField;</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">import</span> org.junit.Test;</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">import</span> com.hoo.entity.User;</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> </pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;">/**</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * <b>function:</b>SolrInputDocument implements Map, Iterable</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * @author hoojo</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * @createDate 2011-10-19 下午03:54:54</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * @file SolrInputDocumentTest.java</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * @package com.hoo.test</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * @project SolrExample</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * @blog http://blog.csdn.net/IBM_hoojo</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * @email hoojo_@126.com</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * @version 1.0</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> */</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#0000ff;">public</span> <span style="color:#0000ff;">class</span> SolrInputDocumentTest {</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> </pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">final</span> <span style="color:#0000ff;">void</span> fail(Object o) {</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> System.out.println(o);</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> }</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> </pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#008000;">/**</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * <b>function:</b> 创建SolrInputDocument</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * @author hoojo</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * @createDate 2011-10-21 下午03:38:20</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> */</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> @Test</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">void</span> createDoc() {</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> SolrInputDocument doc = <span style="color:#0000ff;">new</span> SolrInputDocument();</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> doc.addField(<span style="color:#006080;">"id"</span>, System.currentTimeMillis());</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> doc.addField(<span style="color:#006080;">"name"</span>, <span style="color:#006080;">"SolrInputDocument"</span>);</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> doc.addField(<span style="color:#006080;">"age"</span>, 22, 2.0f);</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> </pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> doc.addField(<span style="color:#006080;">"like"</span>, <span style="color:#0000ff;">new</span> String[] { <span style="color:#006080;">"music"</span>, <span style="color:#006080;">"book"</span>, <span style="color:#006080;">"sport"</span> });</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> </pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> doc.put(<span style="color:#006080;">"address"</span>, <span style="color:#0000ff;">new</span> SolrInputField(<span style="color:#006080;">"guangzhou"</span>));</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> </pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> doc.setField(<span style="color:#006080;">"sex"</span>, <span style="color:#006080;">"man"</span>);</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> doc.setField(<span style="color:#006080;">"remark"</span>, <span style="color:#006080;">"china people"</span>, 2.0f);</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> </pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> fail(doc);</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> }</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> </pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#008000;">/**</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * <b>function:</b> 利用DocumentObjectBinder对象将SolrInputDocument 和 User对象相互转换</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * @author hoojo</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * @createDate 2011-10-21 下午03:38:40</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> */</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> @Test</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">void</span> docAndBean4Binder() {</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> SolrDocument doc = <span style="color:#0000ff;">new</span> SolrDocument();</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> doc.addField(<span style="color:#006080;">"id"</span>, 456);</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> doc.addField(<span style="color:#006080;">"name"</span>, <span style="color:#006080;">"SolrInputDocument"</span>);</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> </pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> doc.addField(<span style="color:#006080;">"likes"</span>, <span style="color:#0000ff;">new</span> String[] { <span style="color:#006080;">"music"</span>, <span style="color:#006080;">"book"</span>, <span style="color:#006080;">"sport"</span> });</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> </pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> doc.put(<span style="color:#006080;">"address"</span>, <span style="color:#006080;">"guangzhou"</span>);</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> </pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> doc.setField(<span style="color:#006080;">"sex"</span>, <span style="color:#006080;">"man"</span>);</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> doc.setField(<span style="color:#006080;">"remark"</span>, <span style="color:#006080;">"china people"</span>);</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> </pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> DocumentObjectBinder binder = <span style="color:#0000ff;">new</span> DocumentObjectBinder();</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> </pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> User user = <span style="color:#0000ff;">new</span> User();</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> user.setId(222);</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> user.setName(<span style="color:#006080;">"JavaBean"</span>);</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> user.setLike(<span style="color:#0000ff;">new</span> String[] { <span style="color:#006080;">"music"</span>, <span style="color:#006080;">"book"</span>, <span style="color:#006080;">"sport"</span> });</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> user.setAddress(<span style="color:#006080;">"guangdong"</span>);</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> </pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> fail(doc);</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#008000;">// User ->> SolrInputDocument</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> fail(binder.toSolrInputDocument(user));</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#008000;">// SolrDocument ->> User</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> fail(binder.getBean(User.<span style="color:#0000ff;">class</span>, doc));</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> </pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> SolrDocumentList list = <span style="color:#0000ff;">new</span> SolrDocumentList();</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> list.add(doc);</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> list.add(doc);</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#008000;">//SolrDocumentList ->> List</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> fail(binder.getBeans(User.<span style="color:#0000ff;">class</span>, list));</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> }</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> </pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#008000;">/**</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * <b>function:</b> SolrInputDocument的相关方法</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * @author hoojo</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> * @createDate 2011-10-21 下午03:44:30</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"><span style="color:#008000;"> */</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> @Test</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">void</span> docMethod() {</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> SolrInputDocument doc = <span style="color:#0000ff;">new</span> SolrInputDocument();</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> doc.addField(<span style="color:#006080;">"id"</span>, System.currentTimeMillis());</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> doc.addField(<span style="color:#006080;">"name"</span>, <span style="color:#006080;">"SolrInputDocument"</span>);</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> doc.addField(<span style="color:#006080;">"age"</span>, 23, 1.0f);</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> doc.addField(<span style="color:#006080;">"age"</span>, 22, 2.0f);</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> doc.addField(<span style="color:#006080;">"age"</span>, 24, 0f);</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> </pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> fail(doc.entrySet());</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> fail(doc.get(<span style="color:#006080;">"age"</span>));</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> <span style="color:#008000;">//排名有用,类似百度竞价排名</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> doc.setDocumentBoost(2.0f);</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> fail(doc.getDocumentBoost());</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> fail(doc.getField(<span style="color:#006080;">"name"</span>));</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> fail(doc.getFieldNames());<span style="color:#008000;">//keys</span></pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> fail(doc.getFieldValues(<span style="color:#006080;">"age"</span>));</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> fail(doc.getFieldValues(<span style="color:#006080;">"id"</span>));</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> fail(doc.values());</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;"> }</pre> <pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:10pt;border-left-style:none;overflow:visible;padding-top:0px;">}</pre>转自: <a href="/misc/goto?guid=4959517665386055413" target="_blank">http://www.cnblogs.com/hoojo/archive/2011/10/21/2220431.html</a>