我有一个拥有100.000+条记录的数据库。我想用Lucene在两个字段上索引它们,所以我添加了以下索引:
create index Book.search on Book (title,isbn) FULLTEXT ENGINE LUCENE
但是,当我使用以下查询搜索其中一个字段时:
select from Book where [title,isbn] LUCENE "android"
查询需要很长时间,就像它正在进行全表扫描一样。如果我使用解释计划,它也表明它正在这样做:
explain select from Book where [title,isbn] LUCENE "android"
结果:
{
"result": [
{
"@type": "d",
"@version": 0,
"documentReads": 80551,
"current": "#16:217944",
"documentAnalyzedCompatibleClass": 80551,
"recordReads": 80551,
"_memoryIndex": "isbn:\n\t'[61 6c 6c 61]':1: [(1)]\n\t'[63 6f 6d 70 6c 65 74 6f]':1: [(6)]\n\t'[63 6f 6e]':1: [(3)]\n\t'[63 6f 72 73 6f]':1: [(5)]\n\t'[65 64 69 74 69 6f 6e]':1: [(15)]\n\t'[67 75 69 64 61]':1: [(0)]\n\t'[69 6d 70 61 72 61 72 65]':1: [(8)]\n\t'[69 74 61 6c 69 61 6e]':1: [(14)]\n\t'[70 65 72]':1: [(7)]\n\t'[70 6f 63 6f]':1: [(12)]\n\t'[70 72 6f 67 72 61 6d 6d 61 72 65]':1: [(10)]\n\t'[70 72 6f 67 72 61 6d 6d 61 7a 69 6f 6e 65]':1: [(2)]\n\t'[72]':1: [(4)]\n\t'[74 65 6d 70 6f]':1: [(13)]\n\tterms=14, positions=14, memory=32.9 KB\ntitle:\n\t'[31 35 33 30 30 35 38 32 33 36]':1: [(0)]\n\tterms=1, positions=1, memory=32.9 KB\n\nfields=2, terms=15, positions=15, memory=66.6 KB",
"fetchingFromTargetElapsed": 17037,
"evaluated": 80551,
"user": "#5:0",
"tips": [
"Query 'SELECT FROM Book WHERE [title, isbn] LUCENE \"android\"' fetched more than 50000 records: to speed up the execution, create an index or change the query to use an existent index"
],
"elapsed": 17040.559,
"resultType": "collection",
"resultSize": 848,
"@fieldTypes": "documentReads=l,current=x,documentAnalyzedCompatibleClass=l,recordReads=l,fetchingFromTargetElapsed=l,evaluated=l,user=x,elapsed=f"
}
],
"warnings": [
"Query 'SELECT FROM Book WHERE [title, isbn] LUCENE \"android\"' fetched more than 50000 records: to speed up the execution, create an index or change the query to use an existent index"
],
"notification": "Query executed in 17.686 sec. Returned 1 record(s)"
}
我在这里缺少什么?
答案 0 :(得分:1)
根据你的解释,没有涉及索引。所以是的,它正在进行扫描
从索引图中我看到字段按此顺序声明[isbn,title]
这应解决它:
select count(1) from Book where [isbn,title] LUCENE "android"
答案 1 :(得分:0)
我试图用96000条记录复制你的问题。 我使用了OrientDb 2.1.12。
课程预订
我插入了一本标题为“android”和isbn“12345”
的书查询select from Book where [title,isbn] LUCENE "android"
它很快就完成了
用解释
{
"result": [
{
"@type": "d",
"@version": 0,
"documentReads": 1,
"fullySortedByIndex": false,
"documentAnalyzedCompatibleClass": 1,
"recordReads": 1,
"Book_search_totalHits": 1,
"luceneIndex": true,
"fetchingFromTargetElapsed": 16,
"indexIsUsedInOrderBy": false,
"score": 8.087625,
"current": "#12:140533",
"totalHits": 1,
"_memoryIndex": "isbn:\n\t'[31 32 33 34 35]':1: [(0)]\n\tterms=1, positions=1, memory=32.9 KB\ntitle:\n\t'[61 6e 64 72 6f 69 64]':1: [(0)]\n\tterms=1, positions=1, memory=32.9 KB\n\nfields=2, terms=2, positions=2, memory=66.5 KB",
"involvedIndexes": [
"Book.search"
],
"limit": -1,
"evaluated": 1,
"user": "#5:0",
"elapsed": 11.263393,
"resultType": "document",
"resultSize": 1,
"@fieldTypes": "documentReads=l,documentAnalyzedCompatibleClass=l,recordReads=l,fetchingFromTargetElapsed=l,score=f,current=x,involvedIndexes=e,evaluated=l,user=x,elapsed=f"
}
],
"notification": "Query executed in 0.042 sec. Returned 1 record(s)"
}
您对包含“android”的标题有多少条记录? 他们超过50000?