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;
}
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());
}
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());
}
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);
}
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());
}
Aggregations