forked from orientechnologies/orientdb
-
Notifications
You must be signed in to change notification settings - Fork 0
Custom Index Engine
bonybeat edited this page Sep 23, 2014
·
5 revisions
OrientDB バージョン1.7より利用可能
新しいインデックスエンジンを開発すには二つのエントリィポイントがあります。
- OIndexFactory
- OIndexEngine
OIndexFactoryを実装して独自のfacoryを開発します
独自のfacoryでは以下を宣言する必要があります
- どんな種類のインデックスをサポートするのか
- どんな種類のアルゴリズムをサポートするのか
そしてcreateIndexメソッドを実装する必要があります。
Luceneインデックスに対するカスタムfactoryの例
package com.orientechnologies.lucene;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import com.orientechnologies.lucene.index.OLuceneFullTextIndex;
import com.orientechnologies.lucene.index.OLuceneSpatialIndex;
import com.orientechnologies.lucene.manager.*;
import com.orientechnologies.lucene.shape.OShapeFactoryImpl;
import com.orientechnologies.orient.core.db.record.ODatabaseRecord;
import com.orientechnologies.orient.core.db.record.OIdentifiable;
import com.orientechnologies.orient.core.exception.OConfigurationException;
import com.orientechnologies.orient.core.index.OIndexFactory;
import com.orientechnologies.orient.core.index.OIndexInternal;
import com.orientechnologies.orient.core.metadata.schema.OClass;
import com.orientechnologies.orient.core.record.impl.ODocument;
/**
* Created by enricorisa on 21/03/14.
*/
public class OLuceneIndexFactory implements OIndexFactory {
private static final Set<String> TYPES;
private static final Set<String> ALGORITHMS;
public static final String LUCENE_ALGORITHM = "LUCENE";
static {
final Set<String> types = new HashSet<String>();
types.add(OClass.INDEX_TYPE.UNIQUE.toString());
types.add(OClass.INDEX_TYPE.NOTUNIQUE.toString());
types.add(OClass.INDEX_TYPE.FULLTEXT.toString());
types.add(OClass.INDEX_TYPE.DICTIONARY.toString());
types.add(OClass.INDEX_TYPE.SPATIAL.toString());
TYPES = Collections.unmodifiableSet(types);
}
static {
final Set<String> algorithms = new HashSet<String>();
algorithms.add(LUCENE_ALGORITHM);
ALGORITHMS = Collections.unmodifiableSet(algorithms);
}
public OLuceneIndexFactory() {
}
@Override
public Set<String> getTypes() {
return TYPES;
}
@Override
public Set<String> getAlgorithms() {
return ALGORITHMS;
}
@Override
public OIndexInternal<?> createIndex(ODatabaseRecord oDatabaseRecord, String indexType, String algorithm,
String valueContainerAlgorithm, ODocument metadata) throws OConfigurationException {
return createLuceneIndex(oDatabaseRecord, indexType, valueContainerAlgorithm, metadata);
}
private OIndexInternal<?> createLuceneIndex(ODatabaseRecord oDatabaseRecord, String indexType, String valueContainerAlgorithm,
ODocument metadata) {
if (OClass.INDEX_TYPE.FULLTEXT.toString().equals(indexType)) {
return new OLuceneFullTextIndex(indexType, LUCENE_ALGORITHM, new OLuceneIndexEngine<Set<OIdentifiable>>(
new OLuceneFullTextIndexManager(), indexType), valueContainerAlgorithm, metadata);
} else if (OClass.INDEX_TYPE.SPATIAL.toString().equals(indexType)) {
return new OLuceneSpatialIndex(indexType, LUCENE_ALGORITHM, new OLuceneIndexEngine<Set<OIdentifiable>>(
new OLuceneSpatialIndexManager(new OShapeFactoryImpl()), indexType), valueContainerAlgorithm);
}
throw new OConfigurationException("Unsupported type : " + indexType);
}
}
factoryをプラグインするには、 META-INF/services配下にcom.orientechnologies.orient.core.index.OIndexFactory
というテキストファイルを作って、そこにあなたのfactoryを書きます。
サンプル
com.orientechnologies.lucene.OLuceneIndexFactory
あたらしいインデックスエンジンを実装するためにはOIndexEngineインターフェースを実装します。
メインメソッドは:
- get
- put
インデックスがキーについてユニークならば、OIdentifiableかOIdentifiableのセットを返します。 キーは以下のいずれかになります。
- 単一インデックスをサポートするならその値(Integer,String,Double..など)
- 複数インデックスをサポートするならOCompositeKey
- keyはインデックスされた値
- valueは、そのkeyに対応したOIdentifiableかOIdentifiableのセット
以下のSQLで、独自インデックスエンジンのインデックスをSQLで作成することができます。
create index Foo.bar on Foo (bar) NOTUNIQUE ENGINE CUSTOM
where CUSTOM はあなたのインデックスエンジンの名前
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script> <script> $(function() { $("*").contents().filter(function() { return this.nodeType==8 && this.nodeValue.match(/^original/); }).each(function(i, e) { var tooltips = e.nodeValue.replace(/^original *[\n\r]|[\n\r]$/g, ''); $(this).prev().attr('title', tooltips); }); }); </script>Home - Download - Install - Upgrade - Professional Support - Courses - Team
- Copyright (C) Orient Technologies - All rights reserved.