Search in sources :

Example 1 with SearchResults

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);
    }
}
Also used : XWikiRestException(org.xwiki.rest.XWikiRestException) SearchResults(org.xwiki.rest.model.jaxb.SearchResults) SpaceSearchResource(org.xwiki.rest.resources.spaces.SpaceSearchResource) XWikiRestException(org.xwiki.rest.XWikiRestException)

Example 2 with SearchResults

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);
    }
}
Also used : XWikiRestException(org.xwiki.rest.XWikiRestException) WikiSearchQueryResource(org.xwiki.rest.resources.wikis.WikiSearchQueryResource) SearchResults(org.xwiki.rest.model.jaxb.SearchResults) XWikiRestException(org.xwiki.rest.XWikiRestException)

Example 3 with SearchResults

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());
}
Also used : WikiSearchQueryResource(org.xwiki.rest.resources.wikis.WikiSearchQueryResource) GetMethod(org.apache.commons.httpclient.methods.GetMethod) SearchResults(org.xwiki.rest.model.jaxb.SearchResults) AbstractHttpTest(org.xwiki.test.rest.framework.AbstractHttpTest) Test(org.junit.Test)

Example 4 with SearchResults

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());
}
Also used : WikisSearchQueryResource(org.xwiki.rest.resources.wikis.WikisSearchQueryResource) GetMethod(org.apache.commons.httpclient.methods.GetMethod) SearchResults(org.xwiki.rest.model.jaxb.SearchResults) AbstractHttpTest(org.xwiki.test.rest.framework.AbstractHttpTest) Test(org.junit.Test)

Example 5 with SearchResults

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);
}
Also used : GetMethod(org.apache.commons.httpclient.methods.GetMethod) SearchResults(org.xwiki.rest.model.jaxb.SearchResults) AbstractHttpTest(org.xwiki.test.rest.framework.AbstractHttpTest) Test(org.junit.Test)

Aggregations

SearchResults (org.xwiki.rest.model.jaxb.SearchResults)14 GetMethod (org.apache.commons.httpclient.methods.GetMethod)10 Test (org.junit.Test)10 AbstractHttpTest (org.xwiki.test.rest.framework.AbstractHttpTest)9 WikiSearchQueryResource (org.xwiki.rest.resources.wikis.WikiSearchQueryResource)5 XWikiRestException (org.xwiki.rest.XWikiRestException)4 SearchResult (org.xwiki.rest.model.jaxb.SearchResult)3 SpaceSearchResource (org.xwiki.rest.resources.spaces.SpaceSearchResource)2 WikiSearchResource (org.xwiki.rest.resources.wikis.WikiSearchResource)2 PostMethod (org.apache.commons.httpclient.methods.PostMethod)1 PutMethod (org.apache.commons.httpclient.methods.PutMethod)1 Ignore (org.junit.Ignore)1 DocumentReference (org.xwiki.model.reference.DocumentReference)1 Page (org.xwiki.rest.model.jaxb.Page)1 Wiki (org.xwiki.rest.model.jaxb.Wiki)1 PageResource (org.xwiki.rest.resources.pages.PageResource)1 WikisSearchQueryResource (org.xwiki.rest.resources.wikis.WikisSearchQueryResource)1 WikiManagerREST (org.xwiki.wiki.rest.WikiManagerREST)1