Skip to content

Commit

Permalink
Merge branch '0.17.x'
Browse files Browse the repository at this point in the history
* 0.17.x:
  No issue: Avoid locally failing builds because of the rat plugin stumbling over the NPM cache
  #1828 - Error in importing projects
  #1825 duplicates in search
  #1825 duplicates in search
  #1825 Search results contains duplicates
  #1825 Search results contains duplicates
  • Loading branch information
reckart committed Oct 27, 2020
2 parents 91c26d4 + fa8d006 commit bbf67e9
Show file tree
Hide file tree
Showing 10 changed files with 133 additions and 89 deletions.
1 change: 1 addition & 0 deletions inception-html-editor/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@
<exclude>src/main/java/de/tudarmstadt/ukp/inception/htmleditor/annotatorjs/resources/annotator.*</exclude>
<exclude>src/main/java/de/tudarmstadt/ukp/inception/htmleditor/annotatorjs/resources/annotator-full.*</exclude>
<exclude>src/main/js/annotatorjs/**/*</exclude>
<exclude>cache/**/*</exclude>
</excludes>
</configuration>
</execution>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,20 @@ public interface FeatureIndexingSupport
* features.
* @param aFeature
* the feature from which to extract the values.
* @return key/value pairs as a map
*/
MultiValuedMap<String, String> indexFeatureValue(String aFieldPrefix,
AnnotationFS aAnnotation, String aFeaturePrefix, AnnotationFeature aFeature);

/**
* Get the name of the feature how it is used in the index
* @param aFieldPrefix
* the layer name
* @param aFeaturePrefix possible prefix to the feature name,
* currently for source and target of relation annotations
* @param aFeature
* the feature
* @return index feature name
*/
String featureIndexName(String aFieldPrefix, String aFeaturePrefix, AnnotationFeature aFeature);
}
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ public void setSelectedForAnnotation(boolean selectedForAnnotation)
/**
* Indicates whether the document to which this result applies cannot be modified by the user
* who issued the query.
* @return whether the document is read-only
*/
public boolean isReadOnly()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,19 @@ List<SearchResult> query(User aUser, Project aProject, String aQuery)
throws IOException, ExecutionException;

/**
* Receive the search results un-grouped as a list. See
* {@link #query(User, Project, String, SourceDocument, AnnotationLayer, AnnotationFeature,
* Receive the search results un-grouped as a list.
* See{@link #query(User, Project, String, SourceDocument, AnnotationLayer, AnnotationFeature,
* long, long)}
* @param aUser
* the current user
* @param aProject
* the project to search in
* @param aQuery
* the search query
* @param aDocument
* limit search to this document or search in the whole project if null
* @throws IOException
* @throws ExecutionException
*/
List<SearchResult> query(User aUser, Project aProject, String aQuery, SourceDocument aDocument)
throws IOException, ExecutionException;
Expand All @@ -50,6 +60,8 @@ List<SearchResult> query(User aUser, Project aProject, String aQuery, SourceDocu
* the current user
* @param aProject
* the project to search in
* @param aQuery
* the search query
* @param aDocument
* limit search to this document or search in the whole project if null
* @param aAnnotationLayer
Expand All @@ -75,7 +87,10 @@ Map<String, List<SearchResult>> query(User aUser, Project aProject, String aQuer

/**
* This method is only for testing. It allows waiting until the indexing process has completed
* before issueing a query.
* before issuing a query.
* @param aProject
* the project
* @return whether the index is flagged as valid
*/
boolean isIndexValid(Project aProject);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
Expand Down Expand Up @@ -167,6 +166,7 @@ private Index loadIndex(long aProjectId)
*
* @param aEvent
* The BeforeProjectRemovedEvent event
* @throws IOException
*/
@EventListener
public void beforeProjectRemove(BeforeProjectRemovedEvent aEvent) throws IOException
Expand Down Expand Up @@ -311,7 +311,6 @@ public void indexDocument(SourceDocument aSourceDocument, byte[] aBinaryCas)
// threads to update the index concurrently. The underlying index code should hopefully
// be thread-safe...
try {
index.getPhysicalIndex().deindexDocument(aSourceDocument);
index.getPhysicalIndex().indexDocument(aSourceDocument, aBinaryCas);
}
catch (IOException e) {
Expand Down Expand Up @@ -355,34 +354,12 @@ public void indexDocument(AnnotationDocument aAnnotationDocument, byte[] aBinary
// threads to update the index concurrently. The underlying index code should hopefully
// be thread-safe...
try {
// NOTE: Deleting and then re-indexing the annotation document could lead to
// no results for this annotation document being returned while the
// re-indexing is still in process. Therefore, we check if there is already
// a version of the annotation document index, we obtain the timestamp of this
// version, then we add the new version, and finally we remove the old version
// as identified by the timestamp.

// Retrieve the timestamp for the current indexed annotation document
Optional<String> oldVersionTimestamp = index.getPhysicalIndex()
.getTimestamp(aAnnotationDocument);

// Add annotation document to the index again
log.trace(
"Indexing new version of annotation document [{}]({}) in project [{}]({})",
aAnnotationDocument.getName(), aAnnotationDocument.getId(),
project.getName(), project.getId());
index.getPhysicalIndex().indexDocument(aAnnotationDocument, aBinaryCas);

// If there was a previous timestamped indexed annotation document, remove it from
// index
if (oldVersionTimestamp.isPresent()) {
log.trace(
"Removing old version of annotation document [{}]({}) in project [{}]({}) with timestamp [{}]",
aAnnotationDocument.getName(), aAnnotationDocument.getId(),
project.getName(), project.getId(), oldVersionTimestamp.get());
index.getPhysicalIndex().deindexDocument(aAnnotationDocument,
oldVersionTimestamp.get());
}
}
catch (IOException e) {
log.error("Error indexing annotation document [{}]({}) in project [{}]({})",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public String getQuery()

/**
* Query is limited to the given document.
* @return the source document if it exists or empty optional
*/
public Optional<SourceDocument> getSourceDocument()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public interface PhysicalIndex
/**
* Deletes the index data, e.g. by removing the index files from disk. If necessary, the index
* is closed before.
* @throws IOException
*/
void delete() throws IOException;

Expand All @@ -50,26 +51,29 @@ Map<String, List<SearchResult>> executeQuery(SearchQueryRequest aRequest)

long numberOfQueryResults(SearchQueryRequest aSearchQueryRequest)
throws IOException, ExecutionException;

void indexDocument(SourceDocument aDocument, byte[] aBinaryCas) throws IOException;

void indexDocument(AnnotationDocument aDocument, byte[] aBinaryCas) throws IOException;

void deindexDocument(SourceDocument aDocument) throws IOException;

void deindexDocument(AnnotationDocument aDocument) throws IOException;

void deindexDocument(AnnotationDocument aDocument, String aTimestamp) throws IOException;

void indexDocument(AnnotationDocument aDocument, byte[] aBinaryCas) throws IOException;

void clear() throws IOException;

/**
* Retrieve the timestamp of this annotation document
* @param aDocument
* The annotation document
* @return
* The document timestamp field value. Empty string if document is not found.
*
* @param aSrcDocId
* the source document's ID
* @param aAnnoDocId
* the annotation document's ID
* @return The first found document timestamp field value. Empty string if document is not
* found.
* @throws IOException
*/
public Optional<String> getTimestamp(AnnotationDocument aDocument) throws IOException;
public Optional<String> getTimestamp(long aSrcDocId, long aAnnoDocId) throws IOException;

void indexDocument(SourceDocument aSourceDocument, byte[] aBinaryCas) throws IOException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ public String toString()
/**
* Used to avoid scheduling duplicate tasks. Returns true if the current task is a duplicate of
* the given task.
*
* @param aTask
* the given scheduling task
* @return whether the given task matches this one
*/
public abstract boolean matches(Task aTask);

Expand Down
Loading

0 comments on commit bbf67e9

Please sign in to comment.