2
我正在使用Legacy索引(現稱爲Manual indexing)。從Neo4j 2遷移到版本3之後,我有一些數字排序問題。在Neo4j的2正確的說法Neo4j 3中的Manual(Legacy)索引中的數字排序無法正常工作
例子:
queryContext.sort(new Sort(new SortField(AGE, SortField.INT, false)));
這stament應該改變對Neo4j的3(Lucene的5):
queryContext.sort(new Sort(new SortField(AGE, SortField.Type.INT, false)));
但是如果你使用這種說法,你會得到一個例外:
java.lang.IllegalStateException: unexpected docvalues type SORTED_SET for field 'firstName' (expected=SORTED). Use UninvertingReader or index with docvalues.
at org.apache.lucene.index.DocValues.checkField(DocValues.java:208)
at org.apache.lucene.index.DocValues.getSorted(DocValues.java:264)
at org.apache.lucene.search.FieldComparator$TermOrdValComparator.getSortedDocValues(FieldComparator.java:762)
at org.apache.lucene.search.FieldComparator$TermOrdValComparator.getLeafComparator(FieldComparator.java:767)
at org.apache.lucene.search.FieldValueHitQueue.getComparators(FieldValueHitQueue.java:183)
at org.apache.lucene.search.TopFieldCollector$SimpleFieldCollector.getLeafCollector(TopFieldCollector.java:164)
at org.neo4j.kernel.api.impl.index.collector.DocValuesCollector.replayTo(DocValuesCollector.java:297)
at org.neo4j.kernel.api.impl.index.collector.DocValuesCollector.getTopDocs(DocValuesCollector.java:275)
at org.neo4j.kernel.api.impl.index.collector.DocValuesCollector.getIndexHits(DocValuesCollector.java:150)
at org.neo4j.index.impl.lucene.legacy.LuceneLegacyIndex.search(LuceneLegacyIndex.java:346)
at org.neo4j.index.impl.lucene.legacy.LuceneLegacyIndex.query(LuceneLegacyIndex.java:261)
at org.neo4j.index.impl.lucene.legacy.LuceneLegacyIndex.query(LuceneLegacyIndex.java:205)
at org.neo4j.index.impl.lucene.legacy.LuceneLegacyIndex.query(LuceneLegacyIndex.java:217)
at org.neo4j.kernel.impl.api.StateHandlingStatementOperations.nodeLegacyIndexQuery(StateHandlingStatementOperations.java:1440)
at org.neo4j.kernel.impl.api.OperationsFacade.nodeLegacyIndexQuery(OperationsFacade.java:1162)
at org.neo4j.kernel.impl.coreapi.LegacyIndexProxy$Type$1.query(LegacyIndexProxy.java:83)
at org.neo4j.kernel.impl.coreapi.LegacyIndexProxy.query(LegacyIndexProxy.java:365)
我認爲這是由Neo4j索引器類中的新增聲明引起的(Ne o4j現在是自動排序的索引字段?)。請參閱:
org.neo4j.index.impl.lucene.legacy.IndexType CustomType addToDocument(Document document, String key, Object value)
新行:
document.add(instantiateSortField(key, value));
和方法instantiateSortField創造SortedSetDocValuesField
所以我改變了我的代碼:
queryContext.sort(new Sort(new SortedSetSortField(AGE, false)));
這運行正常,但排序是不工作,因爲數字按字符串排序。每次在方法「addToDocument」中看到「value」參數都是String。我認爲根本原因,說明它這個老評論:
see comment in class org.neo4j.index.impl.lucene.legacy.IndexType CustomType
// TODO We should honor ValueContext instead of doing value.toString() here.
// if changing it, also change #get to honor ValueContext.
我錯過了一些新的方式如何索引,搜索和Neo4j的3個數據進行排序或這是真的值索引在Neo4j的字符串的問題?
對Neo4j的2和Neo4j的3個簡單的單元測試可以downloaded
通過MishaDemianenko補充解決方案可能你與你的問題的內容和鏈接到你的測試爲GH問題提出這個github.com/neo4j/neo4j/issues? –
新增[GH問題](https://github.com/neo4j/neo4j/issues/7216) – rfisher