objectify query filter by list in entity contains search parameter

谁说胖子不能爱 提交于 2019-12-04 05:27:38

Generally, you do this one of two ways:

Put a property of Set<Key<Employee>> on the Event

or

Put a property of Set<Key<Event>> on the Employee

You could also create a relationship entity, but if you're just doing filtering on values with relatively low counts, usually it's easier to just put the set property on one entity or the other.

Then filter as you describe:

ofy.query(Event.class).filter("employees", employee).list()

or

ofy.query(Employee.class).filter("events", event).list()

The list property should hold a Keys to the target entity. If you pass in an entity to the filter() method, Objectify will understand that you want to filter by the key instead.

Example : /***************************************************/

@Entity

@Cache

public class News {

@Id Long id;
String news ;
@Index List<Long> friend_list = new ArrayList<Long>();

// My friends who can see my news , exemele : friend_list.add(id_f1); friend_list.add(id_f2); friend_list.add(id_f3);

//To make an operation on "friend_list", it is obligatory to index it

}

/*************************************************/

public News(Long id_f){

    List<Long> friend_id = new ArrayList<Long>();
    friend_id.add(id_f);

Query<Nesw> query = ofy().load().type(News.class).filter("friend_list in",friend_id).limit(limit); 

//To filter a list, just after the name of the field you want to filter, add "IN".

//here ==> .filter("friend_list in",friend_id);

// if friend_list contains "id_friend" ==> the query return value

    .........

}

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!