0

I am looking to have users enter their interests, which may or may not already be in the system, and store them in a schemaless database (GAE storage to be specific) in such a way that I can easily discover users with similar interests.

A similar example of what I am trying to do is LinkedIn's skills form.

I am familiar with how this would be done in a SQL datastore but am trying to expand my knowledge of schemaless datastores. Any help would be much appreciated.

1 Answers1

0
  1. Create an Entity with kind "Interest". Have the datastore generate ids automatically for these entities - this will take less space when you reference them from User entities. This entity may have a single property (e.g. "interest" or "text").

When a user enters a new interest, you check if an entity with this interest already exists. If yes, you add an id of this entity to the user's list of interests. If no, you first save a new entity for this interest, and then use the id of this entity.

  1. Create an Entity with kind "User". This entity will have a property "interests". You can save a collection of ids of interests in this property.

For example, in Java, using a low-level Datastore API, you would do:

public void saveUser(User user) {
    Entity userEntity = user.getId() == null ? new Entity("User") : new Entity("User", user.getId());
    if (user.getInterests() != null) {
        // user.getInterests() returns a collection, e.g. an ArrayList<Long>
        userEntity.setProperty("interests", user.getInterests());
    }
    datastore.put(userEntity);
}

public User getUser(Entity entity) {
    User user = new User();
    user.setId(entity.getKey().getId());
    user.setInterests(entity.getProperty("interests"));
    return user;
}

Note that the property "interests" is indexed, so you can run a query to find all users with a specific interest.

Andrei Volgin
  • 40,755
  • 6
  • 49
  • 58