Solrで検索する

検索データの準備

チュートリアル(http://lucene.apache.org/solr/tutorial.html)に従い、下記2件のデータ(*.xml)をpost.jarを使いインポートしてみた。

$ java -jar exampledocs/post.jar exampledocs/solr.xml exampledocs/monitor.xml 
SimplePostTool: version 1.4
SimplePostTool: POSTing files to http://localhost:8983/solr/update..
SimplePostTool: POSTing file solr.xml
SimplePostTool: POSTing file monitor.xml
SimplePostTool: COMMITting Solr index changes..

全サンプルデータにIndexをつける

チュートリアルに従うと、以下のコマンドで、インデックスをすべてのサンプルデータにつけられる。
...ってあれ、さっきのインポートと同じじゃ...。

$ java -jar exampledocs/post.jar exampledocs/*.xml 
SimplePostTool: version 1.4
SimplePostTool: POSTing files to http://localhost:8983/solr/update..
SimplePostTool: POSTing file gb18030-example.xml
SimplePostTool: POSTing file hd.xml
SimplePostTool: POSTing file ipod_other.xml
SimplePostTool: POSTing file ipod_video.xml
SimplePostTool: POSTing file mem.xml
SimplePostTool: POSTing file monitor.xml
SimplePostTool: POSTing file monitor2.xml
SimplePostTool: POSTing file mp500.xml
SimplePostTool: POSTing file sd500.xml
SimplePostTool: POSTing file solr.xml
SimplePostTool: POSTing file utf8-example.xml
SimplePostTool: POSTing file vidcard.xml
SimplePostTool: COMMITting Solr index changes..

検索してみる

"Make a Query"インタフェースを使って、管理画面(Admin screen)から検索してみる。
検索のテキストボックスに"solr"など入れてみて、"search"ボタンを押す。
すると、検索結果がxml形式で返る。この検索結果には、"solr"をキーワードとして含むエントリが返される。

<response>
<lst name="responseHeader">
<int name="status">0</int>
<int name="QTime">0</int>
<lst name="params">
<str name="indent">on</str>
<str name="start">0</str>
<str name="q">solr</str>
<str name="version">2.2</str>
<str name="rows">10</str>
</lst>
</lst>
<result name="response" numFound="1" start="0">
<doc>
<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&#233;llo (hello with an accent over the e)
</str>
</arr>
<str name="id">SOLR1000</str>
<bool name="inStock">true</bool>
<date name="incubationdate_dt">2006-01-17T00:00:00Z</date>
<str name="manu">Apache Software Foundation</str>
<str name="name">Solr, the Enterprise Search Server</str>
<int name="popularity">10</int>
<float name="price">0.0</float>
</doc>
</result>
</response>

詳細検索条件を指定してみる

キーワードだけ指定して検索
  • 検索例
    • video
  • 検索結果
    • に、"video"が含まれるエントリである、idが"MA147LL/A", "EN7800GTX/2DHTV/256M", "100-435805"の3つが返ってきている。
<response>
<lst name="responseHeader">
<int name="status">0</int>
<int name="QTime">1</int>
<lst name="params">
<str name="indent">on</str>
<str name="start">0</str>
<str name="q">video</str>
<str name="version">2.2</str>
<str name="rows">10</str>
</lst>
</lst>
<result name="response" numFound="3" start="0">
<doc>
<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, 320x240 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="id">MA147LL/A</str>
<bool name="inStock">true</bool>
<str name="includes">earbud headphones, USB cable</str>
<str name="manu">Apple Computer Inc.</str>
<date name="manufacturedate_dt">2005-10-12T08:00:00Z</date>
<str name="name">Apple 60 GB iPod with Video Playback Black</str>
<int name="popularity">10</int>
<float name="price">399.0</float>
<str name="store">37.7752,-100.0232</str>
<float name="weight">5.5</float>
</doc>
<doc>
<arr name="cat">
<str>electronics</str>
<str>graphics card</str>
</arr>
<arr name="features">
<str>NVIDIA GeForce 7800 GTX GPU/VPU clocked at 486MHz</str>
<str>256MB GDDR3 Memory clocked at 1.35GHz</str>
<str>PCI Express x16</str>
<str>Dual DVI connectors, HDTV out, video input</str>
<str>OpenGL 2.0, DirectX 9.0</str>
</arr>
<str name="id">EN7800GTX/2DHTV/256M</str>
<bool name="inStock">false</bool>
<str name="manu">ASUS Computer Inc.</str>
<date name="manufacturedate_dt">2006-02-13T00:00:00Z</date>
<str name="name">ASUS Extreme N7800GTX/2DHTV (256 MB)</str>
<int name="popularity">7</int>
<float name="price">479.95</float>
<str name="store">40.7143,-74.006</str>
<float name="weight">16.0</float>
</doc>
<doc>
<arr name="cat">
<str>electronics</str>
<str>graphics card</str>
</arr>
<arr name="features">
<str>ATI RADEON X1900 GPU/VPU clocked at 650MHz</str>
<str>512MB GDDR3 SDRAM clocked at 1.55GHz</str>
<str>PCI Express x16</str>
<str>dual DVI, HDTV, svideo, composite out</str>
<str>OpenGL 2.0, DirectX 9.0</str>
</arr>
<str name="id">100-435805</str>
<bool name="inStock">false</bool>
<str name="manu">ATI Technologies</str>
<date name="manufacturedate_dt">2006-02-13T00:00:00Z</date>
<str name="name">ATI Radeon X1900 XTX 512 MB PCIE Video Card</str>
<int name="popularity">7</int>
<float name="price">649.99</float>
<str name="store">40.7143,-74.006</str>
<float name="weight">48.0</float>
</doc>
</result>
</response>
名前にキーワードが含まれるものだけ検索
  • 検索例
    • name:video
  • 検索結果
    • に"video"が含まれるエントリである、idが"MA147LL/A"と、"100-435805"の2つが返ってきている。
<response>
<lst name="responseHeader">
<int name="status">0</int>
<int name="QTime">0</int>
<lst name="params">
<str name="indent">on</str>
<str name="start">0</str>
<str name="q">name:video</str>
<str name="version">2.2</str>
<str name="rows">10</str>
</lst>
</lst>
<result name="response" numFound="2" start="0">
<doc>
<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, 320x240 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="id">MA147LL/A</str>
<bool name="inStock">true</bool>
<str name="includes">earbud headphones, USB cable</str>
<str name="manu">Apple Computer Inc.</str>
<date name="manufacturedate_dt">2005-10-12T08:00:00Z</date>
<str name="name">Apple 60 GB iPod with Video Playback Black</str>
<int name="popularity">10</int>
<float name="price">399.0</float>
<str name="store">37.7752,-100.0232</str>
<float name="weight">5.5</float>
</doc>
<doc>
<arr name="cat">
<str>electronics</str>
<str>graphics card</str>
</arr>
<arr name="features">
<str>ATI RADEON X1900 GPU/VPU clocked at 650MHz</str>
<str>512MB GDDR3 SDRAM clocked at 1.55GHz</str>
<str>PCI Express x16</str>
<str>dual DVI, HDTV, svideo, composite out</str>
<str>OpenGL 2.0, DirectX 9.0</str>
</arr>
<str name="id">100-435805</str>
<bool name="inStock">false</bool>
<str name="manu">ATI Technologies</str>
<date name="manufacturedate_dt">2006-02-13T00:00:00Z</date>
<str name="name">ATI Radeon X1900 XTX 512 MB PCIE Video Card</str>
<int name="popularity">7</int>
<float name="price">649.99</float>
<str name="store">40.7143,-74.006</str>
<float name="weight">48.0</float>
</doc>
</result>
</response>
キーワードを含み、且つプロパティが特定条件のものだけ検索
  • 検索例
    • 以下の例では、"price"が"400"までのものを検索する
    • +video +price:[* TO 400]
  • 検索結果
    • 〜が400迄の物(399.0の物)だけ返ってきている。
<response>
<lst name="responseHeader">
<int name="status">0</int>
<int name="QTime">1</int>
<lst name="params">
<str name="indent">on</str>
<str name="start">0</str>
<str name="q">+video +price:[* TO 400]</str>
<str name="version">2.2</str>
<str name="rows">10</str>
</lst>
</lst>
<result name="response" numFound="1" start="0">
<doc>
<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, 320x240 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="id">MA147LL/A</str>
<bool name="inStock">true</bool>
<str name="includes">earbud headphones, USB cable</str>
<str name="manu">Apple Computer Inc.</str>
<date name="manufacturedate_dt">2005-10-12T08:00:00Z</date>
<str name="name">Apple 60 GB iPod with Video Playback Black</str>
<int name="popularity">10</int>
<float name="price">399.0</float>
<str name="store">37.7752,-100.0232</str>
<float name="weight">5.5</float>
</doc>
</result>
</response>

検索クエリの文法

検索のクエリ文法は以下で確認できる。
http://wiki.apache.org/solr/SolrQuerySyntax