Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Index map annotations (Fix #12318) #3383

Merged
merged 7 commits into from
Feb 18, 2015
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
37 changes: 34 additions & 3 deletions components/server/src/ome/services/fulltext/FullTextBridge.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@
import ome.model.IObject;
import ome.model.annotations.Annotation;
import ome.model.annotations.FileAnnotation;
import ome.model.annotations.MapAnnotation;
import ome.model.annotations.TagAnnotation;
import ome.model.annotations.TextAnnotation;
import ome.model.annotations.TermAnnotation;
import ome.model.core.OriginalFile;
import ome.model.internal.Details;
import ome.model.internal.NamedValue;
import ome.model.internal.Permissions;
import ome.model.meta.Event;
import ome.model.meta.Experimenter;
Expand Down Expand Up @@ -205,8 +207,10 @@ public void set_annotations(final String name, final IObject object,
}
} else if (annotation instanceof FileAnnotation) {
FileAnnotation fileAnnotation = (FileAnnotation) annotation;
handleFileAnnotation(document, opts,
fileAnnotation);
handleFileAnnotation(document, opts, fileAnnotation);
} else if (annotation instanceof MapAnnotation) {
MapAnnotation mapAnnotation = (MapAnnotation) annotation;
handleMapAnnotation(document, opts, mapAnnotation);
}
}
}
Expand All @@ -216,7 +220,9 @@ public void set_annotations(final String name, final IObject object,
if (object instanceof FileAnnotation) {
FileAnnotation fileAnnotation = (FileAnnotation) object;
handleFileAnnotation(document, opts, fileAnnotation);

} else if (object instanceof MapAnnotation) {
MapAnnotation mapAnnotation = (MapAnnotation) object;
handleMapAnnotation(document, opts, mapAnnotation);
}
}

Expand Down Expand Up @@ -355,6 +361,31 @@ private void handleFileAnnotation(final Document document,
}
}

/**
* Creates {@link Field} instances for {@link MapAnnotation} named-value
* pair.
*
* @param document
* @param store
* @param index
* @param boost
* @param mapAnnotation
*/
private void handleMapAnnotation(final Document document,
final LuceneOptions opts, MapAnnotation mapAnnotation) {
logger().error("handling map annotation");
List<NamedValue> nvs = mapAnnotation.getMapValue();
if (nvs != null && nvs.size() > 0) {
for (NamedValue nv : nvs) {
if (nv != null) {
logger().error("{}={}", nv.getName(), nv.getValue());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"in progress" things to be removed before final merge, I guess

add(document, nv.getName(), nv.getValue(), opts);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we want a standard prefix before map keys. (Even also using the map name, if it has a name?) So, they don't collide with other search field names.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Happy to entertain concrete suggestions. My thinking was that even a collision would still return proper search results. A prefix will require users to know to add it. Shrugs Both perhaps?

add(document, "map.key", nv.getName(), opts);
}
}
}
}

/**
* Return the short type name of an {@link Annotation}. If the instance is
* an {@link ome.model.annotations.TextAnnotation} the returned value will
Expand Down
29 changes: 29 additions & 0 deletions components/tools/OmeroPy/test/integration/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,3 +389,32 @@ def test_hyphen_underscore(self, name, test):
]
finally:
search.close()

def test_map_annotations(self):
client = self.new_client()
key = "k" + self.simple_uuid()
val = "v" + self.simple_uuid()
ann = omero.model.MapAnnotationI()
ann.setMapValue([
omero.model.NamedValue(key, val)
])
proj = omero.model.ProjectI()
proj.name = omero.rtypes.rstring("test_map_annotations")
proj.linkAnnotation(ann)
proj = client.sf.getUpdateService().saveAndReturnObject(proj)
self.root.sf.getUpdateService().indexObject(proj)

search = client.sf.createSearchService()
search.onlyType("Project")

try:
for txt in (key, val,
"%s:%s" % (key, val),
"map.key:%s" % key):
search.byFullText(txt)
assert search.hasNext(), txt
assert proj.id.val in [
x.id.val for x in search.results()
], txt
finally:
search.close()