Reputation: 1013
I'm trying to use graphAware's neo4j recommendation engine (https://github.com/graphaware/neo4j-reco). I'm new to a lot of the technologies involved, but as I understand after I have my recommendation engine built I run the following to get my recommendations:
List<Recommendation<Node>> recoForVince = recommendationEngine.recommend(getPersonByName("Vince"), new SimpleConfig(2));
The examples getPersonByName is this:
private Node getPersonByName(String name) {
return IterableUtils.getSingle(getDatabase().findNodes(DynamicLabel.label("Person"), "name", name));
}
The problem is as I understand it that'll only work if your neo4j server is embedded. We are looking at using spring for our mvc setup and with that we'll have something like:
We will be getting our data with something like:
@Repository
public interface PersonRepository extends GraphRepository<Person> {
@Query("MATCH (p:Person) WHERE m.name = {name} RETURN p")
Person findByTitleContaining(@Param("name") String name);
}
or maybe returned as a Hashmap. My issue is I'm unclear how I can convert either of these results into a Node object that would be usable by the Graphaware framework or how I should go about getting a Node object.
Upvotes: 0
Views: 132
Reputation: 20185
If you run Neo4j in embedded mode, you'll have anyway access to the GraphDatabaseService
.
In your Person
entity you have access to the GraphId
property which is the node internal id.
So you can, in for example your custom RecommendationService, retrieve the Node
object for this id :
private final GraphDatabaseService database;
private final MyRecommendationEngine engine;
@Autowired
public RecommendationService(GraphDatabaseService database, MyRecommendationEngine engine) {
this.database = database;
this.engine = engine;
public List<Recommendation<Node>> processRecommendation(Person person) {
Node node = database.getNodeById(person.getId());
return engine.recommend(node);
}
Please note that this will return Node
objects, if you want to convert them to Person
entities you'll need to handle the hydration yourself.
If you run Neo4j in ServerMode and SDN4 is at your application level then, the best would be to make http request calls to the endpoints provided by the Neo4j-Reco plugin. You can pass then only the name of the Person or his id.
You can see an example here : https://github.com/graphaware/recommendations-meetup
Upvotes: 3