use of org.xwiki.rest.model.jaxb.SearchResults in project xwiki-platform by xwiki.
the class WikisResourceTest method testSearchWikis.
@Test
public void testSearchWikis() throws Exception {
this.testUtils.rest().delete(reference);
this.testUtils.rest().savePage(reference, "content" + this.pageName, "title" + this.pageName);
GetMethod getMethod = executeGet(String.format("%s?q=content" + this.pageName, buildURI(WikiSearchResource.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);
for (SearchResult searchResult : searchResults.getSearchResults()) {
checkLinks(searchResult);
}
getMethod = executeGet(String.format("%s?q=" + this.pageName + "&scope=name", buildURI(WikiSearchResource.class, getWiki())));
Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());
searchResults = (SearchResults) unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());
resultSize = searchResults.getSearchResults().size();
assertEquals(1, resultSize);
for (SearchResult searchResult : searchResults.getSearchResults()) {
checkLinks(searchResult);
}
// Search in titles
getMethod = executeGet(String.format("%s?q=title" + this.pageName + "&scope=title", buildURI(WikiSearchResource.class, getWiki())));
Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());
searchResults = (SearchResults) unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());
resultSize = searchResults.getSearchResults().size();
assertEquals(1, resultSize);
for (SearchResult searchResult : searchResults.getSearchResults()) {
checkLinks(searchResult);
}
// Search for space names
getMethod = executeGet(String.format("%s?q=" + this.spaces.get(0) + "&scope=spaces", buildURI(WikiSearchResource.class, getWiki())));
Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());
searchResults = (SearchResults) unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());
resultSize = searchResults.getSearchResults().size();
assertEquals(1, resultSize);
for (SearchResult searchResult : searchResults.getSearchResults()) {
checkLinks(searchResult);
}
}
use of org.xwiki.rest.model.jaxb.SearchResults in project xwiki-platform by xwiki.
the class WikisResourceTest method testSolrSearch.
@Test
public void testSolrSearch() 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 + "\"&type=solr", 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);
assertEquals(this.fullName, searchResults.getSearchResults().get(0).getPageFullName());
}
use of org.xwiki.rest.model.jaxb.SearchResults in project xwiki-platform by xwiki.
the class WikiManagerRestTest method testMultiwikiSearch.
// FIXME: Test is disabled for the moment. It works if tested against MySQL but with HSQLDB it seems that the
// Lucene plugin is not triggered. Anyway this should be better to rewrite it, if possible, as a unit test.
@Ignore("This test doesn't seem to work correctly with HSQLDB but it actually works if run against MySQL.")
@Test
public void testMultiwikiSearch() throws Exception {
String WIKI1_ID = "w1";
String WIKI2_ID = "w2";
String PAGE_SPACE = "Main";
String PAGE_NAME = "Test";
String PAGE1_STRING = "foo";
String PAGE2_STRING = "bar";
Wiki wiki = objectFactory.createWiki();
wiki.setId(WIKI1_ID);
PostMethod postMethod = executePost(getFullUri(WikiManagerREST.class), "superadmin", "pass", wiki);
Assert.assertEquals(HttpStatus.SC_CREATED, postMethod.getStatusCode());
wiki = objectFactory.createWiki();
wiki.setId(WIKI2_ID);
postMethod = executePost(getFullUri(WikiManagerREST.class), "superadmin", "pass", wiki);
Assert.assertEquals(HttpStatus.SC_CREATED, postMethod.getStatusCode());
/* Store the page */
Page page1 = objectFactory.createPage();
page1.setTitle(PAGE1_STRING);
page1.setContent(PAGE1_STRING);
PutMethod putMethod = executePut(getUriBuilder(PageResource.class).build(WIKI1_ID, PAGE_SPACE, PAGE_NAME).toString(), "superadmin", "pass", page1);
Assert.assertEquals(HttpStatus.SC_CREATED, putMethod.getStatusCode());
page1 = (Page) unmarshaller.unmarshal(putMethod.getResponseBodyAsStream());
/* Retrieve the page to check that it exists */
GetMethod getMethod = executeGet(getUriBuilder(PageResource.class).build(WIKI1_ID, PAGE_SPACE, PAGE_NAME).toString());
Assert.assertEquals(HttpStatus.SC_OK, getMethod.getStatusCode());
Page page = (Page) unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());
Assert.assertEquals(WIKI1_ID, page.getWiki());
Assert.assertEquals(PAGE_SPACE, page.getSpace());
Assert.assertEquals(PAGE_NAME, page.getName());
Assert.assertEquals(PAGE1_STRING, page.getTitle());
Assert.assertEquals(PAGE1_STRING, page.getContent());
Assert.assertEquals(page1.getCreated(), page.getCreated());
Assert.assertEquals(page1.getModified(), page.getModified());
/* Store the page */
Page page2 = objectFactory.createPage();
page2.setTitle(PAGE2_STRING);
page2.setContent(PAGE2_STRING);
putMethod = executePut(getUriBuilder(PageResource.class).build(WIKI2_ID, PAGE_SPACE, PAGE_NAME).toString(), "superadmin", "pass", page2);
Assert.assertEquals(HttpStatus.SC_CREATED, putMethod.getStatusCode());
page2 = (Page) unmarshaller.unmarshal(putMethod.getResponseBodyAsStream());
/* Retrieve the page to check that it exists */
getMethod = executeGet(getUriBuilder(PageResource.class).build(WIKI2_ID, PAGE_SPACE, PAGE_NAME).toString());
Assert.assertEquals(HttpStatus.SC_OK, getMethod.getStatusCode());
page = (Page) unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());
Assert.assertEquals(WIKI2_ID, page.getWiki());
Assert.assertEquals(PAGE_SPACE, page.getSpace());
Assert.assertEquals(PAGE_NAME, page.getName());
Assert.assertEquals(PAGE2_STRING, page.getTitle());
Assert.assertEquals(PAGE2_STRING, page.getContent());
Assert.assertEquals(page2.getCreated(), page.getCreated());
Assert.assertEquals(page2.getModified(), page.getModified());
/* Wait a bit that the Lucene Indexer indexes the pages. */
Thread.sleep(5000);
getMethod = executeGet(URIUtil.encodeQuery(String.format("%s?q=\"%s\"&wikis=w1,w2", getFullUri(WikisSearchQueryResource.class), PAGE_NAME)));
Assert.assertEquals(HttpStatus.SC_OK, getMethod.getStatusCode());
SearchResults searchResults = (SearchResults) unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());
Assert.assertEquals(2, searchResults.getSearchResults().size());
for (SearchResult searchResult : searchResults.getSearchResults()) {
Page pageToBeCheckedAgainst = null;
if (searchResult.getWiki().equals(WIKI1_ID)) {
pageToBeCheckedAgainst = page1;
} else {
pageToBeCheckedAgainst = page2;
}
Assert.assertEquals(pageToBeCheckedAgainst.getWiki(), searchResult.getWiki());
Assert.assertEquals(pageToBeCheckedAgainst.getTitle(), searchResult.getTitle());
Assert.assertEquals(pageToBeCheckedAgainst.getAuthor(), searchResult.getAuthor());
Assert.assertEquals(pageToBeCheckedAgainst.getModified(), searchResult.getModified());
Assert.assertEquals(pageToBeCheckedAgainst.getVersion(), searchResult.getVersion());
}
}
use of org.xwiki.rest.model.jaxb.SearchResults in project xwiki-platform by xwiki.
the class WikiSearchResourceImpl method search.
@Override
public SearchResults search(String wikiName, String keywords, List<String> searchScopeStrings, Integer number, Integer start, String orderField, String order, Boolean withPrettyNames) throws XWikiRestException {
try {
SearchResults searchResults = objectFactory.createSearchResults();
searchResults.setTemplate(String.format("%s?%s", Utils.createURI(uriInfo.getBaseUri(), WikiSearchResource.class, wikiName).toString(), SEARCH_TEMPLATE_INFO));
if (wikiName != null) {
Utils.getXWikiContext(componentManager).setWikiId(wikiName);
}
List<SearchScope> searchScopes = parseSearchScopeStrings(searchScopeStrings);
searchResults.getSearchResults().addAll(search(searchScopes, keywords, getXWikiContext().getWikiId(), null, Utils.getXWiki(componentManager).getRightService().hasProgrammingRights(Utils.getXWikiContext(componentManager)), number, start, true, orderField, order, withPrettyNames));
return searchResults;
} catch (Exception e) {
throw new XWikiRestException(e);
}
}
Aggregations