jmoore wrote:At this point, I would assume that you are in fact adding things to the Lucene index, but the question is whether or not what you are adding is what you are searching for. You might try http://www.getopt.org/luke/ to examine the /OMERO/FullText directory. Find an image that has passed through your bridge and look at its contents. It should have a field of the for A.B.C (or similar).
Unfortunately, I dont see a field of "image_name" for that image (which I tried to add) in the luke.
does this mean my code has some problem?
my code is exactly the same with the sample code
- Code: Select all
/*
* $Id$
*
* Copyright 2008 Glencoe Software, Inc. All rights reserved.
* Use is subject to license terms supplied in LICENSE.txt
*/
package edu.cmu.search.bridges;
import java.util.ArrayList;
import java.util.List;
import ome.model.containers.Dataset;
import ome.model.containers.DatasetImageLink;
import ome.model.containers.Project;
import ome.model.containers.ProjectDatasetLink;
import ome.model.core.Image;
import ome.services.fulltext.BridgeHelper;
import ome.services.fulltext.SimpleLuceneOptions;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.hibernate.search.bridge.FieldBridge;
import org.hibernate.search.bridge.LuceneOptions;
/**
* Example custom {@link FieldBridge} implementation which parses all
* {@link Image} names from a {@link Project} and inserts them into the index
* for that {@link Project}.
*
* @author Josh Moore, josh at glencoesoftware.com
* @since 3.0-Beta3
*/
public class ExperimentFileBridge extends BridgeHelper {
/**
* If the "value" argument is a {@link Project}, this
* {@link FieldBridge bridge} gathers all images and adds them to the index
* with a slightly reduced boost value. The field name of the image name is
* "image_name" but the values are also added to the
* {@link BridgeHelper#COMBINED} field via the
* {@link #add(Document, String, String, org.apache.lucene.document.Field.Store, org.apache.lucene.document.Field.Index, Float)}
* method.
*/
@Override
public void set(final String name, final Object value,
final Document document, final LuceneOptions _opts) {
if (value instanceof Project) {
logger().info("Indexing all image names for " + value);
// Copying lucene options with a new boost value
final float reduced_boost = _opts.getBoost().floatValue() / 2;
final LuceneOptions opts = new SimpleLuceneOptions(_opts, reduced_boost);
final Project p = (Project) value;
for (final ProjectDatasetLink pdl : p.unmodifiableDatasetLinks()) {
final Dataset d = pdl.child();
for (final DatasetImageLink dil : d.unmodifiableImageLinks()) {
final Image i = dil.child();
// Name is never null, but as an example it is important
// to always check the value for null, and either simply
// not call add() or to use a null token like "null".
if (i.getName() != null) {
add(document, "image_name", i.getName(), opts);
} else {
add(document, "image_name", "null", opts);
}
}
}
} else if (value instanceof Image) {
logger().info(
"Scheduling all project containers of " + value
+ " for re-indexing");
final Image i = (Image) value;
final List<Project> list = new ArrayList<Project>();
for (final DatasetImageLink dil : i.unmodifiableDatasetLinks()) {
final Dataset d = dil.parent();
for (final ProjectDatasetLink pdl : d
.unmodifiableProjectLinks()) {
list.add(pdl.parent());
}
}
if (list.size() > 0) {
// ticket:955 Disabling for the moment.
// reindexAll(list);
}
}
}
}