Search in sources :

Example 6 with ScoredDocument

use of com.google.appengine.api.search.ScoredDocument in project blogwt by billy1380.

the class PageService method search.

/* (non-Javadoc)
	 * 
	 * @see com.willshex.blogwt.server.service.search.ISearch#search(java.lang.
	 * String, java.lang.Integer, java.lang.Integer, java.lang.String,
	 * com.willshex.blogwt.shared.api.SortDirectionType) */
@Override
public List<Page> search(String query, Integer start, Integer count, String sortBy, SortDirectionType direction) {
    Results<ScoredDocument> matches = SearchHelper.getIndex().search(query);
    List<Page> pages = new ArrayList<Page>();
    String id;
    Page page;
    int limit = count;
    final String pageServiceName = getName();
    for (ScoredDocument scoredDocument : matches) {
        if (limit == 0) {
            break;
        }
        if ((id = scoredDocument.getId()).startsWith(getName())) {
            page = getPage(Long.valueOf(id.replace(pageServiceName, "")));
            if (page != null) {
                pages.add(page);
            }
        }
        limit--;
    }
    return pages;
}
Also used : ScoredDocument(com.google.appengine.api.search.ScoredDocument) ArrayList(java.util.ArrayList) Page(com.willshex.blogwt.shared.api.datatype.Page)

Example 7 with ScoredDocument

use of com.google.appengine.api.search.ScoredDocument in project blogwt by billy1380.

the class UserService method search.

/* (non-Javadoc)
	 * 
	 * @see com.willshex.blogwt.server.service.search.ISearch#search(java.lang.
	 * String, java.lang.Integer, java.lang.Integer, java.lang.String,
	 * com.willshex.blogwt.shared.api.SortDirectionType) */
@Override
public List<User> search(String query, Integer start, Integer count, String sortBy, SortDirectionType direction) {
    Results<ScoredDocument> matches = SearchHelper.getIndex().search(query);
    List<User> users = new ArrayList<User>();
    String id;
    User user;
    int limit = count;
    final String userServiceName = getName();
    for (ScoredDocument scoredDocument : matches) {
        if (limit == 0) {
            break;
        }
        if ((id = scoredDocument.getId()).startsWith(userServiceName)) {
            user = getUser(Long.valueOf(id.replace(userServiceName, "")));
            if (user != null) {
                users.add(user);
            }
        }
        limit--;
    }
    return users;
}
Also used : ScoredDocument(com.google.appengine.api.search.ScoredDocument) User(com.willshex.blogwt.shared.api.datatype.User) ArrayList(java.util.ArrayList)

Aggregations

ScoredDocument (com.google.appengine.api.search.ScoredDocument)7 ArrayList (java.util.ArrayList)6 Cursor (com.google.appengine.api.search.Cursor)3 QueryOptions (com.google.appengine.api.search.QueryOptions)2 SortOptions (com.google.appengine.api.search.SortOptions)2 Page (com.willshex.blogwt.shared.api.datatype.Page)1 Post (com.willshex.blogwt.shared.api.datatype.Post)1 User (com.willshex.blogwt.shared.api.datatype.User)1