com.orientechnologies.lucene.engine.OLuceneFullTextIndexEngine Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of orientdb-lucene Show documentation
Show all versions of orientdb-lucene Show documentation
Lucene plugin for OrientDB NoSQL document graph dbms
The newest version!
/*
* Copyright 2010-2016 OrientDB LTD (http://orientdb.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.orientechnologies.lucene.engine;
import static com.orientechnologies.lucene.builder.OLuceneQueryBuilder.EMPTY_METADATA;
import com.orientechnologies.common.exception.OException;
import com.orientechnologies.common.log.OLogManager;
import com.orientechnologies.common.util.ORawPair;
import com.orientechnologies.lucene.builder.OLuceneDocumentBuilder;
import com.orientechnologies.lucene.builder.OLuceneIndexType;
import com.orientechnologies.lucene.builder.OLuceneQueryBuilder;
import com.orientechnologies.lucene.collections.LuceneIndexTransformer;
import com.orientechnologies.lucene.collections.OLuceneCompositeKey;
import com.orientechnologies.lucene.collections.OLuceneResultSet;
import com.orientechnologies.lucene.query.OLuceneKeyAndMetadata;
import com.orientechnologies.lucene.query.OLuceneQueryContext;
import com.orientechnologies.lucene.tx.OLuceneTxChanges;
import com.orientechnologies.orient.core.command.OCommandContext;
import com.orientechnologies.orient.core.db.record.OIdentifiable;
import com.orientechnologies.orient.core.id.OContextualRecordId;
import com.orientechnologies.orient.core.id.ORID;
import com.orientechnologies.orient.core.index.OCompositeKey;
import com.orientechnologies.orient.core.index.OIndexEngineException;
import com.orientechnologies.orient.core.index.OIndexKeyUpdater;
import com.orientechnologies.orient.core.index.OIndexMetadata;
import com.orientechnologies.orient.core.index.engine.IndexEngineValidator;
import com.orientechnologies.orient.core.index.engine.IndexEngineValuesTransformer;
import com.orientechnologies.orient.core.record.impl.ODocument;
import com.orientechnologies.orient.core.sql.parser.ParseException;
import com.orientechnologies.orient.core.storage.OStorage;
import com.orientechnologies.orient.core.storage.impl.local.paginated.atomicoperations.OAtomicOperation;
import java.io.IOException;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.atomic.AtomicLong;
import java.util.stream.Stream;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.ScoreDoc;
import org.apache.lucene.search.SortField;
import org.apache.lucene.search.highlight.TextFragment;
import org.apache.lucene.store.Directory;
public class OLuceneFullTextIndexEngine extends OLuceneIndexEngineAbstract {
private final OLuceneDocumentBuilder builder;
private OLuceneQueryBuilder queryBuilder;
private final AtomicLong bonsayFileId = new AtomicLong(0);
public OLuceneFullTextIndexEngine(OStorage storage, String idxName, int id) {
super(id, storage, idxName);
builder = new OLuceneDocumentBuilder();
}
@Override
public void init(OIndexMetadata im) {
super.init(im);
queryBuilder = new OLuceneQueryBuilder(im.getMetadata());
}
@Override
public IndexWriter createIndexWriter(Directory directory) throws IOException {
OLuceneIndexWriterFactory fc = new OLuceneIndexWriterFactory();
OLogManager.instance().debug(this, "Creating Lucene index in '%s'...", directory);
return fc.createIndexWriter(directory, metadata, indexAnalyzer());
}
@Override
public void onRecordAddedToResultSet(
final OLuceneQueryContext queryContext,
final OContextualRecordId recordId,
final Document ret,
final ScoreDoc score) {
HashMap data = new HashMap();
final Map frag = queryContext.getFragments();
frag.forEach(
(key, fragments) -> {
final StringBuilder hlField = new StringBuilder();
for (final TextFragment fragment : fragments) {
if ((fragment != null) && (fragment.getScore() > 0)) {
hlField.append(fragment.toString());
}
}
data.put("$" + key + "_hl", hlField.toString());
});
data.put("$score", score.score);
recordId.setContext(data);
}
@Override
public boolean remove(final OAtomicOperation atomicOperation, final Object key) {
return remove(key);
}
@Override
public Object get(final Object key) {
return getInTx(key, null);
}
@Override
public void update(
final OAtomicOperation atomicOperation,
final Object key,
final OIndexKeyUpdater
© 2015 - 2025 Weber Informatics LLC | Privacy Policy