<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>4.10. マイクロブログ検索システムの作成 — groonga v3.0.5 documentation</title> <link rel="stylesheet" href="../_static/groonga.css" type="text/css" /> <link rel="stylesheet" href="../_static/pygments.css" type="text/css" /> <script type="text/javascript"> var DOCUMENTATION_OPTIONS = { URL_ROOT: '../', VERSION: '3.0.5', COLLAPSE_INDEX: false, FILE_SUFFIX: '.html', HAS_SOURCE: true }; </script> <script type="text/javascript" src="../_static/jquery.js"></script> <script type="text/javascript" src="../_static/underscore.js"></script> <script type="text/javascript" src="../_static/doctools.js"></script> <link rel="shortcut icon" href="../_static/favicon.ico"/> <link rel="top" title="groonga v3.0.5 documentation" href="../index.html" /> <link rel="up" title="4. Tutorial" href="../tutorial.html" /> <link rel="next" title="4.11. クエリ拡張" href="query_expansion.html" /> <link rel="prev" title="4.9. 全文検索の語彙表に対する追加情報" href="lexicon.html" /> </head> <body> <div class="header"> <h1 class="title"> <a id="top-link" href="../index.html"> <span class="project">groonga</span> <span class="separator">-</span> <span class="description">An open-source fulltext search engine and column store.</span> </a> </h1> <div class="other-language-links"> <ul> <li><a href="../../../ja/html/tutorial/micro_blog.html"><img src="../_static/jp.png" alt="日本語">日本語版はこちら</a></li> </ul> </div> </div> <div class="related"> <h3>Navigation</h3> <ul> <li class="right" style="margin-right: 10px"> <a href="../genindex.html" title="General Index" accesskey="I">index</a></li> <li class="right" > <a href="query_expansion.html" title="4.11. クエリ拡張" accesskey="N">next</a> |</li> <li class="right" > <a href="lexicon.html" title="4.9. 全文検索の語彙表に対する追加情報" accesskey="P">previous</a> |</li> <li><a href="../index.html">groonga v3.0.5 documentation</a> »</li> <li><a href="../tutorial.html" accesskey="U">4. Tutorial</a> »</li> </ul> </div> <div class="document"> <div class="documentwrapper"> <div class="bodywrapper"> <div class="body"> <div class="section" id="id1"> <h1>4.10. マイクロブログ検索システムの作成<a class="headerlink" href="#id1" title="Permalink to this headline">¶</a></h1> <p>これまで学んだgroongaの機能を用いて、マイクロブログの検索システムを作成してみましょう。マイクロブログとは、Twitterのような短いメッセージを投稿するブログです。</p> <div class="section" id="id2"> <h2>4.10.1. テーブルの作成<a class="headerlink" href="#id2" title="Permalink to this headline">¶</a></h2> <p>まずは、テーブルを作成します。</p> <div class="highlight-none"><div class="highlight"><pre>table_create --name Users --flags TABLE_HASH_KEY --key_type ShortText table_create --name Comments --flags TABLE_HASH_KEY --key_type ShortText table_create --name HashTags --flags TABLE_HASH_KEY --key_type ShortText table_create --name Bigram --flags TABLE_PAT_KEY|KEY_NORMALIZE --key_type ShortText --default_tokenizer TokenBigram table_create --name GeoIndex --flags TABLE_PAT_KEY --key_type WGS84GeoPoint column_create --table Users --name name --flags COLUMN_SCALAR --type ShortText column_create --table Users --name follower --flags COLUMN_VECTOR --type Users column_create --table Users --name favorites --flags COLUMN_VECTOR --type Comments column_create --table Users --name location --flags COLUMN_SCALAR --type WGS84GeoPoint column_create --table Users --name location_str --flags COLUMN_SCALAR --type ShortText column_create --table Users --name description --flags COLUMN_SCALAR --type ShortText column_create --table Users --name followee --flags COLUMN_INDEX --type Users --source follower column_create --table Comments --name comment --flags COLUMN_SCALAR --type ShortText column_create --table Comments --name last_modified --flags COLUMN_SCALAR --type Time column_create --table Comments --name replied_to --flags COLUMN_SCALAR --type Comments column_create --table Comments --name replied_users --flags COLUMN_VECTOR --type Users column_create --table Comments --name hash_tags --flags COLUMN_VECTOR --type HashTags column_create --table Comments --name location --flags COLUMN_SCALAR --type WGS84GeoPoint column_create --table Comments --name posted_by --flags COLUMN_SCALAR --type Users column_create --table Comments --name favorited_by --flags COLUMN_INDEX --type Users --source favorites column_create --table HashTags --name hash_index --flags COLUMN_INDEX --type Comments --source hash_tags column_create --table Bigram --name users_index --flags COLUMN_INDEX|WITH_POSITION|WITH_SECTION --type Users --source name,location_str,description column_create --table Bigram --name comment_index --flags COLUMN_INDEX|WITH_POSITION --type Comments --source comment column_create --table GeoIndex --name users_location --type Users --flags COLUMN_INDEX --source location column_create --table GeoIndex --name comments_location --type Comments --flags COLUMN_INDEX --source location </pre></div> </div> <div class="section" id="users"> <h3>4.10.1.1. Usersテーブル<a class="headerlink" href="#users" title="Permalink to this headline">¶</a></h3> <p>ユーザーの名前や自己紹介文、フォローしているユーザー一覧など、ユーザー情報を格納するためのテーブルです。</p> <dl class="docutils"> <dt><tt class="docutils literal"><span class="pre">_key</span></tt></dt> <dd>ユーザーID</dd> <dt><tt class="docutils literal"><span class="pre">name</span></tt></dt> <dd>ユーザー名</dd> <dt><tt class="docutils literal"><span class="pre">follower</span></tt></dt> <dd>フォローしているユーザーの一覧</dd> <dt><tt class="docutils literal"><span class="pre">favorites</span></tt></dt> <dd>お気に入りのコメント一覧</dd> <dt><tt class="docutils literal"><span class="pre">location</span></tt></dt> <dd>ユーザーの現在地(緯度経度座標)</dd> <dt><tt class="docutils literal"><span class="pre">location_str</span></tt></dt> <dd>ユーザーの現在地(文字列)</dd> <dt><tt class="docutils literal"><span class="pre">description</span></tt></dt> <dd>ユーザーの自己紹介</dd> <dt><tt class="docutils literal"><span class="pre">followee</span></tt></dt> <dd>Usersテーブルのfollowerカラムに対するインデックス。 このインデックスを作ることで、あるユーザーをフォローしているユーザーを検索できるようになります。</dd> </dl> </div> <div class="section" id="comments"> <h3>4.10.1.2. Commentsテーブル<a class="headerlink" href="#comments" title="Permalink to this headline">¶</a></h3> <p>コメント内容や投稿日時、返信先情報など、コメントに関する内容を格納するテーブルです。</p> <dl class="docutils"> <dt><tt class="docutils literal"><span class="pre">_key</span></tt></dt> <dd>コメントID</dd> <dt><tt class="docutils literal"><span class="pre">comment</span></tt></dt> <dd>コメント内容</dd> <dt><tt class="docutils literal"><span class="pre">last_modified</span></tt></dt> <dd>投稿日時</dd> <dt><tt class="docutils literal"><span class="pre">replied_to</span></tt></dt> <dd>返信元のコメント内容</dd> <dt><tt class="docutils literal"><span class="pre">replied_users</span></tt></dt> <dd>返信先のユーザーの一覧</dd> <dt><tt class="docutils literal"><span class="pre">hash_tags</span></tt></dt> <dd>コメントのハッシュタグの一覧</dd> <dt><tt class="docutils literal"><span class="pre">location</span></tt></dt> <dd>投稿場所(緯度経度座標のため)</dd> <dt><tt class="docutils literal"><span class="pre">posted_by</span></tt></dt> <dd>コメントを書いたユーザー</dd> <dt><tt class="docutils literal"><span class="pre">favorited_by</span></tt></dt> <dd>Usersテーブルのfavoritesカラムに対するインデックス。 このインデックスを作ることで、指定したコメントを誰がお気に入りに入れているのかを検索できるようになります。</dd> </dl> </div> <div class="section" id="hashtags"> <h3>4.10.1.3. HashTagsテーブル<a class="headerlink" href="#hashtags" title="Permalink to this headline">¶</a></h3> <p>コメントのハッシュタグを一覧で保存するためのテーブルです。</p> <dl class="docutils"> <dt><tt class="docutils literal"><span class="pre">_key</span></tt></dt> <dd>ハッシュタグ</dd> <dt><tt class="docutils literal"><span class="pre">hash_index</span></tt></dt> <dd>「Comments.hash_tags」のインデックス。 このインデックスを作ることで、指定したハッシュタグのついているコメントの一覧を出すことが出来るようになります。</dd> </dl> </div> <div class="section" id="bigram"> <h3>4.10.1.4. Bigramテーブル<a class="headerlink" href="#bigram" title="Permalink to this headline">¶</a></h3> <p>ユーザー情報・コメントで全文検索が出来るようにするためのインデックスを格納するテーブルです。</p> <dl class="docutils"> <dt><tt class="docutils literal"><span class="pre">_key</span></tt></dt> <dd>単語</dd> <dt><tt class="docutils literal"><span class="pre">users_index</span></tt></dt> <dd>ユーザー情報のインデックス。 このカラムは、ユーザー名「Users.name」、現在地「Users.location_str」、自己紹介文「Users.description」のインデックスになっています。</dd> <dt><tt class="docutils literal"><span class="pre">comment_index</span></tt></dt> <dd>コメント内容「Comments.comment」のインデックス</dd> </dl> </div> <div class="section" id="geoindex-table"> <h3>4.10.1.5. GeoIndex table<a class="headerlink" href="#geoindex-table" title="Permalink to this headline">¶</a></h3> <p>This is the table which stores indexes of location column to search geo location effectively.</p> <dl class="docutils"> <dt><tt class="docutils literal"><span class="pre">users_location</span></tt></dt> <dd>Indexes of location column for Users table</dd> <dt><tt class="docutils literal"><span class="pre">comments_location</span></tt></dt> <dd>Indexes of location column for Comments table</dd> </dl> </div> </div> <div class="section" id="id3"> <h2>4.10.2. データのロード<a class="headerlink" href="#id3" title="Permalink to this headline">¶</a></h2> <p>つづいて、テスト用データをロードします。</p> <div class="highlight-none"><div class="highlight"><pre>load --table Users [ { "_key": "daijiro", "name": "hsiomaneki", "follower": ["tasukuchan"], "favorites": [], "location": "127678039x502643091", "location_str": "神奈川県", "description": "groonga developer" }, { "_key": "tasukuchan", "name": "グニャラくん", "follower": ["daijiro","OffGao"], "favorites": ["daijiro:1","OffGao:1"], "location": "128423343x502929252", "location_str": "東京都渋谷区", "description": "エロいおっさん" }, { "_key": "OffGao", "name": "OffGao", "follower": ["tasukuchan","daijiro"], "favorites": ["tasukuchan:1","daijiro:1"], "location": "128544408x502801502", "location_str": "東京都中野区", "description": "がおがお" } ] load --table Comments [ { "_key": "daijiro:1", "comment": "マイクロブログ作ってみました(甘栗むいちゃいました的な感じで)。", "last_modified": "2010/03/17 12:05:00", "posted_by": "daijiro", }, { "_key": "tasukuchan:1", "comment": "初の書き込み。テストテスト。", "last_modified": "2010/03/17 12:00:00", "posted_by": "tasukuchan", }, { "_key": "daijiro:2", "comment": "@tasukuchan ようこそ!!!", "last_modified": "2010/03/17 12:05:00", "replied_to": "tasukuchan:1", "replied_users": ["tasukuchan"], "posted_by": "daijiro", }, { "_key": "tasukuchan:2", "comment": "@daijiro ありがとう!", "last_modified": "2010/03/17 13:00:00", "replied_to": "daijiro:2", "replied_users": ["daijiro"], "posted_by": "tasukuchan", }, { "_key": "tasukuchan:3", "comment": "groongaなう #groonga", "last_modified": "2010/03/17 14:00:00", "hash_tags": ["groonga"], "location": "127972422x503117107", "posted_by": "tasukuchan", }, { "_key": "tasukuchan:4", "comment": "groonga開発合宿のため羽田空港に来ました! #groonga #travel", "last_modified": "2010/03/17 14:05:00", "hash_tags": ["groonga", "travel"], "location": "127975798x502919856", "posted_by": "tasukuchan", }, { "_key": "OffGao:1", "comment": "@daijiro @tasukuchan 登録してみましたよー!", "last_modified": "2010/03/17 15:00:00", "replied_users": ["daijiro", "tasukuchan"], "location": "128551935x502796433", "posted_by": "OffGao", } { "_key": "OffGao:2", "comment": "中野ブロードウェイなうなう", "last_modified": "2010/03/17 15:05:00", "location": "128551935x502796434", "posted_by": "OffGao", } ] </pre></div> </div> <p>Usersテーブルのfollowerカラムとfavoritesカラム、そしてCommentsテーブルのreplied_usersカラムは、ベクターカラムです。そのため、これらのカラムは配列で値を指定します。</p> <p>Usersテーブルのlocationカラムと、Commentsテーブルのlocationカラムは、GeoPoint型です。この型での値の指定は、"[緯度]x[経度]"と記述して指定します。</p> <p>Commentsテーブルのlast_modifiedカラムは、Time型です。この型での値を指定する方法は2つあります。 1つ目の方法は、1970年1月1日0時0分0秒からの経過秒数の値を直接指定する方法です。このとき、小数部分を指定することでマイクロ秒数での指定が可能です。指定した値は、データのロードの際にマイクロ秒を単位とする整数値に変換後、格納されます。 2つ目の方法は、文字列で日時と時刻を指定する方法です。"年/月/日 時:分:秒"というフォーマットで記述することで、データロードの際に文字列からキャストされ、マイクロ秒数の値が格納されます。</p> </div> <div class="section" id="id4"> <h2>4.10.3. 検索<a class="headerlink" href="#id4" title="Permalink to this headline">¶</a></h2> <p>それでは、実際に検索をしてみましょう。</p> <div class="section" id="id5"> <h3>4.10.3.1. キーワードでユーザー検索<a class="headerlink" href="#id5" title="Permalink to this headline">¶</a></h3> <p>ここでは、 <a class="reference internal" href="match_columns.html"><em>match_columnsパラメータ</em></a> で扱った、複数カラムを対象とした検索を行います。 指定された文字列で、ユーザー名・現在地・自己紹介文を対象に検索をします。</p> <p>Execution example:</p> <div class="highlight-none"><div class="highlight"><pre>select --table Users --match_columns name,location_str,description --query 東京 --output_columns _key,name # [[0, 1337566253.89858, 0.000355720520019531], true] # [[0, 1337566253.89858, 0.000355720520019531], true] # [[0, 1337566253.89858, 0.000355720520019531], true] # [[0, 1337566253.89858, 0.000355720520019531], true] # [[0, 1337566253.89858, 0.000355720520019531], true] # [[0, 1337566253.89858, 0.000355720520019531], true] # [[0, 1337566253.89858, 0.000355720520019531], true] # [[0, 1337566253.89858, 0.000355720520019531], true] # [[0, 1337566253.89858, 0.000355720520019531], true] # [[0, 1337566253.89858, 0.000355720520019531], true] # [[0, 1337566253.89858, 0.000355720520019531], true] # [[0, 1337566253.89858, 0.000355720520019531], true] # [[0, 1337566253.89858, 0.000355720520019531], true] # [[0, 1337566253.89858, 0.000355720520019531], true] # [[0, 1337566253.89858, 0.000355720520019531], true] # [[0, 1337566253.89858, 0.000355720520019531], true] # [[0, 1337566253.89858, 0.000355720520019531], true] # [[0, 1337566253.89858, 0.000355720520019531], true] # [[0, 1337566253.89858, 0.000355720520019531], true] # [[0, 1337566253.89858, 0.000355720520019531], true] # [[0, 1337566253.89858, 0.000355720520019531], true] # [[0, 1337566253.89858, 0.000355720520019531], true] # [[0, 1337566253.89858, 0.000355720520019531], true] # [[0, 1337566253.89858, 0.000355720520019531], true] # [[0, 1337566253.89858, 0.000355720520019531], true] # [[0, 1337566253.89858, 0.000355720520019531], 3] # [[0, 1337566253.89858, 0.000355720520019531], 8] # [ # [ # 0, # 1337566253.89858, # 0.000355720520019531 # ], # [ # [ # [ # 2 # ], # [ # [ # "_key", # "ShortText" # ], # [ # "name", # "ShortText" # ] # ], # [ # "tasukuchan", # "グニャラくん" # ], # [ # "OffGao", # "OffGao" # ] # ] # ] # ] </pre></div> </div> <p>「東京」をキーワードにユーザー検索した結果、東京都に住んでいる「グニャラくん」と「OffGao」がヒットしました。</p> </div> <div class="section" id="geopoint"> <h3>4.10.3.2. GeoPointでユーザー検索<a class="headerlink" href="#geopoint" title="Permalink to this headline">¶</a></h3> <p>ここでは、 <a class="reference internal" href="search.html"><em>さまざまな検索条件の指定</em></a> で扱った、GeoPoint型のカラムで検索をします。 以下の例では、指定された位置から5000m以内にいるユーザーを検索しています。</p> <p>Execution example:</p> <div class="highlight-none"><div class="highlight"><pre>select --table Users --filter 'geo_in_circle(location,"128484216x502919856",5000)' --output_columns _key,name # [ # [ # 0, # 1337566253.89858, # 0.000355720520019531 # ], # [ # [ # [ # 2 # ], # [ # [ # "_key", # "ShortText" # ], # [ # "name", # "ShortText" # ] # ], # [ # "tasukuchan", # "グニャラくん" # ], # [ # "OffGao", # "OffGao" # ] # ] # ] # ] </pre></div> </div> <p>新宿駅から5km以内にすんでいるユーザーを検索したところ、「グニャラくん」と「OffGao」がヒットしました。</p> </div> <div class="section" id="id6"> <h3>4.10.3.3. あるユーザーをフォローしているユーザーの検索<a class="headerlink" href="#id6" title="Permalink to this headline">¶</a></h3> <p>ここでは、 <a class="reference internal" href="index.html"><em>タグ検索・参照関係の逆引き</em></a> で扱った、参照関係の逆引きをします。 以下の例では、Usersテーブルのfollowerカラムにあるフォローリストを逆引きします。</p> <p>Execution example:</p> <div class="highlight-none"><div class="highlight"><pre>select --table Users --query follower:@tasukuchan --output_columns _key,name # [ # [ # 0, # 1337566253.89858, # 0.000355720520019531 # ], # [ # [ # [ # 2 # ], # [ # [ # "_key", # "ShortText" # ], # [ # "name", # "ShortText" # ] # ], # [ # "daijiro", # "hsiomaneki" # ], # [ # "OffGao", # "OffGao" # ] # ] # ] # ] </pre></div> </div> <p>「グニャラくん」をフォローしている「hsiomaneki」と「OffGao」がヒットしました。</p> </div> <div class="section" id="id7"> <h3>4.10.3.4. GeoPointでコメント検索<a class="headerlink" href="#id7" title="Permalink to this headline">¶</a></h3> <p>ある範囲内で書かれたコメントを検索します。 また、 <a class="reference internal" href="drilldown.html"><em>ドリルダウン</em></a> で扱ったドリルダウンも行います。検索結果をハッシュタグとユーザーでドリルダウンし、ユーザー別・ハッシュタグ別のカウントを出します。</p> <p>Execution example:</p> <div class="highlight-none"><div class="highlight"><pre>select --table Comments --filter 'geo_in_circle(location,"127975798x502919856",20000)' --output_columns posted_by.name,comment --drilldown hash_tags,posted_by # [ # [ # 0, # 1337566253.89858, # 0.000355720520019531 # ], # [ # [ # [ # 4 # ], # [ # [ # "posted_by.name", # "ShortText" # ], # [ # "comment", # "ShortText" # ] # ], # [ # "グニャラくん", # "groonga開発合宿のため羽田空港に来ました! #groonga #travel" # ], # [ # "グニャラくん", # "groongaなう #groonga" # ], # [ # "OffGao", # "@daijiro @tasukuchan 登録してみましたよー!" # ], # [ # "OffGao", # "中野ブロードウェイなうなう" # ] # ], # [ # [ # 2 # ], # [ # [ # "_key", # "ShortText" # ], # [ # "_nsubrecs", # "Int32" # ] # ], # [ # "groonga", # 2 # ], # [ # "travel", # 1 # ] # ], # [ # [ # 2 # ], # [ # [ # "_key", # "ShortText" # ], # [ # "_nsubrecs", # "Int32" # ] # ], # [ # "tasukuchan", # 2 # ], # [ # "OffGao", # 2 # ] # ] # ] # ] </pre></div> </div> <p>範囲を広く指定したため、位置情報のあるすべてのコメントがヒットしました。そして、ヒットしたコメントからドリルダウンされた結果も返ってきており、ハッシュタグは「#groonga」が2つに「#travel」が1つ、投稿者は「グニャラくん」「OffGao」がそれぞれ2件ずつであることがわかります。</p> </div> <div class="section" id="id8"> <h3>4.10.3.5. キーワードでコメント検索<a class="headerlink" href="#id8" title="Permalink to this headline">¶</a></h3> <p>あるキーワードを含むコメントを検索します。 さらに、 <a class="reference internal" href="search.html"><em>さまざまな検索条件の指定</em></a> で扱った、スコア値_scoreも出してみましょう。</p> <p>Execution example:</p> <div class="highlight-none"><div class="highlight"><pre>select --table Comments --query comment:@なう --output_columns comment,_score # [ # [ # 0, # 1337566253.89858, # 0.000355720520019531 # ], # [ # [ # [ # 2 # ], # [ # [ # "comment", # "ShortText" # ], # [ # "_score", # "Int32" # ] # ], # [ # "groongaなう #groonga", # 1 # ], # [ # "中野ブロードウェイなうなう", # 2 # ] # ] # ] # ] </pre></div> </div> <p>「なう」をキーワードにコメント検索した結果、2件のコメントがヒットしました。また、_scoreの値も返ってきており、「なう」の数が出力されていることが確認できます。</p> </div> <div class="section" id="id9"> <h3>4.10.3.6. GeoPointとキーワードでコメント検索<a class="headerlink" href="#id9" title="Permalink to this headline">¶</a></h3> <p>今度は、キーワードとGeoPointの両方を条件に検索をしてみます。--queryと--filterの両方を使用した場合、両方の条件に一致するレコードがヒットします。</p> <p>Execution example:</p> <div class="highlight-none"><div class="highlight"><pre>select --table Comments --query comment:@羽田 --filter 'geo_in_circle(location,"127975798x502919856",20000)' --output_columns posted_by.name,comment --drilldown hash_tags,posted_by # [ # [ # 0, # 1337566253.89858, # 0.000355720520019531 # ], # [ # [ # [ # 1 # ], # [ # [ # "posted_by.name", # "ShortText" # ], # [ # "comment", # "ShortText" # ] # ], # [ # "グニャラくん", # "groonga開発合宿のため羽田空港に来ました! #groonga #travel" # ] # ], # [ # [ # 2 # ], # [ # [ # "_key", # "ShortText" # ], # [ # "_nsubrecs", # "Int32" # ] # ], # [ # "groonga", # 1 # ], # [ # "travel", # 1 # ] # ], # [ # [ # 1 # ], # [ # [ # "_key", # "ShortText" # ], # [ # "_nsubrecs", # "Int32" # ] # ], # [ # "tasukuchan", # 1 # ] # ] # ] # ] </pre></div> </div> <p>両方の条件を満たすコメントが1件ヒットしました。また、ドリルダウンの結果も返ってきており、「グニャラくん」のコメント1件であることがわかります。</p> </div> <div class="section" id="id10"> <h3>4.10.3.7. ハッシュタグでコメント検索<a class="headerlink" href="#id10" title="Permalink to this headline">¶</a></h3> <p>あるハッシュタグのついているコメントを検索します。 これも、 <a class="reference internal" href="index.html"><em>タグ検索・参照関係の逆引き</em></a> で扱った、参照関係の逆引きを使います。</p> <p>Execution example:</p> <div class="highlight-none"><div class="highlight"><pre>select --table Comments --query hash_tags:@groonga --output_columns posted_by.name,comment --drilldown posted_by # [ # [ # 0, # 1337566253.89858, # 0.000355720520019531 # ], # [ # [ # [ # 2 # ], # [ # [ # "posted_by.name", # "ShortText" # ], # [ # "comment", # "ShortText" # ] # ], # [ # "グニャラくん", # "groongaなう #groonga" # ], # [ # "グニャラくん", # "groonga開発合宿のため羽田空港に来ました! #groonga #travel" # ] # ], # [ # [ # 1 # ], # [ # [ # "_key", # "ShortText" # ], # [ # "_nsubrecs", # "Int32" # ] # ], # [ # "tasukuchan", # 2 # ] # ] # ] # ] </pre></div> </div> <p>#groongaタグの付いている2件のコメントがヒットしました。また、投稿者のドリルダウンも返ってきており、2件とも「グニャラくん」のものであることがわかります。</p> </div> <div class="section" id="id"> <h3>4.10.3.8. ユーザーIDでコメント検索<a class="headerlink" href="#id" title="Permalink to this headline">¶</a></h3> <p>あるユーザーが投稿したコメントを検索します。</p> <p>Execution example:</p> <div class="highlight-none"><div class="highlight"><pre>select --table Comments --query posted_by:tasukuchan --output_columns comment --drilldown hash_tags # [ # [ # 0, # 1337566253.89858, # 0.000355720520019531 # ], # [ # [ # [ # 4 # ], # [ # [ # "comment", # "ShortText" # ] # ], # [ # "初の書き込み。テストテスト。" # ], # [ # "@daijiro ありがとう!" # ], # [ # "groongaなう #groonga" # ], # [ # "groonga開発合宿のため羽田空港に来ました! #groonga #travel" # ] # ], # [ # [ # 2 # ], # [ # [ # "_key", # "ShortText" # ], # [ # "_nsubrecs", # "Int32" # ] # ], # [ # "groonga", # 2 # ], # [ # "travel", # 1 # ] # ] # ] # ] </pre></div> </div> <p>「グニャラくん」が書き込んだ4件のコメントがヒットしました。また、ハッシュタグでドリルダウンした結果も返ってきており、ハッシュタグは「#groonga」が2つに「#travel」が1つあることがわかります。</p> </div> <div class="section" id="id11"> <h3>4.10.3.9. ユーザーのお気に入りコメントを検索<a class="headerlink" href="#id11" title="Permalink to this headline">¶</a></h3> <p>あるユーザーがお気に入りに入れているコメントを検索します。</p> <p>Execution example:</p> <div class="highlight-none"><div class="highlight"><pre>select --table Users --query _key:tasukuchan --output_columns favorites.posted_by,favorites.comment # [ # [ # 0, # 1337566253.89858, # 0.000355720520019531 # ], # [ # [ # [ # 1 # ], # [ # [ # "favorites.posted_by", # "Users" # ], # [ # "favorites.comment", # "ShortText" # ] # ], # [ # [ # "daijiro", # "OffGao" # ], # [ # "マイクロブログ作ってみました(甘栗むいちゃいました的な感じで)。", # "@daijiro @tasukuchan 登録してみましたよー!" # ] # ] # ] # ] # ] </pre></div> </div> <p>「グニャラくん」がお気に入りに入れている2件のコメントがヒットしました。</p> </div> <div class="section" id="id12"> <h3>4.10.3.10. 投稿時間でコメント検索<a class="headerlink" href="#id12" title="Permalink to this headline">¶</a></h3> <p>コメントの投稿時間で検索をします。Time型については <a class="reference internal" href="data.html"><em>Various data types</em></a> で扱っています。 この例では、指定した時間よりも前に投稿されているコメントを検索します。</p> <p>Execution example:</p> <div class="highlight-none"><div class="highlight"><pre>select Comments --filter 'last_modified<=1268802000' --output_columns posted_by.name,comment,last_modified --drilldown hash_tags,posted_by # [ # [ # 0, # 1337566253.89858, # 0.000355720520019531 # ], # [ # [ # [ # 5 # ], # [ # [ # "posted_by.name", # "ShortText" # ], # [ # "comment", # "ShortText" # ], # [ # "last_modified", # "Time" # ] # ], # [ # "hsiomaneki", # "マイクロブログ作ってみました(甘栗むいちゃいました的な感じで)。", # 1268795100.0 # ], # [ # "グニャラくん", # "初の書き込み。テストテスト。", # 1268794800.0 # ], # [ # "hsiomaneki", # "@tasukuchan ようこそ!!!", # 1268795100.0 # ], # [ # "グニャラくん", # "@daijiro ありがとう!", # 1268798400.0 # ], # [ # "グニャラくん", # "groongaなう #groonga", # 1268802000.0 # ] # ], # [ # [ # 1 # ], # [ # [ # "_key", # "ShortText" # ], # [ # "_nsubrecs", # "Int32" # ] # ], # [ # "groonga", # 1 # ] # ], # [ # [ # 2 # ], # [ # [ # "_key", # "ShortText" # ], # [ # "_nsubrecs", # "Int32" # ] # ], # [ # "daijiro", # 2 # ], # [ # "tasukuchan", # 3 # ] # ] # ] # ] </pre></div> </div> <p>2010/03/17 14:00:00以前に書かれたコメント5件がヒットしました。また、ドリルダウンの結果も返ってきており、「hsiomaneki」が2件、「グニャラくん」が3件ヒットしていることがわかります。</p> </div> </div> </div> </div> </div> </div> <div class="sphinxsidebar"> <div class="sphinxsidebarwrapper"> <h3><a href="../index.html">Table Of Contents</a></h3> <ul> <li><a class="reference internal" href="#">4.10. マイクロブログ検索システムの作成</a><ul> <li><a class="reference internal" href="#id2">4.10.1. テーブルの作成</a><ul> <li><a class="reference internal" href="#users">4.10.1.1. Usersテーブル</a></li> <li><a class="reference internal" href="#comments">4.10.1.2. Commentsテーブル</a></li> <li><a class="reference internal" href="#hashtags">4.10.1.3. HashTagsテーブル</a></li> <li><a class="reference internal" href="#bigram">4.10.1.4. Bigramテーブル</a></li> <li><a class="reference internal" href="#geoindex-table">4.10.1.5. GeoIndex table</a></li> </ul> </li> <li><a class="reference internal" href="#id3">4.10.2. データのロード</a></li> <li><a class="reference internal" href="#id4">4.10.3. 検索</a><ul> <li><a class="reference internal" href="#id5">4.10.3.1. キーワードでユーザー検索</a></li> <li><a class="reference internal" href="#geopoint">4.10.3.2. GeoPointでユーザー検索</a></li> <li><a class="reference internal" href="#id6">4.10.3.3. あるユーザーをフォローしているユーザーの検索</a></li> <li><a class="reference internal" href="#id7">4.10.3.4. GeoPointでコメント検索</a></li> <li><a class="reference internal" href="#id8">4.10.3.5. キーワードでコメント検索</a></li> <li><a class="reference internal" href="#id9">4.10.3.6. GeoPointとキーワードでコメント検索</a></li> <li><a class="reference internal" href="#id10">4.10.3.7. ハッシュタグでコメント検索</a></li> <li><a class="reference internal" href="#id">4.10.3.8. ユーザーIDでコメント検索</a></li> <li><a class="reference internal" href="#id11">4.10.3.9. ユーザーのお気に入りコメントを検索</a></li> <li><a class="reference internal" href="#id12">4.10.3.10. 投稿時間でコメント検索</a></li> </ul> </li> </ul> </li> </ul> <h4>Previous topic</h4> <p class="topless"><a href="lexicon.html" title="previous chapter">4.9. 全文検索の語彙表に対する追加情報</a></p> <h4>Next topic</h4> <p class="topless"><a href="query_expansion.html" title="next chapter">4.11. クエリ拡張</a></p> <h3>This Page</h3> <ul class="this-page-menu"> <li><a href="../_sources/tutorial/micro_blog.txt" rel="nofollow">Show Source</a></li> </ul> <div id="searchbox" style="display: none"> <h3>Quick search</h3> <form class="search" action="../search.html" method="get"> <input type="text" name="q" /> <input type="submit" value="Go" /> <input type="hidden" name="check_keywords" value="yes" /> <input type="hidden" name="area" value="default" /> </form> <p class="searchtip" style="font-size: 90%"> Enter search terms or a module, class or function name. </p> </div> <script type="text/javascript">$('#searchbox').show(0);</script> </div> </div> <div class="clearer"></div> </div> <div class="related"> <h3>Navigation</h3> <ul> <li class="right" style="margin-right: 10px"> <a href="../genindex.html" title="General Index" >index</a></li> <li class="right" > <a href="query_expansion.html" title="4.11. クエリ拡張" >next</a> |</li> <li class="right" > <a href="lexicon.html" title="4.9. 全文検索の語彙表に対する追加情報" >previous</a> |</li> <li><a href="../index.html">groonga v3.0.5 documentation</a> »</li> <li><a href="../tutorial.html" >4. Tutorial</a> »</li> </ul> </div> <div class="footer"> © Copyright 2009-2013, Brazil, Inc. </div> </body> </html>