Search in sources :

Example 1 with SearchResult

use of org.exoplatform.commons.api.search.data.SearchResult in project social by Meeds-io.

the class SpaceSearchConnector method search.

@Override
public Collection<SearchResult> search(SearchContext context, String query, Range range, Sorting sorting) {
    List<SearchResult> results = new ArrayList<SearchResult>();
    SpaceFilter filter = new SpaceFilter();
    filter.setSpaceNameSearchCondition(query);
    filter.setSorting(sorting);
    // if condition only have special characters or empty
    if (filter.getSpaceNameSearchCondition().isEmpty()) {
        return results;
    }
    ExoContainerContext eXoContext = (ExoContainerContext) ExoContainerContext.getCurrentContainer().getComponentInstanceOfType(ExoContainerContext.class);
    String portalName = eXoContext.getPortalContainerName();
    ListAccess<Space> la = spaceService.getUnifiedSearchSpacesWithListAccess(getCurrentUserName(), filter);
    // 
    try {
        Space[] spaces = la.load(range.offset, range.limit);
        // 
        RowIterator rowIt = rows(buildQuery(filter), range.offset, range.limit);
        Row row = null;
        // 
        for (Space s : spaces) {
            // 
            if (Space.HIDDEN.equals(s.getVisibility()) && !spaceService.isMember(s, getCurrentUserName()))
                continue;
            // 
            StringBuilder sb = new StringBuilder(s.getDisplayName());
            sb.append(String.format(" - %s Member(s)", s.getMembers().length));
            if (Space.OPEN.equals(s.getRegistration())) {
                sb.append(" - Free to Join");
            } else if (Space.VALIDATION.equals(s.getRegistration())) {
                sb.append(" - Register");
            } else if (Space.CLOSE.equals(s.getRegistration())) {
                sb.append(" - Invitation Only");
            } else {
                LOG.debug(s.getRegistration() + " registration unknown");
            }
            // 
            row = (rowIt != null && rowIt.hasNext()) ? rowIt.nextRow() : null;
            // 
            SearchResult result = new SearchResult(getSpaceUrl(context, s, portalName), s.getDisplayName(), // getExcerpt(row),
            s.getDescription(), sb.toString(), s.getAvatarUrl() != null ? s.getAvatarUrl() : LinkProvider.SPACE_DEFAULT_AVATAR_URL, s.getCreatedTime(), getRelevancy(row));
            results.add(result);
        }
    } catch (Exception e) {
        LOG.error(e);
    }
    // 
    return results;
}
Also used : Space(org.exoplatform.social.core.space.model.Space) ArrayList(java.util.ArrayList) SearchResult(org.exoplatform.commons.api.search.data.SearchResult) SpaceFilter(org.exoplatform.social.core.space.SpaceFilter) RowIterator(javax.jcr.query.RowIterator) ExoContainerContext(org.exoplatform.container.ExoContainerContext) Row(javax.jcr.query.Row)

Example 2 with SearchResult

use of org.exoplatform.commons.api.search.data.SearchResult in project ecms by exoplatform.

the class TestDocumentSearchServiceConnector method testSearchSingle.

public void testSearchSingle() throws Exception {
    Collection<String> sites = new ArrayList<String>();
    sites.add("classic");
    Collection<SearchResult> ret = documentSearch_.search(new SearchContext(new Router(new ControllerDescriptor()), "classic"), "anthony~", sites, 0, 20, "title", "asc");
    // 2
    assertEquals(4, ret.size());
}
Also used : SearchContext(org.exoplatform.commons.api.search.data.SearchContext) Router(org.exoplatform.web.controller.router.Router) SearchResult(org.exoplatform.commons.api.search.data.SearchResult) ControllerDescriptor(org.exoplatform.web.controller.metadata.ControllerDescriptor)

Example 3 with SearchResult

use of org.exoplatform.commons.api.search.data.SearchResult in project ecms by exoplatform.

the class TestDocumentSearchServiceConnector method testSearchSingleWithOffset.

public void testSearchSingleWithOffset() throws Exception {
    Collection<String> sites = new ArrayList<String>();
    sites.add("classic");
    Collection<SearchResult> ret = documentSearch_.search(new SearchContext(new Router(new ControllerDescriptor()), "classic"), "anthony~", sites, 1, 20, "title", "asc");
    // 1
    assertEquals(3, ret.size());
}
Also used : SearchContext(org.exoplatform.commons.api.search.data.SearchContext) Router(org.exoplatform.web.controller.router.Router) SearchResult(org.exoplatform.commons.api.search.data.SearchResult) ControllerDescriptor(org.exoplatform.web.controller.metadata.ControllerDescriptor)

Example 4 with SearchResult

use of org.exoplatform.commons.api.search.data.SearchResult in project ecms by exoplatform.

the class TestDocumentSearchServiceConnector method testSearchDate.

/**
 * Test if returned date switch result is consistent
 * @throws Exception
 */
public void testSearchDate() throws Exception {
    long calendarBeforeSearch = Calendar.getInstance().getTimeInMillis();
    Collection<String> sites = new ArrayList<String>();
    sites.add("classic");
    Collection<SearchResult> ret = documentSearch_.search(new SearchContext(new Router(new ControllerDescriptor()), "classic"), "hopkins~", sites, 0, 20, "title", "asc");
    // 2
    assertEquals(4, ret.size());
    boolean matchFound = false;
    for (SearchResult searchResult : ret) {
        if (searchResult.getTitle().equals("Albert Einstein")) {
            // Search result don't have exo:dateModified and exo:dateCreated properties
            // The date should be added with a fake instance == now
            assertTrue("Retuned search result has an incoherent modified date", searchResult.getDate() > calendarBeforeSearch);
            matchFound = true;
        } else {
            // Search result have exo:dateModified and exo:dateCreated properties
            // the modification date should be before running this test
            assertTrue("Retuned search result has an incoherent modified date", searchResult.getDate() < calendarBeforeSearch);
        }
    }
    assertTrue("'Albert Einstein' content was not matched", matchFound);
}
Also used : SearchContext(org.exoplatform.commons.api.search.data.SearchContext) Router(org.exoplatform.web.controller.router.Router) SearchResult(org.exoplatform.commons.api.search.data.SearchResult) ControllerDescriptor(org.exoplatform.web.controller.metadata.ControllerDescriptor)

Example 5 with SearchResult

use of org.exoplatform.commons.api.search.data.SearchResult in project ecms by exoplatform.

the class TestDocumentSearchServiceConnector method testSearchDocumentByTagsShouldReturnNoResult.

public void testSearchDocumentByTagsShouldReturnNoResult() throws Exception {
    // Create Tags parent node
    Node root = session.getRootNode();
    Node applicationData = root.hasNode("Application Data") ? root.getNode("Application Data") : root.addNode("Application Data");
    Node tagsNode = applicationData.hasNode("Tags") ? applicationData.getNode("Tags") : applicationData.addNode("Tags");
    String[] tags = { "sport" };
    String site = "classic";
    String publicFolksonomyTreePath = "/Application Data/Tags";
    // Create node Article 5
    Node article5 = root.addNode("article 5", "exo:article");
    article5.setProperty("exo:title", "john");
    article5.setProperty("exo:text", "Smith");
    article5.addMixin(NodetypeConstant.EXO_DATETIME);
    session.save();
    // Add tag to document Article 5
    newFolksonomyService_.addPublicTag(publicFolksonomyTreePath, tags, article5, COLLABORATION_WS);
    Collection<SearchResult> ret = documentSearch_.search(new SearchContext(new Router(new ControllerDescriptor()), site), "music~", Collections.singleton(site), 0, 20, "", "asc");
    // No document is tagged with music
    assertEquals(0, ret.size());
}
Also used : Node(javax.jcr.Node) SearchContext(org.exoplatform.commons.api.search.data.SearchContext) Router(org.exoplatform.web.controller.router.Router) SearchResult(org.exoplatform.commons.api.search.data.SearchResult) ControllerDescriptor(org.exoplatform.web.controller.metadata.ControllerDescriptor)

Aggregations

SearchResult (org.exoplatform.commons.api.search.data.SearchResult)45 SearchContext (org.exoplatform.commons.api.search.data.SearchContext)21 ControllerDescriptor (org.exoplatform.web.controller.metadata.ControllerDescriptor)18 Router (org.exoplatform.web.controller.router.Router)18 ArrayList (java.util.ArrayList)11 InitParams (org.exoplatform.container.xml.InitParams)9 Test (org.junit.Test)9 Node (javax.jcr.Node)8 EcmsSearchResult (org.exoplatform.services.wcm.search.base.EcmsSearchResult)7 RepositoryException (javax.jcr.RepositoryException)6 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)6 PropertiesParam (org.exoplatform.container.xml.PropertiesParam)5 Profile (org.exoplatform.social.core.identity.model.Profile)4 Space (org.exoplatform.social.core.space.model.Space)4 MetadataItem (org.exoplatform.social.metadata.model.MetadataItem)4 MetadataObject (org.exoplatform.social.metadata.model.MetadataObject)4 Date (java.util.Date)3 List (java.util.List)3 Map (java.util.Map)3 SessionProvider (org.exoplatform.services.jcr.ext.common.SessionProvider)3