Github user ejwhite922 commented on a diff in the pull request:

    https://github.com/apache/incubator-rya/pull/153#discussion_r134297278
  
    --- Diff: 
extras/indexing/src/main/java/org/apache/rya/indexing/entity/storage/mongo/MongoEntityStorage.java
 ---
    @@ -242,4 +283,84 @@ private static Bson makeExplicitTypeFilter(final 
RyaURI typeId) {
     
             return Stream.of(dataTypeFilter, valueFilter);
         }
    +
    +    private boolean detectDuplicates(final Entity entity) throws 
EntityStorageException {
    +        boolean hasDuplicate = false;
    +        if (duplicateDataDetector.isDetectionEnabled()) {
    +            // Grab all entities that have all the same explicit types as 
our
    +            // original Entity.
    +            final List<Entity> comparisonEntities = 
searchHasAllExplicitTypes(entity.getExplicitTypeIds());
    +
    +            // Now that we have our set of potential duplicates, compare 
them.
    +            // We can stop when we find one duplicate.
    +            for (final Entity compareEntity : comparisonEntities) {
    +                try {
    +                    hasDuplicate = 
duplicateDataDetector.compareEntities(entity, compareEntity);
    +                } catch (final SmartUriException e) {
    +                    throw new EntityStorageException("Encountered an error 
while comparing entities.", e);
    +                }
    +                if (hasDuplicate) {
    +                    break;
    +                }
    +            }
    +        }
    +        return hasDuplicate;
    +    }
    +
    +    /**
    +     * Searches the Entity storage for all Entities that contain all the
    +     * specified explicit type IDs.
    +     * @param explicitTypeIds the {@link ImmutableList} of {@link RyaURI}s 
that
    +     * are being searched for.
    +     * @return the {@link List} of {@link Entity}s that have all the 
specified
    +     * explicit type IDs. If nothing was found an empty {@link List} is
    +     * returned.
    +     * @throws EntityStorageException
    +     */
    +    private List<Entity> searchHasAllExplicitTypes(final 
ImmutableList<RyaURI> explicitTypeIds) throws EntityStorageException {
    +        final List<Entity> hasAllExplicitTypesEntities = new ArrayList<>();
    +        if (!explicitTypeIds.isEmpty()) {
    +            // Grab the first type from the explicit type IDs.
    +            final RyaURI firstType = explicitTypeIds.get(0);
    +
    +            // Check if that type exists anywhere in storage.
    +            final List<RyaURI> subjects = new ArrayList<>();
    +            Optional<Type> type;
    +            try {
    +                if (mongoTypeStorage == null) {
    +                    mongoTypeStorage = new MongoTypeStorage(mongo, 
ryaInstanceName);
    +                }
    +                type = mongoTypeStorage.get(firstType);
    +            } catch (final TypeStorageException e) {
    +                throw new EntityStorageException("Unable to get entity 
type: " + firstType, e);
    +            }
    +            if (type.isPresent()) {
    +                // Grab the subjects for all the types we found matching 
"firstType"
    +                final ConvertingCursor<TypedEntity> cursor = 
search(Optional.empty(), type.get(), Collections.emptySet());
    --- End diff --
    
    To clarify one the first point, querying with fuzzy-matching for properties 
is not supported by Rya and would need to be done at the MongoDB level.  A new 
JIRA ticket for that improvement has been opened, 
[RYA-349](https://issues.apache.org/jira/browse/RYA-349).


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to