Search in sources :

Example 16 with SearchRequestContext

use of org.alfresco.rest.api.search.context.SearchRequestContext in project alfresco-remote-api by Alfresco.

the class SearchMapperTests method toSearchParameters.

@Test
public void toSearchParameters() throws Exception {
    SearchRequestContext searchRequest = SearchRequestContext.from(minimalQuery());
    SearchParameters searchParameters = searchMapper.toSearchParameters(ResultMapperTests.EMPTY_PARAMS, minimalQuery(), searchRequest);
    assertNotNull(searchParameters);
    // Test defaults
    assertEquals("There should be only 1 default store", 1, searchParameters.getStores().size());
    assertEquals("workspaces store is the default", StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, searchParameters.getStores().get(0));
    assertEquals(LimitBy.FINAL_SIZE, searchParameters.getLimitBy());
    assertEquals(100, searchParameters.getLimit());
    searchParameters = searchMapper.toSearchParameters(ResultMapperTests.EMPTY_PARAMS, helper.searchQueryFromJson(), searchRequest);
    assertNotNull(searchParameters);
}
Also used : SearchParameters(org.alfresco.service.cmr.search.SearchParameters) SearchRequestContext(org.alfresco.rest.api.search.context.SearchRequestContext) Test(org.junit.Test)

Example 17 with SearchRequestContext

use of org.alfresco.rest.api.search.context.SearchRequestContext in project alfresco-remote-api by Alfresco.

the class SearchMapperTests method facetFormatV2.

@Test
public void facetFormatV2() {
    Query query = new Query("afts", "a*", "");
    SearchQuery sq = new SearchQuery(query, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, FacetFormat.V2);
    SearchRequestContext searchRequestContext = SearchRequestContext.from(sq);
    SearchParameters searchParameters = searchMapper.toSearchParameters(ResultMapperTests.EMPTY_PARAMS, sq, searchRequestContext);
    assertNotNull(searchParameters);
    // Test defaults
    assertEquals("There should be only 1 default store", 1, searchParameters.getStores().size());
    assertEquals("workspaces store is the default", StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, searchParameters.getStores().get(0));
    assertEquals(LimitBy.FINAL_SIZE, searchParameters.getLimitBy());
    assertEquals(100, searchParameters.getLimit());
}
Also used : SearchQuery(org.alfresco.rest.api.search.model.SearchQuery) SearchParameters(org.alfresco.service.cmr.search.SearchParameters) FacetQuery(org.alfresco.rest.api.search.model.FacetQuery) FilterQuery(org.alfresco.rest.api.search.model.FilterQuery) Query(org.alfresco.rest.api.search.model.Query) SearchQuery(org.alfresco.rest.api.search.model.SearchQuery) SearchRequestContext(org.alfresco.rest.api.search.context.SearchRequestContext) Test(org.junit.Test)

Example 18 with SearchRequestContext

use of org.alfresco.rest.api.search.context.SearchRequestContext in project alfresco-remote-api by Alfresco.

the class SearchMapperTests method fromPivot.

@Test
public void fromPivot() throws Exception {
    SearchParameters searchParameters = new SearchParameters();
    searchMapper.fromPivot(searchParameters, null, null, null, null, null);
    List<FacetField> facets = new ArrayList<>(1);
    facets.add(new FacetField("myfield", null, null, null, null, null, null, null, null, null, null));
    facets.add(new FacetField("yourfield", null, null, null, null, null, null, null, null, null, null));
    FacetFields ff = new FacetFields(facets);
    searchMapper.fromFacetFields(searchParameters, ff);
    searchMapper.fromPivot(searchParameters, null, ff, null, null, null);
    assertEquals(2, searchParameters.getFieldFacets().size());
    assertEquals(0, searchParameters.getPivots().size());
    // Handle unknown pivot.
    searchParameters = new SearchParameters();
    try {
        searchMapper.fromPivot(searchParameters, null, ff, null, Arrays.asList(new Pivot(null, null)), null);
        fail();
    } catch (IllegalArgumentException iae) {
        // "bob" doesn't refer to a field facet
        assertNotNull(iae);
    }
    try {
        searchMapper.fromPivot(searchParameters, null, ff, null, Arrays.asList(new Pivot("", null)), null);
        fail();
    } catch (IllegalArgumentException iae) {
        assertNotNull(iae);
    }
    SearchRequestContext searchRequestContext = SearchRequestContext.from(minimalQuery());
    // "bob" doesn't refer to a field facet but its the last one so needs to refer to a stat
    StatsRequestParameters bobf = new StatsRequestParameters("bob", null, null, null, null, null, null, null, null, null, null, null, null, null, null, null);
    StatsRequestParameters bobL = new StatsRequestParameters("creator", "bob", null, null, null, null, null, null, null, null, null, null, null, null, null, null);
    try {
        searchMapper.fromPivot(searchParameters, Arrays.asList(bobf), ff, null, Arrays.asList(new Pivot("bob", null)), searchRequestContext);
        fail();
    } catch (InvalidArgumentException iae) {
        // "bob" refers to a stat but it can't be at the root pivot, it needs to be nested
        assertNotNull(iae);
    }
    searchMapper.fromPivot(searchParameters, Arrays.asList(bobf), ff, null, Arrays.asList(new Pivot("yourfield", Arrays.asList(new Pivot("bob", null)))), searchRequestContext);
    assertEquals(1, searchParameters.getPivots().size());
    try {
        searchMapper.fromPivot(searchParameters, null, ff, null, Arrays.asList(new Pivot("ken", null), new Pivot("bob", null)), searchRequestContext);
        fail();
    } catch (InvalidArgumentException iae) {
        // "ken" doesn't refer to a field facet and its not the last one
        assertNotNull(iae);
    }
    searchParameters = new SearchParameters();
    searchMapper.fromPivot(searchParameters, null, ff, null, Arrays.asList(new Pivot("myfield", null)), searchRequestContext);
    searchMapper.fromFacetFields(searchParameters, ff);
    // Moved from a field facet to a pivot
    assertEquals(0, searchParameters.getFieldFacets().size());
    assertEquals(1, searchParameters.getPivots().size());
    assertEquals("myfield", searchParameters.getPivots().get(0).get(0));
    searchParameters = new SearchParameters();
    try {
        searchMapper.fromPivot(searchParameters, Arrays.asList(bobf), ff, null, Arrays.asList(new Pivot("bob", Arrays.asList(new Pivot("hope", null)))), searchRequestContext);
        fail();
    } catch (InvalidArgumentException iae) {
        // "bob" doesn't refer to a field facet or stat
        assertNotNull(iae);
    }
    searchRequestContext = SearchRequestContext.from(minimalQuery());
    facets = new ArrayList<>(1);
    facets.add(new FacetField("king", null, null, null, null, null, null, null, null, null, null));
    ff = new FacetFields(facets);
    searchMapper.fromPivot(searchParameters, Arrays.asList(bobf), ff, null, Arrays.asList(new Pivot("king", Arrays.asList(new Pivot("bob", null)))), searchRequestContext);
    assertEquals(1, searchParameters.getPivots().size());
    assertEquals(2, searchParameters.getPivots().get(0).size());
    assertEquals("king", searchParameters.getPivots().get(0).get(0));
    assertEquals("bob", searchParameters.getPivots().get(0).get(1));
    searchRequestContext = SearchRequestContext.from(minimalQuery());
    searchParameters = new SearchParameters();
    facets = new ArrayList<>(1);
    facets.add(new FacetField("king", null, null, null, null, null, null, null, null, null, null));
    facets.add(new FacetField("kong", null, null, null, null, null, null, null, null, null, null));
    facets.add(new FacetField("kang", null, null, null, null, null, null, null, null, null, null));
    ff = new FacetFields(facets);
    searchMapper.fromPivot(searchParameters, Arrays.asList(bobf), ff, null, Arrays.asList(new Pivot("king", Arrays.asList(new Pivot("bob", null))), new Pivot("kong", null)), searchRequestContext);
    assertEquals(2, searchParameters.getPivots().size());
    assertEquals(2, searchParameters.getPivots().get(0).size());
    assertEquals("king", searchParameters.getPivots().get(0).get(0));
    assertEquals("bob", searchParameters.getPivots().get(0).get(1));
    assertEquals("kong", searchParameters.getPivots().get(1).get(0));
    searchRequestContext = SearchRequestContext.from(minimalQuery());
    searchParameters = new SearchParameters();
    List<RangeParameters> rangeParams = new ArrayList<RangeParameters>();
    facets = new ArrayList<>(2);
    facets.add(new FacetField("king", null, null, null, null, null, null, null, null, null, null));
    facets.add(new FacetField("kong", null, null, null, null, null, null, null, null, null, null));
    ff = new FacetFields(facets);
    rangeParams.add(new RangeParameters("content.size", "0", "100000", "1000", true, null, null, "hope", null));
    searchMapper.fromPivot(searchParameters, Arrays.asList(bobf), ff, rangeParams, Arrays.asList(new Pivot("king", Arrays.asList(new Pivot("bob", null))), new Pivot("kong", Arrays.asList(new Pivot("hope", null)))), searchRequestContext);
    assertEquals(2, searchParameters.getPivots().size());
    assertEquals(2, searchParameters.getPivots().get(0).size());
    assertEquals("king", searchParameters.getPivots().get(0).get(0));
    assertEquals("bob", searchParameters.getPivots().get(0).get(1));
    assertEquals("kong", searchParameters.getPivots().get(1).get(0));
    assertEquals("hope", searchParameters.getPivots().get(1).get(1));
}
Also used : ArrayList(java.util.ArrayList) FacetField(org.alfresco.rest.api.search.model.FacetField) StatsRequestParameters(org.alfresco.service.cmr.search.StatsRequestParameters) SearchRequestContext(org.alfresco.rest.api.search.context.SearchRequestContext) SearchParameters(org.alfresco.service.cmr.search.SearchParameters) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) FacetFields(org.alfresco.rest.api.search.model.FacetFields) Pivot(org.alfresco.rest.api.search.model.Pivot) RangeParameters(org.alfresco.service.cmr.search.RangeParameters) Test(org.junit.Test)

Example 19 with SearchRequestContext

use of org.alfresco.rest.api.search.context.SearchRequestContext in project alfresco-remote-api by Alfresco.

the class SearchMapperTests method fromScope.

@Test
public void fromScope() throws Exception {
    SearchParameters searchParameters = new SearchParameters();
    searchMapper.setDefaults(searchParameters);
    SearchRequestContext searchRequestContext = SearchRequestContext.from(minimalQuery());
    // Doesn't error, has default store
    searchMapper.fromScope(searchParameters, null, searchRequestContext);
    assertEquals(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, searchParameters.getStores().get(0));
    searchMapper.fromScope(searchParameters, new Scope(null), searchRequestContext);
    assertEquals(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, searchParameters.getStores().get(0));
    try {
        searchMapper.fromScope(searchParameters, new Scope(Arrays.asList("nonsense")), searchRequestContext);
        fail();
    } catch (InvalidArgumentException iae) {
        // Must be a valid store ref
        assertNotNull(iae);
    }
    searchMapper.fromScope(searchParameters, new Scope(Arrays.asList(StoreMapper.DELETED, StoreMapper.LIVE_NODES, StoreMapper.VERSIONS)), searchRequestContext);
    assertEquals(3, searchParameters.getStores().size());
    assertEquals(StoreRef.STORE_REF_ARCHIVE_SPACESSTORE.toString(), searchParameters.getStores().get(0).toString());
    assertEquals(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE.toString(), searchParameters.getStores().get(1).toString());
    assertEquals(StoreMapper.STORE_REF_VERSION2_SPACESSTORE.toString(), searchParameters.getStores().get(2).toString());
    searchMapper.fromScope(searchParameters, new Scope(Arrays.asList(StoreMapper.HISTORY)), searchRequestContext);
    assertEquals(1, searchParameters.getStores().size());
    assertEquals(StoreMapper.STORE_REF_HISTORY.toString(), searchParameters.getStores().get(0).toString());
    try {
        searchMapper.fromScope(searchParameters, new Scope(Arrays.asList(StoreMapper.HISTORY, StoreMapper.DELETED)), searchRequestContext);
        fail();
    } catch (InvalidArgumentException iae) {
        // Must be a valid scope with history
        assertNotNull(iae);
    }
    try {
        searchMapper.fromScope(searchParameters, new Scope(Arrays.asList(StoreMapper.HISTORY, StoreMapper.LIVE_NODES)), searchRequestContext);
        fail();
    } catch (InvalidArgumentException iae) {
        // Must be a valid scope with history
        assertNotNull(iae);
    }
    try {
        searchMapper.fromScope(searchParameters, new Scope(Arrays.asList(StoreMapper.HISTORY, StoreMapper.VERSIONS)), searchRequestContext);
        fail();
    } catch (InvalidArgumentException iae) {
        // Must be a valid scope with history
        assertNotNull(iae);
    }
}
Also used : SearchParameters(org.alfresco.service.cmr.search.SearchParameters) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) Scope(org.alfresco.rest.api.search.model.Scope) SearchRequestContext(org.alfresco.rest.api.search.context.SearchRequestContext) Test(org.junit.Test)

Aggregations

SearchRequestContext (org.alfresco.rest.api.search.context.SearchRequestContext)19 Test (org.junit.Test)16 SearchQuery (org.alfresco.rest.api.search.model.SearchQuery)13 ResultSet (org.alfresco.service.cmr.search.ResultSet)12 EmptyResultSet (org.alfresco.repo.search.EmptyResultSet)11 SolrJSONResultSet (org.alfresco.repo.search.impl.lucene.SolrJSONResultSet)11 SearchParameters (org.alfresco.service.cmr.search.SearchParameters)11 SearchContext (org.alfresco.rest.api.search.context.SearchContext)10 Metric (org.alfresco.repo.search.impl.solr.facet.facetsresponse.Metric)9 SimpleMetric (org.alfresco.repo.search.impl.solr.facet.facetsresponse.SimpleMetric)9 Matchers.anyString (org.mockito.Matchers.anyString)9 ListMetric (org.alfresco.repo.search.impl.solr.facet.facetsresponse.ListMetric)8 PercentileMetric (org.alfresco.repo.search.impl.solr.facet.facetsresponse.PercentileMetric)8 Node (org.alfresco.rest.api.model.Node)8 ArrayList (java.util.ArrayList)7 Arrays (java.util.Arrays)6 List (java.util.List)6 Map (java.util.Map)6 Set (java.util.Set)6 Collectors (java.util.stream.Collectors)6