Search in sources :

Example 1 with IntervalParameters

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

the class SearchMapperTests method fromInterval.

@Test
public void fromInterval() throws Exception {
    SearchParameters searchParameters = new SearchParameters();
    IntervalParameters intervalParameters = new IntervalParameters(null, null);
    try {
        searchMapper.fromFacetIntervals(searchParameters, intervalParameters);
        fail();
    } catch (IllegalArgumentException iae) {
        // intervals is required
        assertNotNull(iae);
    }
    Set<IntervalSet> intervalSets = new HashSet(Arrays.asList(new IntervalSet(null, "1", null, null, null)));
    List<Interval> intervalList = Arrays.asList(new Interval(null, "bob", null));
    intervalParameters = new IntervalParameters(intervalSets, intervalList);
    try {
        searchMapper.fromFacetIntervals(searchParameters, intervalParameters);
        fail();
    } catch (IllegalArgumentException iae) {
        // facetIntervals intervals field is required
        assertNotNull(iae);
    }
    intervalList = Arrays.asList(new Interval("aFileld", "bob", null));
    intervalParameters = new IntervalParameters(intervalSets, intervalList);
    try {
        searchMapper.fromFacetIntervals(searchParameters, intervalParameters);
        fail();
    } catch (IllegalArgumentException iae) {
        // set start is required
        assertNotNull(iae);
    }
    intervalSets = new HashSet(Arrays.asList(new IntervalSet("1", null, null, null, true)));
    intervalParameters = new IntervalParameters(intervalSets, intervalList);
    try {
        searchMapper.fromFacetIntervals(searchParameters, intervalParameters);
        fail();
    } catch (IllegalArgumentException iae) {
        // set end is required
        assertNotNull(iae);
    }
    intervalSets = new HashSet<>();
    intervalSets.add(new IntervalSet("0", "3", "bob", null, null));
    intervalSets.add(new IntervalSet("30", "50", "bill", true, true));
    Set<IntervalSet> anIntervalSet = new HashSet<>();
    anIntervalSet.add(new IntervalSet("1", "10", "bert", false, false));
    intervalList = Arrays.asList(new Interval("cm:price", "Price", null), new Interval("cm:price", "Price", anIntervalSet));
    intervalParameters = new IntervalParameters(intervalSets, intervalList);
    try {
        searchMapper.fromFacetIntervals(searchParameters, intervalParameters);
        fail();
    } catch (InvalidArgumentException iae) {
        // duplicate labels
        assertNotNull(iae);
    }
    intervalList = Arrays.asList(new Interval("cm:price", "Prices", null), new Interval("cm:price", "Pricey", anIntervalSet));
    intervalParameters = new IntervalParameters(intervalSets, intervalList);
    searchMapper.fromFacetIntervals(searchParameters, intervalParameters);
    assertEquals(searchParameters.getInterval(), intervalParameters);
}
Also used : SearchParameters(org.alfresco.service.cmr.search.SearchParameters) IntervalParameters(org.alfresco.service.cmr.search.IntervalParameters) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) IntervalSet(org.alfresco.service.cmr.search.IntervalSet) HashSet(java.util.HashSet) Interval(org.alfresco.service.cmr.search.Interval) Test(org.junit.Test)

Example 2 with IntervalParameters

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

the class SearchQuerySerializerTests method testDeserializeQuery.

@Test
public void testDeserializeQuery() throws IOException {
    SearchQuery searchQuery = helper.searchQueryFromJson();
    assertEquals(SearchQuery.class, searchQuery.getClass());
    assertEquals("afts", searchQuery.getQuery().getLanguage());
    assertEquals("g*", searchQuery.getQuery().getQuery());
    assertEquals("great", searchQuery.getQuery().getUserQuery());
    assertEquals(99, searchQuery.getPaging().getMaxItems());
    assertEquals(4, searchQuery.getPaging().getSkipCount());
    assertEquals(2, searchQuery.getInclude().size());
    assertTrue(searchQuery.getInclude().contains("aspectNames"));
    assertTrue(searchQuery.getInclude().contains("properties"));
    assertEquals(1, searchQuery.getSort().size());
    assertEquals(2, searchQuery.getTemplates().size());
    Default defaults = searchQuery.getDefaults();
    assertEquals("namesp", defaults.getNamespace());
    assertEquals("myfield", defaults.getDefaultFieldName());
    assertEquals("AND", defaults.getDefaultFTSOperator());
    assertEquals(2, defaults.getTextAttributes().size());
    assertTrue(defaults.getTextAttributes().contains("roy"));
    assertTrue(defaults.getTextAttributes().contains("king"));
    assertEquals(2, searchQuery.getFilterQueries().size());
    assertEquals("myquery", searchQuery.getFilterQueries().get(0).getQuery());
    assertEquals(2, searchQuery.getFilterQueries().get(0).getTags().size());
    assertEquals("myquery2", searchQuery.getFilterQueries().get(1).getQuery());
    assertEquals(1, searchQuery.getFacetQueries().size());
    assertEquals("cm:created:bob", searchQuery.getFacetQueries().get(0).getQuery());
    assertEquals("small", searchQuery.getFacetQueries().get(0).getLabel());
    assertEquals("alfrezco", searchQuery.getSpellcheck().getQuery());
    assertEquals(1, searchQuery.getScope().getLocations().size());
    assertEquals(StoreMapper.LIVE_NODES, searchQuery.getScope().getLocations().get(0));
    assertEquals(3, searchQuery.getFacetFields().getFacets().size());
    FacetField ff = searchQuery.getFacetFields().getFacets().get(0);
    assertEquals("cm:creator", ff.getField());
    assertEquals("myquery2", ff.getPrefix());
    assertEquals("COUNT", ff.getSort());
    assertEquals(false, ff.getMissing());
    ff = searchQuery.getFacetFields().getFacets().get(1);
    assertEquals("modifier", ff.getField());
    assertEquals("mylabel", ff.getLabel());
    assertEquals("FC", ff.getMethod());
    assertEquals(Integer.valueOf(5), ff.getMincount());
    assertEquals(2000, searchQuery.getLimits().getPermissionEvaluationCount().intValue());
    assertEquals(5000, searchQuery.getLimits().getPermissionEvaluationTime().intValue());
    assertEquals(2, searchQuery.getFields().size());
    assertTrue(searchQuery.getFields().contains("id"));
    assertTrue(searchQuery.getFields().contains("name"));
    // Highlight
    assertEquals("]", searchQuery.getHighlight().getPostfix());
    assertEquals("[", searchQuery.getHighlight().getPrefix());
    assertEquals(20, searchQuery.getHighlight().getSnippetCount().intValue());
    assertEquals(10, searchQuery.getHighlight().getFragmentSize().intValue());
    assertEquals(true, searchQuery.getHighlight().getMergeContiguous());
    assertEquals(40, searchQuery.getHighlight().getMaxAnalyzedChars().intValue());
    assertEquals(true, searchQuery.getHighlight().getUsePhraseHighlighter());
    assertEquals(2, searchQuery.getHighlight().getFields().size());
    FieldHighlightParameters high1 = searchQuery.getHighlight().getFields().get(0);
    assertEquals("my", high1.getField());
    assertEquals("ยก", high1.getPostfix());
    assertEquals("?", high1.getPrefix());
    assertEquals(23, high1.getSnippetCount().intValue());
    assertEquals(5, high1.getFragmentSize().intValue());
    assertEquals(true, high1.getMergeContiguous());
    FieldHighlightParameters high2 = searchQuery.getHighlight().getFields().get(1);
    assertEquals("your", high2.getField());
    assertEquals(")", high2.getPostfix());
    assertEquals("(", high2.getPrefix());
    assertEquals(3, high2.getSnippetCount().intValue());
    assertEquals(15, high2.getFragmentSize().intValue());
    assertEquals(false, high2.getMergeContiguous());
    // Facet intervals
    IntervalParameters ip = searchQuery.getFacetIntervals();
    assertNotNull(ip);
    assertEquals(1, ip.getSets().size());
    IntervalSet expected = new IntervalSet("1", "2", "king", true, false);
    assertTrue(ip.getSets().contains(expected));
    assertEquals(2, ip.getIntervals().size());
    Interval interval = ip.getIntervals().get(0);
    assertEquals("creator", interval.getLabel());
    assertEquals("cm:creator", interval.getField());
    expected = new IntervalSet("a", "b", "last", false, true);
    assertTrue(interval.getSets().contains(expected));
    assertEquals(1, searchQuery.getPivots().size());
    assertEquals("mylabel", searchQuery.getPivots().get(0).getKey());
    assertEquals(1, searchQuery.getStats().size());
    assertEquals("cm:creator", searchQuery.getStats().get(0).getField());
    assertEquals("mylabel", searchQuery.getStats().get(0).getLabel());
    // Range Facet
    List<RangeParameters> ranges = searchQuery.getFacetRanges();
    assertNotNull(ranges);
}
Also used : SearchQuery(org.alfresco.rest.api.search.model.SearchQuery) IntervalParameters(org.alfresco.service.cmr.search.IntervalParameters) IntervalSet(org.alfresco.service.cmr.search.IntervalSet) FacetField(org.alfresco.rest.api.search.model.FacetField) FieldHighlightParameters(org.alfresco.service.cmr.search.FieldHighlightParameters) RangeParameters(org.alfresco.service.cmr.search.RangeParameters) Default(org.alfresco.rest.api.search.model.Default) Interval(org.alfresco.service.cmr.search.Interval) Test(org.junit.Test)

Example 3 with IntervalParameters

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

the class SearchMapper method fromFacetIntervals.

/**
 * Sets the Interval Parameters object on search parameters
 *
 * It does some valiation then takes any "SETS" at the top level and sets them at every field level.
 *
 * @param sp SearchParameters
 * @param facetIntervals IntervalParameters
 */
public void fromFacetIntervals(SearchParameters sp, IntervalParameters facetIntervals) {
    if (facetIntervals != null) {
        ParameterCheck.mandatory("facetIntervals intervals", facetIntervals.getIntervals());
        Set<IntervalSet> globalSets = facetIntervals.getSets();
        validateSets(globalSets, "facetIntervals");
        if (facetIntervals.getIntervals() != null && !facetIntervals.getIntervals().isEmpty()) {
            List<String> intervalLabels = new ArrayList<>(facetIntervals.getIntervals().size());
            for (Interval interval : facetIntervals.getIntervals()) {
                ParameterCheck.mandatory("facetIntervals intervals field", interval.getField());
                validateSets(interval.getSets(), "facetIntervals intervals " + interval.getField());
                if (interval.getSets() != null && globalSets != null) {
                    interval.getSets().addAll(globalSets);
                }
                ParameterCheck.mandatoryCollection("facetIntervals intervals sets", interval.getSets());
                List<Map.Entry<String, Long>> duplicateSetLabels = interval.getSets().stream().collect(groupingBy(IntervalSet::getLabel, Collectors.counting())).entrySet().stream().filter(e -> e.getValue().intValue() > 1).collect(toList());
                if (!duplicateSetLabels.isEmpty()) {
                    throw new InvalidArgumentException(InvalidArgumentException.DEFAULT_MESSAGE_ID, new Object[] { ": duplicate set interval label " + duplicateSetLabels.toString() });
                }
                if (interval.getLabel() != null)
                    intervalLabels.add(interval.getLabel());
            }
            List<Map.Entry<String, Long>> duplicateIntervalLabels = intervalLabels.stream().collect(groupingBy(Function.identity(), Collectors.counting())).entrySet().stream().filter(e -> e.getValue().intValue() > 1).collect(toList());
            if (!duplicateIntervalLabels.isEmpty()) {
                throw new InvalidArgumentException(InvalidArgumentException.DEFAULT_MESSAGE_ID, new Object[] { ": duplicate interval label " + duplicateIntervalLabels.toString() });
            }
        }
        if (facetIntervals.getSets() != null) {
            facetIntervals.getSets().clear();
        }
    }
    sp.setInterval(facetIntervals);
}
Also used : Arrays(java.util.Arrays) FacetQuery(org.alfresco.rest.api.search.model.FacetQuery) Pivot(org.alfresco.rest.api.search.model.Pivot) Paging(org.alfresco.rest.framework.resource.parameters.Paging) PARAM_INCLUDE_PROPERTIES(org.alfresco.rest.api.Nodes.PARAM_INCLUDE_PROPERTIES) RangeParameters(org.alfresco.service.cmr.search.RangeParameters) Template(org.alfresco.rest.api.search.model.Template) IntervalParameters(org.alfresco.service.cmr.search.IntervalParameters) Limits(org.alfresco.rest.api.search.model.Limits) Matcher(java.util.regex.Matcher) Params(org.alfresco.rest.framework.resource.parameters.Params) Locale(java.util.Locale) Map(java.util.Map) LANGUAGE_FTS_ALFRESCO(org.alfresco.service.cmr.search.SearchService.LANGUAGE_FTS_ALFRESCO) Scope(org.alfresco.rest.api.search.model.Scope) PARAM_INCLUDE_PATH(org.alfresco.rest.api.Nodes.PARAM_INCLUDE_PATH) Localization(org.alfresco.rest.api.search.model.Localization) TimeZone(java.util.TimeZone) Set(java.util.Set) FacetFields(org.alfresco.rest.api.search.model.FacetFields) Collectors(java.util.stream.Collectors) ZoneId(java.time.ZoneId) IntervalSet(org.alfresco.service.cmr.search.IntervalSet) List(java.util.List) LuceneQueryLanguageSPI(org.alfresco.repo.search.impl.lucene.LuceneQueryLanguageSPI) PARAM_INCLUDE_ALLOWABLEOPERATIONS(org.alfresco.rest.api.Nodes.PARAM_INCLUDE_ALLOWABLEOPERATIONS) Optional(java.util.Optional) Default(org.alfresco.rest.api.search.model.Default) FilterQuery(org.alfresco.rest.api.search.model.FilterQuery) SortDef(org.alfresco.rest.api.search.model.SortDef) LimitBy(org.alfresco.service.cmr.search.LimitBy) PARAM_INCLUDE_ISLINK(org.alfresco.rest.api.Nodes.PARAM_INCLUDE_ISLINK) Interval(org.alfresco.service.cmr.search.Interval) FieldFacet(org.alfresco.service.cmr.search.SearchParameters.FieldFacet) SearchRequestContext(org.alfresco.rest.api.search.context.SearchRequestContext) Collectors.groupingBy(java.util.stream.Collectors.groupingBy) GeneralHighlightParameters(org.alfresco.service.cmr.search.GeneralHighlightParameters) Function(java.util.function.Function) ArrayList(java.util.ArrayList) FieldFacetSort(org.alfresco.service.cmr.search.SearchParameters.FieldFacetSort) PARAM_INCLUDE_ASPECTNAMES(org.alfresco.rest.api.Nodes.PARAM_INCLUDE_ASPECTNAMES) ParameterCheck(org.alfresco.util.ParameterCheck) StatsRequestParameters(org.alfresco.service.cmr.search.StatsRequestParameters) FacetField(org.alfresco.rest.api.search.model.FacetField) LANGUAGE_LUCENE(org.alfresco.service.cmr.search.SearchService.LANGUAGE_LUCENE) SortType(org.alfresco.service.cmr.search.SearchParameters.SortDefinition.SortType) StoreRef(org.alfresco.service.cmr.repository.StoreRef) PARAM_INCLUDE_ASSOCIATION(org.alfresco.rest.api.Nodes.PARAM_INCLUDE_ASSOCIATION) FieldFacetMethod(org.alfresco.service.cmr.search.SearchParameters.FieldFacetMethod) LANGUAGE_CMIS_ALFRESCO(org.alfresco.service.cmr.search.SearchService.LANGUAGE_CMIS_ALFRESCO) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) Operator(org.alfresco.service.cmr.search.SearchParameters.Operator) Query(org.alfresco.rest.api.search.model.Query) Collectors.toList(java.util.stream.Collectors.toList) SearchQuery(org.alfresco.rest.api.search.model.SearchQuery) SortDefinition(org.alfresco.service.cmr.search.SearchParameters.SortDefinition) Spelling(org.alfresco.rest.api.search.model.Spelling) SearchParameters(org.alfresco.service.cmr.search.SearchParameters) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) IntervalSet(org.alfresco.service.cmr.search.IntervalSet) ArrayList(java.util.ArrayList) Interval(org.alfresco.service.cmr.search.Interval)

Aggregations

Interval (org.alfresco.service.cmr.search.Interval)3 IntervalParameters (org.alfresco.service.cmr.search.IntervalParameters)3 IntervalSet (org.alfresco.service.cmr.search.IntervalSet)3 Default (org.alfresco.rest.api.search.model.Default)2 FacetField (org.alfresco.rest.api.search.model.FacetField)2 SearchQuery (org.alfresco.rest.api.search.model.SearchQuery)2 InvalidArgumentException (org.alfresco.rest.framework.core.exceptions.InvalidArgumentException)2 RangeParameters (org.alfresco.service.cmr.search.RangeParameters)2 SearchParameters (org.alfresco.service.cmr.search.SearchParameters)2 Test (org.junit.Test)2 ZoneId (java.time.ZoneId)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Locale (java.util.Locale)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Set (java.util.Set)1 TimeZone (java.util.TimeZone)1