2015-11-10 43 views
0

我已經存儲的數據中arangodb以下列格式:全文檢索中arangodb使用AQL和python

{"data": [ 
{ 
    "content": "maindb", 
    "type": "string", 
    "name": "db_name", 
    "key": "1745085839" 
}, 
{ 
    "type": "id", 
    "name": "rel", 
    "content": "1745085840", 
    "key": "1745085839" 
}, 
{ 
    "content": "user", 
    "type": "string", 
    "name": "rel_name", 
    "key": "1745085840" 
}, 
{ 
    "type": "id", 
    "name": "tuple", 
    "content": "174508584001", 
    "key": "1745085840" 
}, 
{ 
    "type": "id", 
    "name": "tuple", 
    "content": "174508584002", 
    "key": "1745085840" 
}, 
{ 
    "type": "id", 
    "name": "tuple", 
    "content": "174508584003", 
    "key": "1745085840" 
}, 
{ 
    "type": "id", 
    "name": "tuple", 
    "content": "174508584004", 
    "key": "1745085840" 
}, 
{ 
    "type": "id", 
    "name": "tuple", 
    "content": "174508584005", 
    "key": "1745085840" 
}, 
{ 
    "type": "id", 
    "name": "tuple", 
    "content": "174508584006", 
    "key": "1745085840" 
}, 
{ 
    "type": "id", 
    "name": "tuple", 
    "content": "174508584007", 
    "key": "1745085840" 
}, 
{ 
    "content": "dspclient", 
    "type": "varchar", 
    "name": "username", 
    "key": "174508584001" 
}, 
{ 
    "content": "12345", 
    "type": "varchar", 
    "name": "password", 
    "key": "174508584001" 
}, 
{ 
    "content": "12345", 
    "type": "varchar", 
    "name": "cpassword", 
    "key": "174508584001" 
}, 
{ 
    "content": "n", 
    "type": "varchar", 
    "name": "PostgreSQL", 
    "key": "174508584001" 
}, 
{ 
    "content": "n", 
    "name": "IBMDB2", 
    "type": "varchar", 
    "key": "174508584001" 
}, 
{ 
    "content": "n", 
    "name": "MySQL", 
    "type": "varchar", 
    "key": "174508584001" 
}, 
{ 
    "content": "n", 
    "type": "varchar", 
    "name": "SQLServer", 
    "key": "174508584001" 
}, 
{ 
    "content": "n", 
    "name": "Hadoop", 
    "type": "varchar", 
    "key": "174508584001" 
}, 
{ 
    "content": "None", 
    "name": "dir1", 
    "type": "varchar", 
    "key": "174508584001" 
}, 
{ 
    "content": "None", 
    "name": "dir2", 
    "type": "varchar", 
    "key": "174508584001" 
}, 
{ 
    "content": "None", 
    "name": "dir3", 
    "type": "varchar", 
    "key": "174508584001" 
}, 
{ 
    "content": "None", 
    "name": "dir4", 
    "type": "varchar", 
    "key": "174508584001" 
}, 
{ 
    "type": "inet", 
    "name": "ipaddr", 
    "content": "1921680103", 
    "key": "174508584001" 
}, 
{ 
    "content": "y", 
    "name": "status", 
    "type": "varchar", 
    "key": "174508584001" 
}, 
{ 
    "content": "None", 
    "type": "varchar", 
    "name": "logintime", 
    "key": "174508584001" 
}, 
{ 
    "content": "None", 
    "type": "varchar", 
    "name": "logindate", 
    "key": "174508584001" 
}, 
{ 
    "content": "None", 
    "type": "varchar", 
    "name": "logouttime", 
    "key": "174508584001" 
}, 
{ 
    "content": "client", 
    "type": "varchar", 
    "name": "user_type", 
    "key": "174508584001" 
}, 
{ 
    "content": "royal", 
    "type": "varchar", 
    "name": "username", 
    "key": "174508584002" 
}, 
{ 
    "content": "12345", 
    "type": "varchar", 
    "name": "password", 
    "key": "174508584002" 
}, 
{ 
    "content": "12345", 
    "type": "varchar", 
    "name": "cpassword", 
    "key": "174508584002" 
}, 
{ 
    "content": "n", 
    "type": "varchar", 
    "name": "PostgreSQL", 
    "key": "174508584002" 
}, 
{ 
    "content": "n", 
    "name": "IBMDB2", 
    "type": "varchar", 
    "key": "174508584002" 
}, 
{ 
    "content": "n", 
    "name": "MySQL", 
    "type": "varchar", 
    "key": "174508584002" 
}, 
{ 
    "content": "n", 
    "type": "varchar", 
    "name": "SQLServer", 
    "key": "174508584002" 
}, 
{ 
    "content": "n", 
    "name": "Hadoop", 
    "type": "varchar", 
    "key": "174508584002" 
}, 
{ 
    "content": "None", 
    "name": "dir1", 
    "type": "varchar", 
    "key": "174508584002" 
}, 
{ 
    "content": "None", 
    "name": "dir2", 
    "type": "varchar", 
    "key": "174508584002" 
}, 
{ 
    "content": "None", 
    "name": "dir3", 
    "type": "varchar", 
    "key": "174508584002" 
}, 
{ 
    "content": "None", 
    "name": "dir4", 
    "type": "varchar", 
    "key": "174508584002" 
}, 
{ 
    "type": "inet", 
    "name": "ipaddr", 
    "content": "1921680105", 
    "key": "174508584002" 
}, 
{ 
    "content": "y", 
    "name": "status", 
    "type": "varchar", 
    "key": "174508584002" 
}, 
{ 
    "content": "190835899000", 
    "type": "varchar", 
    "name": "logintime", 
    "key": "174508584002" 
}, 
{ 
    "content": "20151002", 
    "type": "varchar", 
    "name": "logindate", 
    "key": "174508584002" 
}, 
{ 
    "content": "None", 
    "type": "varchar", 
    "name": "logouttime", 
    "key": "174508584002" 
}, 
{ 
    "content": "client", 
    "type": "varchar", 
    "name": "user_type", 
    "key": "174508584002" 
}, 
{ 
    "content": "abc", 
    "type": "varchar", 
    "name": "username", 
    "key": "174508584003" 
}, 
{ 
    "content": "12345", 
    "type": "varchar", 
    "name": "password", 
    "key": "174508584003" 
}, 
{ 
    "content": "12345", 
    "type": "varchar", 
    "name": "cpassword", 
    "key": "174508584003" 
}, 
{ 
    "content": "n", 
    "type": "varchar", 
    "name": "PostgreSQL", 
    "key": "174508584003" 
}, 
{ 
    "content": "n", 
    "name": "IBMDB2", 
    "type": "varchar", 
    "key": "174508584003" 
}]} 

爲了執行全文搜索,我已經通過使用從語法創建的內容屬性的索引Python腳本:

c.DSP.ensureFulltextIndex("content"); 

其中,C爲數據庫,DSP是集名稱。現在,我想在上面的數據使用語法設置執行搜索操作:

FOR doc IN FULLTEXT(DSP, "content", "username") RETURN doc 

然後,錯誤occure:

[1571] in function 'FULLTEXT()': no suitable fulltext index found for fulltext query on 'DSP' (while executing) 

請告訴我問題,還告訴我當我用python腳本嘗試這個查詢時,語法是什麼。

謝謝...

+0

你看看管理界面了嗎? Collections-> yourCollection [(I)] - >索引 - 您應該在列表中找到您的索引。 – dothebart

+0

謝謝dothebert,現在我已經通過arangodb界面創建了索引...但是上面的查詢返回空列表[]作爲結果.... –

+0

如果我的眼球grep工作正常,你沒有任何'content'包含字符串'username'的屬性?請參閱[全文索引示例](https://docs.arangodb.com/IndexHandling/Fulltext.html) – dothebart

回答

1

the 10 minutes tutorial工作和driver documentation

我得到它的工作是這樣的:

from pyArango.connection import * 
c = Connection() 
db = c.createDatabase(name = "testdb") 
DSP= db.createCollection(name = "DSP") 

DSP.ensureFulltextIndex(fields=["content"]) 

doc = DSP.createDocument({"content": "test bla"}) 
doc.save() 

print db.AQLQuery('''FOR doc IN FULLTEXT(DSP, "content", "bla") RETURN doc''', 10) 

,導致:

[{u'_key': u'1241175138503', u'content': u'test bla', u'_rev': u'1241175138503', u'_id': u'DSP/1241175138503'}] 

我用arangosh重新驗證pyt的步驟hon提示:

arangosh> db._useDatabase("testdb") 
arangosh [testdb]> db.DSP.getIndexes() 
[ 
    { 
    "id" : "DSP/0", 
    "type" : "primary", 
    "fields" : [ 
     "_key" 
    ], 
    "selectivityEstimate" : 1, 
    "unique" : true, 
    "sparse" : false 
    }, 
    { 
    "id" : "DSP/1241140928711", 
    "type" : "hash", 
    "fields" : [ 
     "content" 
    ], 
    "selectivityEstimate" : 1, 
    "unique" : false, 
    "sparse" : true 
    }, 
    { 
    "id" : "DSP/1241142960327", 
    "type" : "fulltext", 
    "fields" : [ 
     "content" 
    ], 
    "unique" : false, 
    "sparse" : true, 
    "minLength" : 2 
    } 
] 
arangosh [testdb]> db.testdb.toArray() 
[ 
    { 
    "content" : "test bla", 
    "_id" : "DSP/1241175138503", 
    "_rev" : "1241175138503", 
    "_key" : "1241175138503" 
    } 
] 
db._query('FOR doc IN FULLTEXT(DSP, "content", "bla") RETURN doc') 
+0

您好先生,我試過這個查詢 –

+0

您是否重新驗證arangosh窗口的輸出? – dothebart

+0

是的,我已經重新驗證了我的輸出 –