Search in sources :

Example 1 with SearchResult

use of im.actor.core.entity.SearchResult in project actor-platform by actorapp.

the class GlobalSearchSource method loadGlobalResults.

private void loadGlobalResults(String query, ArrayList<SearchResult> localResults, Consumer<List<SearchResult>> callback) {
    context().getSearchModule().findPeers(query).then(r -> {
        ArrayList<SearchResult> results = new ArrayList<>();
        outer: for (PeerSearchEntity peerSearch : r) {
            for (SearchResult l : localResults) {
                if (peerSearch.getPeer().equals(l.getPeer())) {
                    continue outer;
                }
            }
            if (peerSearch.getPeer().getPeerType() == PeerType.GROUP) {
                Group group = context().getGroupsModule().getGroups().getValue(peerSearch.getPeer().getPeerId());
                results.add(new SearchResult(peerSearch.getPeer(), group.getAvatar(), group.getTitle(), peerSearch.getOptMatchString()));
            } else if (peerSearch.getPeer().getPeerType() == PeerType.PRIVATE) {
                UserVM user = context().getUsersModule().getUsers().get(peerSearch.getPeer().getPeerId());
                results.add(new SearchResult(peerSearch.getPeer(), user.getAvatar().get(), user.getName().get(), peerSearch.getOptMatchString()));
            }
        }
        if (results.size() > 0) {
            ArrayList<SearchResult> combined = new ArrayList<>();
            combined.addAll(localResults);
            combined.addAll(results);
            callback.apply(combined);
        }
    });
}
Also used : Group(im.actor.core.entity.Group) PeerSearchEntity(im.actor.core.entity.PeerSearchEntity) UserVM(im.actor.core.viewmodel.UserVM) ArrayList(java.util.ArrayList) SearchResult(im.actor.core.entity.SearchResult)

Example 2 with SearchResult

use of im.actor.core.entity.SearchResult in project actor-platform by actorapp.

the class GlobalSearchSource method loadResults.

@Override
public void loadResults(String query, Consumer<List<SearchResult>> callback) {
    ListEngine<SearchEntity> searchList = context().getSearchModule().getSearchList();
    if (searchList instanceof ListEngineDisplayExt) {
        ((ListEngineDisplayExt<SearchEntity>) searchList).loadBackward(query, 20, (items, topSortKey, bottomSortKey) -> {
            ArrayList<SearchResult> localResults = new ArrayList<>();
            for (SearchEntity e : items) {
                localResults.add(new SearchResult(e.getPeer(), e.getAvatar(), e.getTitle(), null));
            }
            callback.apply(new ArrayList<>(localResults));
            if (query.length() > 3) {
                loadGlobalResults(query, localResults, callback);
            }
        });
    } else {
        if (query.length() > 3) {
            loadGlobalResults(query, new ArrayList<>(), callback);
        } else {
            callback.apply(new ArrayList<>());
        }
    }
}
Also used : ListEngineDisplayExt(im.actor.runtime.storage.ListEngineDisplayExt) PeerSearchEntity(im.actor.core.entity.PeerSearchEntity) SearchEntity(im.actor.core.entity.SearchEntity) ArrayList(java.util.ArrayList) SearchResult(im.actor.core.entity.SearchResult)

Aggregations

PeerSearchEntity (im.actor.core.entity.PeerSearchEntity)2 SearchResult (im.actor.core.entity.SearchResult)2 ArrayList (java.util.ArrayList)2 Group (im.actor.core.entity.Group)1 SearchEntity (im.actor.core.entity.SearchEntity)1 UserVM (im.actor.core.viewmodel.UserVM)1 ListEngineDisplayExt (im.actor.runtime.storage.ListEngineDisplayExt)1