Skip to content

Commit

Permalink
Merge pull request #1863 from inception-project/bugfix/1860-Layers-wi…
Browse files Browse the repository at this point in the history
…thout-features-are-not-indexed-for-search

#1860 - Layers without features are not indexed for search
  • Loading branch information
reckart authored Nov 25, 2020
2 parents 9830875 + ca19d9e commit a005cdf
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.stream.Collectors;

import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -177,7 +176,7 @@ public class MtasDocumentIndex
private ReferenceManager<IndexSearcher> _searcherManager;
private ScheduledFuture<?> _commitFuture;

private List<AnnotationFeature> features;
private Map<AnnotationLayer, List<AnnotationFeature>> layersAndFeatures;

public MtasDocumentIndex(Project aProject, DocumentService aDocumentService,
AnnotationSchemaService aSchemaService, String aDir,
Expand All @@ -202,11 +201,19 @@ private synchronized IndexWriter getIndexWriter() throws IOException
OPEN_INDEXES.put(project.getId(), this);

// Initialize and populate the hash maps for the layers and features
features = schemaService.listAnnotationFeature(project).stream()
.filter(feat -> feat.getLayer().isEnabled())
.filter(feat -> feat.isEnabled())
.collect(Collectors.toList());

layersAndFeatures = new LinkedHashMap<>();
schemaService.listAnnotationLayer(project)
.forEach(layer -> layersAndFeatures.put(layer, new ArrayList<>()));
for (AnnotationFeature feat : schemaService.listAnnotationFeature(project)) {
if (!feat.getLayer().isEnabled() || !feat.isEnabled()) {
continue;
}

List<AnnotationFeature> feats = layersAndFeatures.computeIfAbsent(feat.getLayer(),
key -> new ArrayList<>());
feats.add(feat);
}

// Add the project id to the configuration
JSONObject jsonParserConfiguration = new JSONObject();
jsonParserConfiguration.put(PARAM_PROJECT_ID, project.getId());
Expand Down Expand Up @@ -1083,9 +1090,9 @@ public Project getProject()
return project;
}

public List<AnnotationFeature> getFeaturesToIndex()
public Map<AnnotationLayer, List<AnnotationFeature>> getLayersAndFeaturesToIndex()
{
return features;
return layersAndFeatures;
}

public static MtasDocumentIndex getIndex(long aProjectId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,13 @@ public MtasUimaParser(MtasConfiguration config)
.getIndex(jsonParserConfiguration.getLong(PARAM_PROJECT_ID));

// Initialize and populate the hash maps for the layers and features
for (AnnotationFeature feature : index.getFeaturesToIndex()) {
layers.put(feature.getLayer().getName(), feature.getLayer());
for (Entry<AnnotationLayer, List<AnnotationFeature>> e : index.getLayersAndFeaturesToIndex()
.entrySet()) {
layers.put(e.getKey().getName(), e.getKey());
layerFeatures
.computeIfAbsent(feature.getLayer().getName(), key -> new ArrayList<>())
.add(feature);
}
.computeIfAbsent(e.getKey().getName(), key -> new ArrayList<>())
.addAll(e.getValue());
}
}

// This constructor is used for testing
Expand Down Expand Up @@ -363,23 +364,32 @@ private int indexFeatures(AnnotationFS aAnnotation, String aLayer, String aPrefi
if (features == null) {
return mtasId;
}

// Iterate over the features of this layer and index them one-by-one
for (AnnotationFeature feature : features) {
Optional<FeatureIndexingSupport> fis = featureIndexingSupportRegistry
.getIndexingSupport(feature);
if (fis.isPresent()) {
MultiValuedMap<String, String> fieldsAndValues = fis.get()
.indexFeatureValue(aLayer, aAnnotation, aPrefix, feature);
MultiValuedMap<String, String> fieldsAndValues = fis.get().indexFeatureValue(aLayer,
aAnnotation, aPrefix, feature);
for (Entry<String, String> e : fieldsAndValues.entries()) {
indexFeatureValue(e.getKey(), e.getValue(), mtasId++,
aAnnotation.getBegin(), aAnnotation.getEnd(), aRange, aFSAddress);
indexFeatureValue(e.getKey(), e.getValue(), mtasId++, aAnnotation.getBegin(),
aAnnotation.getEnd(), aRange, aFSAddress);
}

if (LOG.isTraceEnabled()) {
if (fieldsAndValues.isEmpty()) {
LOG.trace("FEAT[{}-{}]: [{}]: Nothing to index",
aRange.getBegin(), aRange.getEnd(), feature.getName());
}
else {
LOG.trace("FEAT[{}-{}]: [{}] = {}", aRange.getBegin(), aRange.getEnd(),
feature.getName(), fieldsAndValues);
}
}

LOG.trace("FEAT[{}-{}]: {}", aRange.getBegin(), aRange.getEnd(), fieldsAndValues);
}
}

return mtasId;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import static de.tudarmstadt.ukp.clarin.webanno.api.annotation.util.WebAnnoCasUtil.getAddr;
import static de.tudarmstadt.ukp.clarin.webanno.support.lambda.LambdaBehavior.enabledWhen;
import static de.tudarmstadt.ukp.clarin.webanno.support.lambda.LambdaBehavior.visibleWhen;
import static java.lang.Math.min;
import static java.util.Collections.emptyList;
import static java.util.stream.Collectors.groupingBy;
import static org.apache.commons.lang3.StringUtils.isBlank;
Expand Down Expand Up @@ -231,7 +232,8 @@ protected void populateItem(Item<ResultsGroup> item)
Label numberOfResults = new Label("numberOfResults");
numberOfResults.setDefaultModel(LoadableDetachableModel.of(() -> String.format("%d-%d / %d",
searchResultGroups.getFirstItemOffset() + 1,
searchResultGroups.getFirstItemOffset() + searchResultGroups.getItemsPerPage(),
min(searchResultGroups.getFirstItemOffset() + searchResultGroups.getItemsPerPage(),
searchResultGroups.getItemCount()),
searchResultGroups.getItemCount())));
numberOfResults.add(visibleWhen(() -> groupedSearchResults.getObject() != null
&& !groupedSearchResults.getObject().isEmpty()));
Expand Down

0 comments on commit a005cdf

Please sign in to comment.