Search in sources :

Example 76 with SearchParameters

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

the class SearchMapperTests method fromDefaults.

@Test
public void fromDefaults() throws Exception {
    SearchParameters searchParameters = new SearchParameters();
    // Doesn't error
    searchMapper.fromDefault(searchParameters, null);
    searchMapper.fromDefault(searchParameters, new Default(null, null, null, null, null));
    searchMapper.fromDefault(searchParameters, new Default(null, "AND", null, null, null));
    assertEquals("AND", searchParameters.getDefaultFTSOperator().toString());
    searchMapper.fromDefault(searchParameters, new Default(null, null, "or", null, null));
    assertEquals("OR", searchParameters.getDefaultFTSFieldOperator().toString());
    try {
        searchMapper.fromDefault(searchParameters, new Default(null, null, "ELSE", null, null));
        fail();
    } catch (IllegalArgumentException iae) {
        // ELSE is illegal
        assertNotNull(iae);
    }
    searchMapper.fromDefault(searchParameters, new Default(null, null, null, "nspa", "dfn"));
    assertEquals("nspa", searchParameters.getNamespace());
    assertEquals("dfn", searchParameters.getDefaultFieldName());
    assertEquals(0, searchParameters.getTextAttributes().size());
    searchMapper.fromDefault(searchParameters, new Default(Arrays.asList("sausage", "mash"), null, null, null, null));
    assertEquals(2, searchParameters.getTextAttributes().size());
    assertTrue(searchParameters.getTextAttributes().contains("sausage"));
    assertTrue(searchParameters.getTextAttributes().contains("mash"));
}
Also used : SearchParameters(org.alfresco.service.cmr.search.SearchParameters) Default(org.alfresco.rest.api.search.model.Default) Test(org.junit.Test)

Example 77 with SearchParameters

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

the class SearchMapperTests method fromTemplate.

@Test
public void fromTemplate() throws Exception {
    SearchParameters searchParameters = new SearchParameters();
    // Doesn't error
    searchMapper.fromTemplate(searchParameters, null);
    searchMapper.fromTemplate(searchParameters, Arrays.asList(new Template("hedge", "hog"), new Template("king", "kong"), new Template("bish", "bash")));
    assertEquals(3, searchParameters.getQueryTemplates().size());
    assertEquals("hog", searchParameters.getQueryTemplates().get("hedge"));
    assertEquals("kong", searchParameters.getQueryTemplates().get("king"));
    assertEquals("bash", searchParameters.getQueryTemplates().get("bish"));
}
Also used : SearchParameters(org.alfresco.service.cmr.search.SearchParameters) Template(org.alfresco.rest.api.search.model.Template) Test(org.junit.Test)

Example 78 with SearchParameters

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

Example 79 with SearchParameters

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

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

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