Package org.springframework.data.solr.core.query

Examples of org.springframework.data.solr.core.query.StatsOptions$StatsOptionsState


  private StatsOptions extractStatsOptions(SolrQueryMethod queryMethod, SolrParameterAccessor accessor) {
    if (!queryMethod.hasStatsDefinition()) {
      return null;
    }

    StatsOptions options = new StatsOptions();

    for (String fieldName : queryMethod.getFieldStats()) {
      options.addField(fieldName);
    }

    for (String facetFieldName : queryMethod.getStatsFacets()) {
      options.addFacet(facetFieldName);
    }

    options.setCalcDistinct(queryMethod.isFieldStatsCountDistinctEnable());

    Collection<String> selectiveCountDistinct = queryMethod.getStatsSelectiveCountDistinctFields();

    for (Entry<String, String[]> selectiveFacet : queryMethod.getStatsSelectiveFacets().entrySet()) {
      FieldStatsOptions fieldStatsOptions = options.addField(selectiveFacet.getKey());
      for (String facetFieldName : selectiveFacet.getValue()) {
        fieldStatsOptions.addSelectiveFacet(facetFieldName);
      }

      fieldStatsOptions.setSelectiveCalcDistinct(selectiveCountDistinct.contains(selectiveFacet.getKey()));
View Full Code Here


      ((NamedObjectsQuery) query).setName(object, name);
    }
  }

  private void processStatsOptions(SolrQuery solrQuery, Query query) {
    StatsOptions statsOptions = query.getStatsOptions();

    if (statsOptions == null
        || (CollectionUtils.isEmpty(statsOptions.getFields()) && CollectionUtils.isEmpty(statsOptions.getFacets()) && CollectionUtils
            .isEmpty(statsOptions.getSelectiveFacets()))) {
      return;
    }

    solrQuery.set(StatsParams.STATS, true);

    for (Field field : statsOptions.getFields()) {
      solrQuery.add(StatsParams.STATS_FIELD, field.getName());

      String selectiveCalcDistinctParam = CommonParams.FIELD + "." + field.getName() + "."
          + StatsParams.STATS_CALC_DISTINCT;
      Boolean selectiveCountDistincts = statsOptions.isSelectiveCalcDistincts(field);

      if (selectiveCountDistincts != null) {
        solrQuery.add(selectiveCalcDistinctParam, String.valueOf(selectiveCountDistincts.booleanValue()));
      }

    }

    for (Field field : statsOptions.getFacets()) {
      solrQuery.add(StatsParams.STATS_FACET, field.getName());
    }

    for (Entry<Field, Collection<Field>> entry : statsOptions.getSelectiveFacets().entrySet()) {

      Field field = entry.getKey();
      String prefix = CommonParams.FIELD + "." + field.getName() + ".";

      String paramName = prefix + StatsParams.STATS_FACET;
View Full Code Here

    createQueryForMethod("findAndApplyStats", Pageable.class).execute(new Object[] { new PageRequest(0, 10) });

    Mockito.verify(solrOperationsMock, Mockito.times(1)).queryForPage(captor.capture(),
        (Class<ProductBean>) Matchers.any());

    StatsOptions capturedOptions = captor.getValue().getStatsOptions();

    Assert.assertEquals(2, capturedOptions.getFields().size());
    Assert.assertTrue(capturedOptions.getFields().containsAll(
        Arrays.asList(new SimpleField("field1"), new SimpleField("field4"))));

    Assert.assertEquals(2, capturedOptions.getFacets().size());
    Assert.assertTrue(capturedOptions.getFacets().containsAll(
        Arrays.asList(new SimpleField("field2"), new SimpleField("field3"))));

    Collection<Field> selectiveFacetsField = capturedOptions.getSelectiveFacets().get(new SimpleField("field4"));
    List<SimpleField> selectiveFacetsFields = Arrays.asList(new SimpleField("field4_1"), new SimpleField("field4_2"));
    Assert.assertEquals(1, capturedOptions.getSelectiveFacets().size());
    Assert.assertTrue(selectiveFacetsField.containsAll(selectiveFacetsFields));
  }
View Full Code Here

        new Object[] { new PageRequest(0, 10) });

    Mockito.verify(solrOperationsMock, Mockito.times(1)).queryForPage(captor.capture(),
        (Class<ProductBean>) Matchers.any());

    StatsOptions capturedOptions = captor.getValue().getStatsOptions();

    Assert.assertEquals(1, capturedOptions.getFields().size());
    Assert.assertTrue(capturedOptions.getFields().containsAll(Arrays.asList(new SimpleField("field1"))));

    Assert.assertEquals(2, capturedOptions.getFacets().size());
    Assert.assertTrue(capturedOptions.getFacets().containsAll(
        Arrays.asList(new SimpleField("field2"), new SimpleField("field3"))));

    Assert.assertThat(capturedOptions.getSelectiveFacets().entrySet(), IsEmptyIterable.emptyIterable());
  }
View Full Code Here

    createQueryForMethod("findAndApplyStatsNoFacets", Pageable.class).execute(new Object[] { new PageRequest(0, 10) });

    Mockito.verify(solrOperationsMock, Mockito.times(1)).queryForPage(captor.capture(),
        (Class<ProductBean>) Matchers.any());

    StatsOptions capturedOptions = captor.getValue().getStatsOptions();

    Assert.assertEquals(1, capturedOptions.getFields().size());
    Assert.assertTrue(capturedOptions.getFields().containsAll(Arrays.asList(new SimpleField("field1"))));

    Assert.assertThat(capturedOptions.getFacets(), IsEmptyIterable.emptyIterable());
    Assert.assertThat(capturedOptions.getSelectiveFacets().entrySet(), IsEmptyIterable.emptyIterable());
  }
View Full Code Here

  /**
   * @see DATASOLR-160
   */
  @Test
  public void testConstructSolrQueryWithStatField() {
    StatsOptions statsOptions = new StatsOptions().addField(new SimpleField("field_1"));

    SimpleQuery query = new SimpleQuery("*:*");
    query.setStatsOptions(statsOptions);

    SolrQuery solrQuery = queryParser.constructSolrQuery(query);
View Full Code Here

  /**
   * @see DATASOLR-160
   */
  @Test
  public void testConstructSolrQueryWithStatFields() {
    StatsOptions statsOptions = new StatsOptions()//
        .addField(new SimpleField("field_1"))//
        .addField(new SimpleField("field_2"));

    SimpleQuery query = new SimpleQuery("*:*");
    query.setStatsOptions(statsOptions);
 
View Full Code Here

  /**
   * @see DATASOLR-160
   */
  @Test
  public void testConstructSolrQueryWithStatFacets() {
    StatsOptions statsOptions = new StatsOptions()//
        .addFacet(new SimpleField("field_1"))//
        .addFacet(new SimpleField("field_2"));

    SimpleQuery query = new SimpleQuery("*:*");
    query.setStatsOptions(statsOptions);
 
View Full Code Here

  /**
   * @see DATASOLR-160
   */
  @Test
  public void testConstructSolrQueryWithStatFieldsAndFacets() {
    StatsOptions statsOptions = new StatsOptions()//
        .addField(new SimpleField("field_1"))//
        .addFacet(new SimpleField("field_2"));

    SimpleQuery query = new SimpleQuery("*:*");
    query.setStatsOptions(statsOptions);
 
View Full Code Here

  /**
   * @see DATASOLR-160
   */
  @Test
  public void testConstructSolrQueryWithSelectiveStatsFacet() {
    StatsOptions statsOptions = new StatsOptions()//
        .addField(new SimpleField("field_1"))//
        .addSelectiveFacet(new SimpleField("field_2"));

    SimpleQuery query = new SimpleQuery("*:*");
    query.setStatsOptions(statsOptions);
 
View Full Code Here

TOP

Related Classes of org.springframework.data.solr.core.query.StatsOptions$StatsOptionsState

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.