Search in sources :

Example 81 with SearchParameters

use of org.alfresco.service.cmr.search.SearchParameters in project alfresco-remote-api by Alfresco.

the class SearchMapperTests method fromLocales.

@Test
public void fromLocales() throws Exception {
    SearchParameters searchParameters = new SearchParameters();
    // Doesn't error
    searchMapper.fromLocalization(searchParameters, null);
    searchMapper.fromLocalization(searchParameters, new Localization(null, null));
    List<String> testLocales = new ArrayList<>();
    testLocales.add(null);
    try {
        searchMapper.fromLocalization(searchParameters, new Localization(null, testLocales));
        fail();
    } catch (IllegalArgumentException iae) {
        assertTrue(iae.getLocalizedMessage().contains("Invalid locale"));
    }
    // Unfortunately this isn't validated, language can be anything.
    searchMapper.fromLocalization(searchParameters, new Localization(null, Arrays.asList("NOTTHIS")));
    searchParameters = new SearchParameters();
    searchMapper.fromLocalization(searchParameters, new Localization(null, Arrays.asList("fr")));
    assertEquals(Locale.FRENCH, searchParameters.getLocales().get(0));
    searchParameters = new SearchParameters();
    searchMapper.fromLocalization(searchParameters, new Localization(null, Arrays.asList("fr_FR")));
    assertEquals(Locale.FRANCE, searchParameters.getLocales().get(0));
    searchParameters = new SearchParameters();
    searchMapper.fromLocalization(searchParameters, new Localization(null, Arrays.asList("fr-FR")));
    assertEquals(Locale.FRANCE, searchParameters.getLocales().get(0));
    searchParameters = new SearchParameters();
    searchMapper.fromLocalization(searchParameters, new Localization(null, Arrays.asList("fr-fr")));
    assertEquals(Locale.FRANCE, searchParameters.getSortLocale());
    searchParameters = new SearchParameters();
    searchMapper.fromLocalization(searchParameters, new Localization(null, Arrays.asList("fr-ca")));
    assertEquals(Locale.CANADA_FRENCH, searchParameters.getSortLocale());
    searchParameters = new SearchParameters();
    searchMapper.fromLocalization(searchParameters, new Localization(null, Arrays.asList("fr_ca")));
    assertEquals(Locale.CANADA_FRENCH, searchParameters.getSortLocale());
    searchParameters = new SearchParameters();
    searchMapper.fromLocalization(searchParameters, new Localization(null, Arrays.asList("en-gb")));
    assertEquals(Locale.UK, searchParameters.getSortLocale());
    searchParameters = new SearchParameters();
    searchMapper.fromLocalization(searchParameters, new Localization(null, Arrays.asList("en-us")));
    assertEquals(Locale.US, searchParameters.getSortLocale());
}
Also used : SearchParameters(org.alfresco.service.cmr.search.SearchParameters) ArrayList(java.util.ArrayList) Localization(org.alfresco.rest.api.search.model.Localization) Test(org.junit.Test)

Example 82 with SearchParameters

use of org.alfresco.service.cmr.search.SearchParameters in project alfresco-remote-api by Alfresco.

the class SearchMapperTests method facetRange.

@Test
public void facetRange() {
    SearchParameters searchParameters = new SearchParameters();
    List<RangeParameters> rangeParams = new ArrayList<RangeParameters>();
    rangeParams.add(new RangeParameters(null, null, null, null, false, null, null, null, null));
    try {
        searchMapper.fromRange(searchParameters, rangeParams);
        fail();
    } catch (IllegalArgumentException iae) {
        assertNotNull(iae);
    }
    rangeParams.clear();
    rangeParams.add(new RangeParameters("content.size", "0", "100000", "1000", true, null, null, null, null));
    searchMapper.fromRange(searchParameters, rangeParams);
    assertEquals(searchParameters.getRanges(), rangeParams);
    rangeParams.clear();
    List<String> includes = new ArrayList<String>();
    includes.add("lower");
    List<String> other = new ArrayList<String>();
    includes.add("before");
    rangeParams.add(new RangeParameters("content.size", "0", "100000", "1000", true, other, includes, null, null));
    searchMapper.fromRange(searchParameters, rangeParams);
    assertEquals(searchParameters.getRanges(), rangeParams);
    // Assert multiple ranges
    rangeParams.add(new RangeParameters("created", "2015-09-29T10:45:15.729Z", "2016-09-29T10:45:15.729Z", "+100DAY", true, other, includes, null, null));
    searchMapper.fromRange(searchParameters, rangeParams);
    assertEquals(searchParameters.getRanges(), rangeParams);
    assertEquals(2, searchParameters.getRanges().size());
}
Also used : SearchParameters(org.alfresco.service.cmr.search.SearchParameters) ArrayList(java.util.ArrayList) RangeParameters(org.alfresco.service.cmr.search.RangeParameters) Test(org.junit.Test)

Example 83 with SearchParameters

use of org.alfresco.service.cmr.search.SearchParameters in project alfresco-remote-api by Alfresco.

the class SearchMapperTests method fromPaging.

@Test
public void fromPaging() throws Exception {
    SearchParameters searchParameters = new SearchParameters();
    // Doesn't error
    searchMapper.fromPaging(searchParameters, null);
    Paging paging = Paging.DEFAULT;
    searchMapper.fromPaging(searchParameters, paging);
    assertEquals(searchParameters.getLimit(), paging.getMaxItems());
    assertEquals(searchParameters.getSkipCount(), paging.getSkipCount());
}
Also used : SearchParameters(org.alfresco.service.cmr.search.SearchParameters) Paging(org.alfresco.rest.framework.resource.parameters.Paging) Test(org.junit.Test)

Example 84 with SearchParameters

use of org.alfresco.service.cmr.search.SearchParameters 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 85 with SearchParameters

use of org.alfresco.service.cmr.search.SearchParameters in project alfresco-remote-api by Alfresco.

the class SearchMapperTests method fromSpelling.

@Test
public void fromSpelling() throws Exception {
    SearchParameters searchParameters = new SearchParameters();
    // Doesn't error
    searchMapper.fromSpellCheck(searchParameters, null);
    assertFalse(searchParameters.isSpellCheck());
    try {
        searchMapper.fromSpellCheck(searchParameters, new Spelling(null));
        fail();
    } catch (InvalidArgumentException iae) {
        // Can't be null
        assertNotNull(iae);
    }
    // Now set search term first
    searchParameters.setSearchTerm("fred");
    searchMapper.fromSpellCheck(searchParameters, new Spelling(null));
    assertEquals("fred", searchParameters.getSearchTerm());
    // Now query replaces userQuery (search term)
    searchMapper.fromSpellCheck(searchParameters, new Spelling("favourit"));
    assertEquals("favourit", searchParameters.getSearchTerm());
    assertTrue(searchParameters.isSpellCheck());
}
Also used : SearchParameters(org.alfresco.service.cmr.search.SearchParameters) Spelling(org.alfresco.rest.api.search.model.Spelling) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) Test(org.junit.Test)

Aggregations

SearchParameters (org.alfresco.service.cmr.search.SearchParameters)120 ResultSet (org.alfresco.service.cmr.search.ResultSet)51 Test (org.junit.Test)41 NodeRef (org.alfresco.service.cmr.repository.NodeRef)33 ArrayList (java.util.ArrayList)25 StoreRef (org.alfresco.service.cmr.repository.StoreRef)16 IOException (java.io.IOException)15 HashMap (java.util.HashMap)14 QName (org.alfresco.service.namespace.QName)13 List (java.util.List)12 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)12 JSONObject (org.json.JSONObject)12 SearchRequestContext (org.alfresco.rest.api.search.context.SearchRequestContext)11 FieldHighlightParameters (org.alfresco.service.cmr.search.FieldHighlightParameters)11 Set (java.util.Set)10 InvalidArgumentException (org.alfresco.rest.framework.core.exceptions.InvalidArgumentException)10 RangeParameters (org.alfresco.service.cmr.search.RangeParameters)10 JSONArray (org.json.JSONArray)10 JSONTokener (org.json.JSONTokener)10 Locale (java.util.Locale)9