solr与lucene
Solr最显著的特点就是其分布式,不然的话跟Lucene也就没多大区别了,那么什么时候我们会用到分布式搜索呢?那就是当索引过多的时候,多到了在一台服务器上存放时会因此而影响到搜索速度,这个时候就可以考虑将索引划分成多个分片,搜索时在多个分片上进行搜索,最后将多个搜索结果进行合并。
接下来,我们将在一台服务器上使用solr-3.6.0为例来体验一下Solr的分布式搜索特性。在一台服务器上,我们将创建两个端口不一样的Solr服务,以此来模拟其分布式搜索功能。
将apache-solr-3.6.0解压到/usr/local目录下,步骤为:
1、做一个拷贝
cd apache-solr-3.6.0
cp -r example example7574
2、改变example7574端口号为7574
perl -pi -e s/8983/7574/g example7574/etc/jetty.xml example7574/exampledocs/post.sh
3、启动端口为8983的jetty服务
cd example
java -server -jar start.jar
4、启动端口为7574的jetty服务
cd example7574
java -server -jar start.jar
5、为端口为8983的服务创建索引
cd example/exampledocs
./post.sh [a-m]*.xml
6、为端口为7574的服务创建索引
cd http://www.cnblogs.com/example7574/exampledocs
./post.sh [n-z]*.xml
7、通过浏览器或curl命令来进行分布式搜索
curl ‘http://localhost:8983/solr/select?shards=localhost:8983/solr,localhost:7574/solr&indent=true&q=ipod+solr’
搜索结果如下(共4条结果):
<?xml version=”1.0″ encoding=”UTF-8″?>
<response>
<lst name=”responseHeader”>
<int name=”status”>0</int>
<int name=”QTime”>87</int>
<lst name=”params”>
<str name=”indent”>true</str>
<str name=”q”>ipod solr</str>
<str name=”shards”>localhost:8983/solr,localhost:7574/solr</str>
</lst>
</lst>
<result name=”response” numFound=”4″ start=”0″>
<doc>
<str name=”id”>IW-02</str>
<str name=”name”>iPod & iPod Mini USB 2.0 Cable</str>
<str name=”manu”>Belkin</str>
<arr name=”cat”>
<str>electronics</str>
<str>connector</str>
</arr>
<arr name=”features”>
<str>car power adapter for iPod, white</str>
</arr>
<float name=”weight”>2.0</float>
<float name=”price”>11.5</float>
<str name=”price_c”>11.50,USD</str>
<int name=”popularity”>1</int>
<bool name=”inStock”>false</bool>
<str name=”store”>37.7752,-122.4232</str>
<date name=”manufacturedate_dt”>2006-02-14T23:55:59Z</date>
</doc>
<doc>
<str name=”id”>F8V7067-APL-KIT</str>
<str name=”name”>Belkin Mobile Power Cord for iPod w/ Dock</str>
<str name=”manu”>Belkin</str>
<arr name=”cat”>
<str>electronics</str>
<str>connector</str>
</arr>
<arr name=”features”>
<str>car power adapter, white</str>
</arr>
<float name=”weight”>4.0</float>
<float name=”price”>19.95</float>
<str name=”price_c”>19.95,USD</str>
<int name=”popularity”>1</int>
<bool name=”inStock”>false</bool>
<str name=”store”>45.17614,-93.87341</str>
<date name=”manufacturedate_dt”>2005-08-01T16:30:25Z</date>
</doc>
<doc>
<str name=”id”>SOLR1000</str>
<str name=”name”>Solr, the Enterprise Search Server</str>
<str name=”manu”>Apache Software Foundation</str>
<arr name=”cat”>
<str>software</str>
<str>search</str>
</arr>
<arr name=”features”>
<str>Advanced Full-Text Search Capabilities using Lucene</str>
<str>Optimized for High Volume Web Traffic</str>
<str>Standards Based Open Interfaces – XML and HTTP</str>
<str>Comprehensive HTML Administration Interfaces</str>
<str>Scalability – Efficient Replication to other Solr Search Servers</str>
<str>Flexible and Adaptable with XML configuration and Schema</str>
<str>Good unicode support: h茅llo (hello with an accent over the e)</str>
</arr>
<float name=”price”>0.0</float>
<str name=”price_c”>0,USD</str>
<int name=”popularity”>10</int>
<bool name=”inStock”>true</bool>
<date name=”incubationdate_dt”>2006-01-17T00:00:00Z</date>
</doc>
<doc>
<str name=”id”>MA147LL/A</str>
<str name=”name”>Apple 60 GB iPod with Video Playback Black</str>
<str name=”manu”>Apple Computer Inc.</str>
<arr name=”cat”>
<str>electronics</str>
<str>music</str>
</arr>
<arr name=”features”>
<str>iTunes, Podcasts, Audiobooks</str>
<str>Stores up to 15,000 songs, 25,000 photos, or 150 hours of video</str>
<str>2.5-inch, 320×240 color TFT LCD display with LED backlight</str>
<str>Up to 20 hours of battery life</str>
<str>Plays AAC, MP3, WAV, AIFF, Audible, Apple Lossless, H.264 video</str>
<str>Notes, Calendar, Phone book, Hold button, Date display, Photo wallet, Built-in games, JPEG photo playback, Upgradeable firmware, USB 2.0 compatibility, Playback speed control, Rechargeable capability, Battery level indication</str>
</arr>
<str name=”includes”>earbud headphones, USB cable</str>
<float name=”weight”>5.5</float>
<float name=”price”>399.0</float>
<str name=”price_c”>399.00,USD</str>
<int name=”popularity”>10</int>
<bool name=”inStock”>true</bool>
<str name=”store”>37.7752,-100.0232</str>
<date name=”manufacturedate_dt”>2005-10-12T08:00:00Z</date>
</doc>
</result>
</response>
浙公网安备 33010602011771号