spring-projects / spring-data-neo4j

Provide support to increase developer productivity in Java when using Neo4j. Uses familiar Spring concepts such as a template classes for core API usage and lightweight repository style data access.
http://spring.io/projects/spring-data-neo4j
Apache License 2.0
828 stars 620 forks source link

Search by @DynamicLabels #2638

Closed iva-bashmat closed 1 year ago

iva-bashmat commented 1 year ago

There is a way to retrieve dynamic labels for a node, but no way to create method to search by them. Check following example:

Node:

@Node("Port")
public class Port {
    @Id
    private Long id;
    private String code;
    @DynamicLabels
    private List<String> labels;
}

Repository:

public interface PortRepository extends Neo4jRepository<Port, Long> {
    List<Port> findByLabelsContaining(String label);
}

Actual query:

MATCH (port:`Port`) 
WHERE $label IN port.labels
RETURN port{.code, .id, __nodeLabels__: labels(port), __internalNeo4jId__: id(port)}

Expected query:

MATCH (port:`Port`) 
WHERE $label IN labels(port)
RETURN port{.code, .id, __nodeLabels__: labels(port), __internalNeo4jId__: id(port)}
michael-simons commented 1 year ago

Good point, thanks for raising it.

iva-bashmat commented 1 year ago

Thanks a lot!