null+****@clear*****
null+****@clear*****
2011年 8月 12日 (金) 15:51:43 JST
Kouhei Sutou 2011-08-12 06:51:43 +0000 (Fri, 12 Aug 2011)
New Revision: 8934104906d120ccb75cbaa47094fd150b94095e
Log:
[doc] support multi database.
Added files:
doc/source/example/suggestion-1.log
Modified files:
doc/source/example/completion-1.log
doc/source/example/correction-1.log
doc/source/suggest/completion.txt
doc/source/suggest/correction.txt
doc/source/suggest/suggestion.txt
doc/source/tutorial/tutorial01.txt
doc/source/update_execution_example.py
Modified: doc/source/example/completion-1.log (+2 -2)
===================================================================
--- doc/source/example/completion-1.log 2011-08-12 06:08:43 +0000 (2452290)
+++ doc/source/example/completion-1.log 2011-08-12 06:51:43 +0000 (d8d2bda)
@@ -1,5 +1,5 @@
Execution example::
> suggest --table item_query --column kana --types complete --threshold 1 --query en
- [[0,1312956152.1091,0.001121197],{"complete":[[5],[["_key","ShortText"],["_score","Int32"]],["en",1],["engine",1],["engi",1],["engin",1],["eng",1]]}]
-
\ No newline at end of file
+ [[0,1313131879.64588,0.000913584],{"complete":[[1],[["_key","ShortText"],["_score","Int32"]],["engine",1]]}]
+
\ No newline at end of file
Modified: doc/source/example/correction-1.log (+1 -1)
===================================================================
--- doc/source/example/correction-1.log 2011-08-12 06:08:43 +0000 (b91c44d)
+++ doc/source/example/correction-1.log 2011-08-12 06:51:43 +0000 (4091455)
@@ -1,5 +1,5 @@
Execution example::
> suggest --table item_query --column kana --types correction --threshold 1 --query saerch
- [[0,1312990993.62398,0.000350034],{"correct":[[1],[["_key","ShortText"],["_score","Int32"]],["search",2]]}]
+ [[0,1313131812.39207,0.000783031],{"correct":[[1],[["_key","ShortText"],["_score","Int32"]],["search",1]]}]
\ No newline at end of file
Added: doc/source/example/suggestion-1.log (+5 -0) 100644
===================================================================
--- /dev/null
+++ doc/source/example/suggestion-1.log 2011-08-12 06:51:43 +0000 (9c7723c)
@@ -0,0 +1,5 @@
+Execution example::
+
+ > suggest --table item_query --column kana --types suggest --threshold 1 --query search
+ [[0,1313131808.92868,0.000607197],{"suggest":[[2],[["_key","ShortText"],["_score","Int32"]],["search engine",1],["web search realtime",1]]}]
+
\ No newline at end of file
Modified: doc/source/suggest/completion.txt (+2 -4)
===================================================================
--- doc/source/suggest/completion.txt 2011-08-12 06:08:43 +0000 (a214e67)
+++ doc/source/suggest/completion.txt 2011-08-12 06:51:43 +0000 (acaffdc)
@@ -3,10 +3,8 @@
.. highlightlang:: none
.. groonga-command
-.. % rm -rf /tmp/completion
-.. % mkdir -p /tmp/completion
-.. % groonga -n /tmp/completion/db shutdown
-.. % groonga-suggest-create-dataset /tmp/completion/db query
+.. % groonga-suggest-create-dataset /tmp/groonga-databases/completion query
+.. database: completion
Completion
==========
Modified: doc/source/suggest/correction.txt (+2 -4)
===================================================================
--- doc/source/suggest/correction.txt 2011-08-12 06:08:43 +0000 (ca361c5)
+++ doc/source/suggest/correction.txt 2011-08-12 06:51:43 +0000 (b19ae95)
@@ -3,10 +3,8 @@
.. highlightlang:: none
.. groonga-command
-.. % rm -rf /tmp/correction
-.. % mkdir -p /tmp/correction
-.. % groonga -n /tmp/correction/db shutdown
-.. % groonga-suggest-create-dataset /tmp/correction/db query
+.. % groonga-suggest-create-dataset /tmp/groonga-databases/correction query
+.. database: correction
Correction
==========
Modified: doc/source/suggest/suggestion.txt (+2 -4)
===================================================================
--- doc/source/suggest/suggestion.txt 2011-08-12 06:08:43 +0000 (bf39d8a)
+++ doc/source/suggest/suggestion.txt 2011-08-12 06:51:43 +0000 (c253201)
@@ -3,10 +3,8 @@
.. highlightlang:: none
.. groonga-command
-.. % rm -rf /tmp/suggestion
-.. % mkdir -p /tmp/suggestion
-.. % groonga -n /tmp/suggestion/db shutdown
-.. % groonga-suggest-create-dataset /tmp/suggestion/db query
+.. % groonga-suggest-create-dataset /tmp/groonga-databases/suggestion query
+.. database: suggestion
Suggestion
==========
Modified: doc/source/tutorial/tutorial01.txt (+1 -0)
===================================================================
--- doc/source/tutorial/tutorial01.txt 2011-08-12 06:08:43 +0000 (df134c3)
+++ doc/source/tutorial/tutorial01.txt 2011-08-12 06:51:43 +0000 (888ba87)
@@ -3,6 +3,7 @@
.. highlightlang:: none
.. groonga-command
+.. database: tutorial
.. table_remove Site
.. table_remove Terms
Modified: doc/source/update_execution_example.py (+33 -17)
===================================================================
--- doc/source/update_execution_example.py 2011-08-12 06:08:43 +0000 (3db329a)
+++ doc/source/update_execution_example.py 2011-08-12 06:51:43 +0000 (67406d4)
@@ -6,16 +6,31 @@ from select import select
from sys import argv,stdout
import os
import os.path
+import shutil
-GROONGA_PATH = os.environ.get("GROONGA")
-if GROONGA_PATH is None:
- GROONGA_PATH = "groonga"
-DB_PATH = "/tmp/example.db"
+DB_DIRECTORY = "/tmp/groonga-databases"
-os.system('rm -rf %s*' % DB_PATH)
-ioobj = Popen([GROONGA_PATH, '-n', DB_PATH], stdin = PIPE, stdout = PIPE)
-ioin = ioobj.stdin
-ioout = ioobj.stdout
+shutil.rmtree(DB_DIRECTORY, ignore_errors=True)
+os.makedirs(DB_DIRECTORY)
+
+groonga_process = None
+def close_groonga():
+ global groonga_process
+ if groonga_process:
+ groonga_process.stdin.close()
+ groonga_process.stdout.close()
+ groonga_process = None
+ print '###<<< database: close'
+
+def reconnect(name):
+ global groonga_process
+ close_groonga()
+ db_path = os.path.join(DB_DIRECTORY, name)
+ if os.path.exists(db_path):
+ groonga_process = Popen(["groonga", db_path], stdin=PIPE, stdout=PIPE)
+ else:
+ groonga_process = Popen(["groonga", "-n", db_path], stdin=PIPE, stdout=PIPE)
+ print '###>>> database: open <%s>' % db_path
fout = None
@@ -23,14 +38,14 @@ def execmd(cmd, fout):
a = '> ' + cmd + "\n"
stdout.write(a)
stdout.flush()
- ioin.write(cmd + "\n")
- ioin.flush()
+ groonga_process.stdin.write(cmd + "\n")
+ groonga_process.stdin.flush()
if fout:
fout.write(a + " ")
while True:
- out = select([ioout], [], [], 0.2)
+ out = select([groonga_process.stdout], [], [], 0.2)
if len(out[0]):
- a = ioout.read(1)
+ a = groonga_process.stdout.read(1)
if a != None:
stdout.write(a)
if fout:
@@ -64,7 +79,10 @@ def readfile(fname, outflag):
fout = None
while len(dat):
cmd = dat.pop(0)
- if cmd.startswith('.. include:: '):
+ if cmd.startswith('.. database:'):
+ database_name = cmd[cmd.index(":")+1:].strip()
+ reconnect(database_name)
+ elif cmd.startswith('.. include:: '):
a = rootdir + cmd[13:]
if outflag == 0:
dir_name = os.path.dirname(a)
@@ -104,9 +122,8 @@ def readfile(fname, outflag):
readfile(a, outflag + 1)
print '###<<< include end'
-
entry_point = "./"
-if len(argv) == 1:
+if len(argv) == 2:
entry_point = argv[1]
if os.path.isfile(entry_point):
readfile(entry_point, 0)
@@ -120,6 +137,5 @@ else:
if fout:
fout.close()
-ioin.close()
-ioout.close()
+close_groonga()