use of org.xwiki.rest.model.jaxb.SearchResults in project xwiki-platform by xwiki.
the class SpaceSearchResourceImpl method search.
@Override
public SearchResults search(String wikiName, String spaceName, String keywords, List<String> searchScopeStrings, Integer number, Integer start, String orderField, String order, Boolean withPrettyNames) throws XWikiRestException {
List<String> spaces = parseSpaceSegments(spaceName);
try {
SearchResults searchResults = objectFactory.createSearchResults();
searchResults.setTemplate(String.format("%s?%s", Utils.createURI(uriInfo.getBaseUri(), SpaceSearchResource.class, wikiName, spaces).toString(), SEARCH_TEMPLATE_INFO));
List<SearchScope> searchScopes = parseSearchScopeStrings(searchScopeStrings);
searchResults.getSearchResults().addAll(search(searchScopes, keywords, wikiName, Utils.getLocalSpaceId(spaces), Utils.getXWiki(componentManager).getRightService().hasProgrammingRights(Utils.getXWikiContext(componentManager)), number, start, true, orderField, order, withPrettyNames));
return searchResults;
} catch (Exception e) {
throw new XWikiRestException(e);
}
}
use of org.xwiki.rest.model.jaxb.SearchResults in project xwiki-platform by xwiki.
the class WikiSearchQueryResourceImpl method search.
@Override
public SearchResults search(String wikiName, String query, String queryTypeString, Integer number, Integer start, Boolean distinct, String orderField, String order, Boolean withPrettyNames, String className) throws XWikiRestException {
try {
SearchResults searchResults = objectFactory.createSearchResults();
searchResults.setTemplate(String.format("%s?%s", Utils.createURI(uriInfo.getBaseUri(), WikiSearchQueryResource.class, wikiName).toString(), QUERY_TEMPLATE_INFO));
searchResults.getSearchResults().addAll(searchQuery(query, queryTypeString, wikiName, null, Utils.getXWiki(componentManager).getRightService().hasProgrammingRights(Utils.getXWikiContext(componentManager)), orderField, order, distinct, number, start, withPrettyNames, className));
return searchResults;
} catch (Exception e) {
throw new XWikiRestException(e);
}
}
use of org.xwiki.rest.model.jaxb.SearchResults in project xwiki-platform by xwiki.
the class WikisResourceTest method testHQLQuerySearchWithClassnameNotAuthenticated.
@Test
public void testHQLQuerySearchWithClassnameNotAuthenticated() throws Exception {
GetMethod getMethod = executeGet(URIUtil.encodeQuery(String.format("%s?q=where doc.space='XWiki' and doc.name='XWikiPreferences'&type=hql&className=XWiki.XWikiGlobalRights", buildURI(WikiSearchQueryResource.class, getWiki()))));
Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());
SearchResults searchResults = (SearchResults) unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());
int resultSize = searchResults.getSearchResults().size();
assertEquals(1, resultSize);
assertNull(searchResults.getSearchResults().get(0).getObject());
}
use of org.xwiki.rest.model.jaxb.SearchResults in project xwiki-platform by xwiki.
the class WikisResourceTest method testGlobalSearch.
@Test
public void testGlobalSearch() throws Exception {
this.testUtils.rest().delete(this.reference);
this.testUtils.rest().savePage(this.reference);
this.solrUtils.waitEmpyQueue();
GetMethod getMethod = executeGet(URIUtil.encodeQuery(String.format("%s?q=\"" + this.pageName + "\"", buildURI(WikisSearchQueryResource.class, getWiki()))));
Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());
SearchResults searchResults = (SearchResults) unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());
int resultSize = searchResults.getSearchResults().size();
assertEquals(1, resultSize);
assertEquals(this.fullName, searchResults.getSearchResults().get(0).getPageFullName());
}
use of org.xwiki.rest.model.jaxb.SearchResults in project xwiki-platform by xwiki.
the class WikisResourceTest method testObjectSearchAuthenticated.
@Test
public void testObjectSearchAuthenticated() throws Exception {
/* Check search for an object containing XWiki.Admin (i.e., the admin profile) */
GetMethod getMethod = executeGet(String.format("%s?q=XWiki.XWikiGuest&scope=objects", buildURI(WikiSearchResource.class, getWiki())), TestUtils.SUPER_ADMIN_CREDENTIALS.getUserName(), TestUtils.SUPER_ADMIN_CREDENTIALS.getPassword());
Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());
SearchResults searchResults = (SearchResults) unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());
/*
* We get more results because previous tests have also created comments on behalf of XWiki.Admin. They will
* appear in the results.
*/
int resultSize = searchResults.getSearchResults().size();
Assert.assertTrue(String.format("Found %s results", resultSize), resultSize >= 1);
}
Aggregations