[Groonga-commit] groonga/groonga.org at d1f9cf5 [gh-pages] blog ja: update use case

Back to archive index

Kentaro Hayashi null+****@clear*****
Sat Jul 29 00:08:24 JST 2017


Kentaro Hayashi	2017-07-29 00:08:24 +0900 (Sat, 29 Jul 2017)

  New Revision: d1f9cf566a3f42b44b0bdd2eceb99692a706fc47
  https://github.com/groonga/groonga.org/commit/d1f9cf566a3f42b44b0bdd2eceb99692a706fc47

  Message:
    blog ja: update use case

  Modified files:
    ja/_posts/2017-07-29-groonga-7.0.5.md

  Modified: ja/_posts/2017-07-29-groonga-7.0.5.md (+13 -39)
===================================================================
--- ja/_posts/2017-07-29-groonga-7.0.5.md    2017-07-28 23:50:37 +0900 (3bed294)
+++ ja/_posts/2017-07-29-groonga-7.0.5.md    2017-07-29 00:08:24 +0900 (1e2df04)
@@ -58,55 +58,29 @@ SQLを使って全文検索システムを構築したい、今のウェブサ
 
     plugin_register functions/math
 
-駅から何mという情報があらかじめお店ごとに設定されていて、駅から250mにある仕事場から最も近いお店を探索したいとします。
+都市のデータを特定の都市からの時差が少ない順にソートして表示したいとします。
 
-サンプルのスキーマとデータは以下の通りとします。
+それに使うサンプルのスキーマとデータは以下の通りとします。
 
-    table_create Shops TABLE_HASH_KEY ShortText 
-    column_create Shops from_station COLUMN_SCALAR Int32                                        
+    table_create City TABLE_HASH_KEY ShortText
+    column_create City utc COLUMN_SCALAR Int32
 
-    load --table Shops                          
+    load --table City
     [
-    {"_key": "Coffee Shop",         "from_station":  50},
-    {"_key": "Donut & Coffee Shop", "from_station": 400},
-    {"_key": "Cake & Coffee Shop",  "from_station": 200}
+    {"_key": "Tokyo",    "utc": 9},
+    {"_key": "New York", "utc": -4},
+    {"_key": "Paris",    "utc": 2}
     ]
 
+このデータから、シンガポール(UTC+8)との時差が少ない都市を順に表示するには次のようなクエリーを実行します。絶対値で比較するのに math_abs()を使います。
+
 すると、以下の様なクエリーで仕事場から近いお店をソートして得ることができます。
 
-    select Shops \
+    select City \
       --filter true \
-      --output_columns '_key, from_office' \
-      --scorer '_score = math_abs(250 - from_station)' \
+      --output_columns '_key, utc, _score' \
+      --scorer '_score = math_abs(8 - utc)' \
       --sort_keys _score
-    
-    [
-      [
-        [
-          3
-        ],
-        [
-          [
-            "_key",
-            "ShortText"
-          ],
-          [
-            "from_office",
-            "Int32"
-          ]
-        ],
-        [                                        
-          "Cake & Coffee Shop",                  
-          50                                     
-        ],                                       
-        [                                        
-          "Donut & Coffee Shop",                 
-          150                                    
-        ],                                       
-        [                                        
-          "Coffee Shop",                         
-          200                                    
-        ]                       
   
 math_abs()がない場合に自乗するという回避策をとらなくてもよくなります。
 
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Back to archive index