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

Examples of org.springframework.data.solr.core.query.FacetOptions$FieldWithFacetParameters


  }

  @Override
  public FacetPage<Product> findByNameStartingWithAndFacetOnAvailable(String namePrefix) {
    FacetQuery query = new SimpleFacetQuery(new Criteria(SolrSearchableFields.NAME).startsWith(namePrefix));
    query.setFacetOptions(new FacetOptions(SolrSearchableFields.AVAILABLE));
    return getSolrOperations().queryForFacetPage(query, Product.class);
  }
View Full Code Here


    return options;
  }

  private FacetOptions extractFacetOptions(SolrQueryMethod queryMethod, SolrParameterAccessor parameterAccessor) {
    FacetOptions options = new FacetOptions();
    if (queryMethod.hasFacetFields()) {
      options.addFacetOnFlieldnames(queryMethod.getFacetFields());
    }
    if (queryMethod.hasFacetQueries()) {
      for (String queryString : queryMethod.getFacetQueries()) {
        options.addFacetQuery(createQueryFromString(queryString, parameterAccessor));
      }
    }
    if (queryMethod.hasPivotFields()) {
      for (String[] pivot : queryMethod.getPivotFields()) {
        options.addFacetOnPivot(pivot);
      }
    }
    options.setFacetLimit(queryMethod.getFacetLimit());
    options.setFacetMinCount(queryMethod.getFacetMinCount());
    options.setFacetPrefix(replacePlaceholders(queryMethod.getFacetPrefix(), parameterAccessor));
    return options;
  }
View Full Code Here

  protected String createPerFieldOverrideParameterName(Field field, String parameterName) {
    return "f." + field.getName() + "." + parameterName;
  }

  private boolean enableFaceting(SolrQuery solrQuery, FacetQuery query) {
    FacetOptions facetOptions = query.getFacetOptions();
    if (facetOptions == null
        || (!facetOptions.hasFields() && !facetOptions.hasFacetQueries() && !facetOptions.hasPivotFields())) {
      return false;
    }
    solrQuery.setFacet(true);
    solrQuery.setFacetMinCount(facetOptions.getFacetMinCount());
    solrQuery.setFacetLimit(facetOptions.getPageable().getPageSize());
    if (facetOptions.getPageable().getPageNumber() > 0) {
      solrQuery.set(FacetParams.FACET_OFFSET, facetOptions.getPageable().getOffset());
    }
    if (FacetOptions.FacetSort.INDEX.equals(facetOptions.getFacetSort())) {
      solrQuery.setFacetSort(FacetParams.FACET_SORT_INDEX);
    }
    return true;
  }
View Full Code Here

    }
    return true;
  }

  private void appendFacetingOnFields(SolrQuery solrQuery, FacetQuery query) {
    FacetOptions facetOptions = query.getFacetOptions();
    if (facetOptions.getPageable().getPageNumber() > 0) {
      solrQuery.set(FacetParams.FACET_OFFSET, facetOptions.getPageable().getOffset());
    }
    solrQuery.addFacetField(convertFieldListToStringArray(facetOptions.getFacetOnFields()));
    if (facetOptions.hasFacetPrefix()) {
      solrQuery.setFacetPrefix(facetOptions.getFacetPrefix());
    }
    for (FieldWithFacetParameters parametrizedField : facetOptions.getFieldsWithParameters()) {
      addPerFieldFacetParameters(solrQuery, parametrizedField);
      if (parametrizedField.getSort() != null && FacetOptions.FacetSort.INDEX.equals(parametrizedField.getSort())) {
        addFieldSpecificParameterToSolrQuery(solrQuery, parametrizedField, new FacetParameter(FacetParams.FACET_SORT,
            FacetParams.FACET_SORT_INDEX));
      }
View Full Code Here

      addFieldSpecificParameterToSolrQuery(solrQuery, field, parameter);
    }
  }

  private void appendFacetingQueries(SolrQuery solrQuery, FacetQuery query) {
    FacetOptions facetOptions = query.getFacetOptions();
    for (SolrDataQuery fq : facetOptions.getFacetQueries()) {
      String facetQueryString = getQueryString(fq);
      if (StringUtils.isNotBlank(facetQueryString)) {
        solrQuery.addFacetQuery(facetQueryString);
      }
    }
View Full Code Here

    if (VersionUtil.isSolr3XAvailable()) {
      throw new UnsupportedOperationException(
          "Pivot Facets are not available for solr version lower than 4.x - Please check your depdendencies.");
    }

    FacetOptions facetOptions = query.getFacetOptions();
    String[] pivotFields = convertFieldListToStringArray(facetOptions.getFacetOnPivots());
    solrQuery.addFacetPivotField(pivotFields);
  }
View Full Code Here

    }
    solrTemplate.saveBeans(values);
    solrTemplate.commit();

    FacetQuery q = new SimpleFacetQuery(new Criteria(Criteria.WILDCARD).expression(Criteria.WILDCARD))
        .setFacetOptions(new FacetOptions().addFacetOnField("name").addFacetOnField("id").setFacetLimit(5));

    FacetPage<ExampleSolrBean> page = solrTemplate.queryForFacetPage(q, ExampleSolrBean.class);

    for (Page<FacetFieldEntry> facetResultPage : page.getFacetResultPages()) {
      Assert.assertEquals(5, facetResultPage.getNumberOfElements());
View Full Code Here

    }
    solrTemplate.saveBeans(values);
    solrTemplate.commit();

    FacetQuery q = new SimpleFacetQuery(new Criteria(Criteria.WILDCARD).expression(Criteria.WILDCARD))
        .setFacetOptions(new FacetOptions().addFacetOnPivot("cat", "name"));

    FacetPage<ExampleSolrBean> page = solrTemplate.queryForFacetPage(q, ExampleSolrBean.class);

    List<FacetPivotFieldEntry> pivotEntries = page.getPivot("cat,name");
    Assert.assertNotNull(pivotEntries);
View Full Code Here

    }
    solrTemplate.saveBeans(values);
    solrTemplate.commit();

    FacetQuery q = new SimpleFacetQuery(new SimpleStringCriteria("*:*"));
    q.setFacetOptions(new FacetOptions(new SimpleQuery(new SimpleStringCriteria("inStock:true")), new SimpleQuery(
        new SimpleStringCriteria("inStock:false"))));

    FacetPage<ExampleSolrBean> page = solrTemplate.queryForFacetPage(q, ExampleSolrBean.class);

    Page<FacetQueryEntry> facetQueryResultPage = page.getFacetQueryResult();
View Full Code Here

    solrTemplate.saveBeans(Arrays.asList(season, framework, island, language));
    solrTemplate.commit();

    FacetQuery q = new SimpleFacetQuery(new Criteria(Criteria.WILDCARD).expression(Criteria.WILDCARD))
        .setFacetOptions(new FacetOptions().addFacetOnField("name").setFacetLimit(5).setFacetPrefix("spr"));

    FacetPage<ExampleSolrBean> page = solrTemplate.queryForFacetPage(q, ExampleSolrBean.class);
    Page<FacetFieldEntry> facetPage = page.getFacetResultPage(new SimpleField("name"));
    for (FacetFieldEntry entry : facetPage) {
      Assert.assertEquals("spring", entry.getValue());
View Full Code Here

TOP

Related Classes of org.springframework.data.solr.core.query.FacetOptions$FieldWithFacetParameters

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.