Example usage for org.apache.solr.common.params FacetParams FACET_RANGE_GAP

List of usage examples for org.apache.solr.common.params FacetParams FACET_RANGE_GAP

Introduction

In this page you can find the example usage for org.apache.solr.common.params FacetParams FACET_RANGE_GAP.

Prototype

String FACET_RANGE_GAP

To view the source code for org.apache.solr.common.params FacetParams FACET_RANGE_GAP.

Click Source Link

Document

Number indicating the interval of sub-ranges for a numerical facet range.

Usage

From source file:fi.nationallibrary.ndl.solr.request.RangeFieldFacets.java

License:Apache License

private <T extends Comparable<T>> NamedList getFacetRangeCounts(final SchemaField sf,
        final RangeEndpointCalculator<T> calc) throws IOException {

    final String f = sf.getName();
    final NamedList res = new SimpleOrderedMap();
    final NamedList counts = new NamedList();
    res.add("counts", counts);

    final T start = calc.getValue(required.getFieldParam(f, FacetParams.FACET_RANGE_START));

    // not final, hardend may change this
    T end = calc.getValue(required.getFieldParam(f, FacetParams.FACET_RANGE_END));
    if (end.compareTo(start) < 0) {
        throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,
                "range facet 'end' comes before 'start': " + end + " < " + start);
    }/*from ww w .  j  a  v  a2s.c o  m*/

    final String gap = required.getFieldParam(f, FacetParams.FACET_RANGE_GAP);
    String[] gaps = parseGaps(gap);
    // explicitly return the gap.  compute this early so we are more 
    // likely to catch parse errors before attempting math
    for (int i = 0; i < gaps.length; i++) {
        calc.getGap(gaps[i]);
    }
    res.add("gap", gap);

    final int minCount = params.getFieldInt(f, FacetParams.FACET_MINCOUNT, 0);

    final EnumSet<FacetRangeInclude> include = FacetRangeInclude
            .parseParam(params.getFieldParams(f, FacetParams.FACET_RANGE_INCLUDE));

    T low = start;
    int gapIdx = 0;
    int previousCount = 0;

    while (low.compareTo(end) < 0) {
        T high = calc.addGap(low, gaps[gapIdx]);
        if (end.compareTo(high) < 0) {
            if (params.getFieldBool(f, FacetParams.FACET_RANGE_HARD_END, false)) {
                high = end;
            } else {
                end = high;
            }
        }
        if (high.compareTo(low) < 0) {
            throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,
                    "range facet infinite loop (is gap negative? did the math overflow?)");
        }

        final boolean includeLower = (include.contains(FacetRangeInclude.LOWER)
                || (include.contains(FacetRangeInclude.EDGE) && 0 == low.compareTo(start)));
        final boolean includeUpper = (include.contains(FacetRangeInclude.UPPER)
                || (include.contains(FacetRangeInclude.EDGE) && 0 == high.compareTo(end)));

        final String lowS = calc.formatValue(low);
        final String highS = calc.formatValue(high);

        final int count = rangeCount(sf, lowS, highS, includeLower, includeUpper);
        if (count >= minCount && count != previousCount) {
            counts.add(lowS, count);
            previousCount = count;
        }

        low = high;

        gapIdx = Math.min(gaps.length - 1, gapIdx + 1);
    }

    // explicitly return the start and end so all the counts 
    // (including before/after/between) are meaningful - even if mincount
    // has removed the neighboring ranges
    res.add("start", start);
    res.add("end", end);

    final String[] othersP = params.getFieldParams(f, FacetParams.FACET_RANGE_OTHER);
    if (null != othersP && 0 < othersP.length) {
        Set<FacetRangeOther> others = EnumSet.noneOf(FacetRangeOther.class);

        for (final String o : othersP) {
            others.add(FacetRangeOther.get(o));
        }

        // no matter what other values are listed, we don't do
        // anything if "none" is specified.
        if (!others.contains(FacetRangeOther.NONE)) {

            boolean all = others.contains(FacetRangeOther.ALL);
            final String startS = calc.formatValue(start);
            final String endS = calc.formatValue(end);

            if (all || others.contains(FacetRangeOther.BEFORE)) {
                // include upper bound if "outer" or if first gap doesn't already include it
                res.add(FacetRangeOther.BEFORE.toString(),
                        rangeCount(sf, null, startS, false,
                                (include.contains(FacetRangeInclude.OUTER)
                                        || (!(include.contains(FacetRangeInclude.LOWER)
                                                || include.contains(FacetRangeInclude.EDGE))))));

            }
            if (all || others.contains(FacetRangeOther.AFTER)) {
                // include lower bound if "outer" or if last gap doesn't already include it
                res.add(FacetRangeOther.AFTER.toString(),
                        rangeCount(sf, endS, null,
                                (include.contains(FacetRangeInclude.OUTER)
                                        || (!(include.contains(FacetRangeInclude.UPPER)
                                                || include.contains(FacetRangeInclude.EDGE)))),
                                false));
            }
            if (all || others.contains(FacetRangeOther.BETWEEN)) {
                res.add(FacetRangeOther.BETWEEN.toString(), rangeCount(sf, startS, endS,
                        (include.contains(FacetRangeInclude.LOWER) || include.contains(FacetRangeInclude.EDGE)),
                        (include.contains(FacetRangeInclude.UPPER)
                                || include.contains(FacetRangeInclude.EDGE))));

            }
        }
    }
    return res;
}

From source file:org.dspace.statistics.SolrLogger.java

License:BSD License

public static void shardSolrIndex() throws IOException, SolrServerException {
    /*/*www.j a v  a 2s  . c  o  m*/
    Start by faceting by year so we can include each year in a separate core !
     */
    SolrQuery yearRangeQuery = new SolrQuery();
    yearRangeQuery.setQuery("*:*");
    yearRangeQuery.setRows(0);
    yearRangeQuery.setFacet(true);
    yearRangeQuery.add(FacetParams.FACET_RANGE, "time");
    //We go back to 2000 the year 2000, this is a bit overkill but this way we ensure we have everything
    //The alternative would be to sort but that isn't recommended since it would be a very costly query !
    yearRangeQuery.add(FacetParams.FACET_RANGE_START,
            "NOW/YEAR-" + (Calendar.getInstance().get(Calendar.YEAR) - 2000) + "YEARS");
    //Add the +0year to ensure that we DO NOT include the current year
    yearRangeQuery.add(FacetParams.FACET_RANGE_END, "NOW/YEAR+0YEARS");
    yearRangeQuery.add(FacetParams.FACET_RANGE_GAP, "+1YEAR");
    yearRangeQuery.add(FacetParams.FACET_MINCOUNT, String.valueOf(1));

    //Create a temp directory to store our files in !
    File tempDirectory = new File(
            ConfigurationManager.getProperty("dspace.dir") + File.separator + "temp" + File.separator);
    tempDirectory.mkdirs();

    QueryResponse queryResponse = solr.query(yearRangeQuery);
    //We only have one range query !
    List<RangeFacet.Count> yearResults = queryResponse.getFacetRanges().get(0).getCounts();
    for (RangeFacet.Count count : yearResults) {
        long totalRecords = count.getCount();

        //Create a range query from this !
        //We start with out current year
        DCDate dcStart = new DCDate(count.getValue());
        Calendar endDate = Calendar.getInstance();
        //Advance one year for the start of the next one !
        endDate.setTime(dcStart.toDate());
        endDate.add(Calendar.YEAR, 1);
        DCDate dcEndDate = new DCDate(endDate.getTime());

        StringBuilder filterQuery = new StringBuilder();
        filterQuery.append("time:([");
        filterQuery.append(ClientUtils.escapeQueryChars(dcStart.toString()));
        filterQuery.append(" TO ");
        filterQuery.append(ClientUtils.escapeQueryChars(dcEndDate.toString()));
        filterQuery.append("]");
        //The next part of the filter query excludes the content from midnight of the next year !
        filterQuery.append(" NOT ").append(ClientUtils.escapeQueryChars(dcEndDate.toString()));
        filterQuery.append(")");

        Map<String, String> yearQueryParams = new HashMap<String, String>();
        yearQueryParams.put(CommonParams.Q, "*:*");
        yearQueryParams.put(CommonParams.ROWS, String.valueOf(10000));
        yearQueryParams.put(CommonParams.FQ, filterQuery.toString());
        yearQueryParams.put(CommonParams.WT, "csv");

        //Start by creating a new core
        String coreName = "statistics-" + dcStart.getYear();
        HttpSolrServer statisticsYearServer = createCore(solr, coreName);

        System.out.println("Moving: " + totalRecords + " into core " + coreName);
        log.info("Moving: " + totalRecords + " records into core " + coreName);

        List<File> filesToUpload = new ArrayList<File>();
        for (int i = 0; i < totalRecords; i += 10000) {
            String solrRequestUrl = solr.getBaseURL() + "/select";
            solrRequestUrl = generateURL(solrRequestUrl, yearQueryParams);

            HttpGet get = new HttpGet(solrRequestUrl);
            HttpResponse response = new DefaultHttpClient().execute(get);
            InputStream csvInputstream = response.getEntity().getContent();
            //Write the csv ouput to a file !
            File csvFile = new File(tempDirectory.getPath() + File.separatorChar + "temp." + dcStart.getYear()
                    + "." + i + ".csv");
            FileUtils.copyInputStreamToFile(csvInputstream, csvFile);
            filesToUpload.add(csvFile);

            //Add 10000 & start over again
            yearQueryParams.put(CommonParams.START, String.valueOf((i + 10000)));
        }

        for (File tempCsv : filesToUpload) {
            //Upload the data in the csv files to our new solr core
            ContentStreamUpdateRequest contentStreamUpdateRequest = new ContentStreamUpdateRequest(
                    "/update/csv");
            contentStreamUpdateRequest.setParam("stream.contentType", "text/plain;charset=utf-8");
            contentStreamUpdateRequest.setAction(AbstractUpdateRequest.ACTION.COMMIT, true, true);
            contentStreamUpdateRequest.addFile(tempCsv, "text/plain;charset=utf-8");

            statisticsYearServer.request(contentStreamUpdateRequest);
        }
        statisticsYearServer.commit(true, true);

        //Delete contents of this year from our year query !
        solr.deleteByQuery(filterQuery.toString());
        solr.commit(true, true);

        log.info("Moved " + totalRecords + " records into core: " + coreName);
    }

    FileUtils.deleteDirectory(tempDirectory);
}

From source file:org.dspace.statistics.SolrLoggerServiceImpl.java

License:BSD License

@Override
public void shardSolrIndex() throws IOException, SolrServerException {
    /*/* w w w.  ja  v a 2s . co  m*/
    Start by faceting by year so we can include each year in a separate core !
     */
    SolrQuery yearRangeQuery = new SolrQuery();
    yearRangeQuery.setQuery("*:*");
    yearRangeQuery.setRows(0);
    yearRangeQuery.setFacet(true);
    yearRangeQuery.add(FacetParams.FACET_RANGE, "time");
    //We go back to 2000 the year 2000, this is a bit overkill but this way we ensure we have everything
    //The alternative would be to sort but that isn't recommended since it would be a very costly query !
    yearRangeQuery.add(FacetParams.FACET_RANGE_START,
            "NOW/YEAR-" + (Calendar.getInstance().get(Calendar.YEAR) - 2000) + "YEARS");
    //Add the +0year to ensure that we DO NOT include the current year
    yearRangeQuery.add(FacetParams.FACET_RANGE_END, "NOW/YEAR+0YEARS");
    yearRangeQuery.add(FacetParams.FACET_RANGE_GAP, "+1YEAR");
    yearRangeQuery.add(FacetParams.FACET_MINCOUNT, String.valueOf(1));

    //Create a temp directory to store our files in !
    File tempDirectory = new File(
            configurationService.getProperty("dspace.dir") + File.separator + "temp" + File.separator);
    tempDirectory.mkdirs();

    QueryResponse queryResponse = solr.query(yearRangeQuery);
    //We only have one range query !
    List<RangeFacet.Count> yearResults = queryResponse.getFacetRanges().get(0).getCounts();
    for (RangeFacet.Count count : yearResults) {
        long totalRecords = count.getCount();

        //Create a range query from this !
        //We start with out current year
        DCDate dcStart = new DCDate(count.getValue());
        Calendar endDate = Calendar.getInstance();
        //Advance one year for the start of the next one !
        endDate.setTime(dcStart.toDate());
        endDate.add(Calendar.YEAR, 1);
        DCDate dcEndDate = new DCDate(endDate.getTime());

        StringBuilder filterQuery = new StringBuilder();
        filterQuery.append("time:([");
        filterQuery.append(ClientUtils.escapeQueryChars(dcStart.toString()));
        filterQuery.append(" TO ");
        filterQuery.append(ClientUtils.escapeQueryChars(dcEndDate.toString()));
        filterQuery.append("]");
        //The next part of the filter query excludes the content from midnight of the next year !
        filterQuery.append(" NOT ").append(ClientUtils.escapeQueryChars(dcEndDate.toString()));
        filterQuery.append(")");

        Map<String, String> yearQueryParams = new HashMap<String, String>();
        yearQueryParams.put(CommonParams.Q, "*:*");
        yearQueryParams.put(CommonParams.ROWS, String.valueOf(10000));
        yearQueryParams.put(CommonParams.FQ, filterQuery.toString());
        yearQueryParams.put(CommonParams.WT, "csv");

        //Start by creating a new core
        String coreName = "statistics-" + dcStart.getYear();
        HttpSolrServer statisticsYearServer = createCore(solr, coreName);

        System.out.println("Moving: " + totalRecords + " into core " + coreName);
        log.info("Moving: " + totalRecords + " records into core " + coreName);

        List<File> filesToUpload = new ArrayList<File>();
        for (int i = 0; i < totalRecords; i += 10000) {
            String solrRequestUrl = solr.getBaseURL() + "/select";
            solrRequestUrl = generateURL(solrRequestUrl, yearQueryParams);

            HttpGet get = new HttpGet(solrRequestUrl);
            HttpResponse response = new DefaultHttpClient().execute(get);
            InputStream csvInputstream = response.getEntity().getContent();
            //Write the csv ouput to a file !
            File csvFile = new File(tempDirectory.getPath() + File.separatorChar + "temp." + dcStart.getYear()
                    + "." + i + ".csv");
            FileUtils.copyInputStreamToFile(csvInputstream, csvFile);
            filesToUpload.add(csvFile);

            //Add 10000 & start over again
            yearQueryParams.put(CommonParams.START, String.valueOf((i + 10000)));
        }

        for (File tempCsv : filesToUpload) {
            //Upload the data in the csv files to our new solr core
            ContentStreamUpdateRequest contentStreamUpdateRequest = new ContentStreamUpdateRequest(
                    "/update/csv");
            contentStreamUpdateRequest.setParam("stream.contentType", "text/plain;charset=utf-8");
            contentStreamUpdateRequest.setParam("skip", "_version_");
            contentStreamUpdateRequest.setAction(AbstractUpdateRequest.ACTION.COMMIT, true, true);
            contentStreamUpdateRequest.addFile(tempCsv, "text/plain;charset=utf-8");

            statisticsYearServer.request(contentStreamUpdateRequest);
        }
        statisticsYearServer.commit(true, true);

        //Delete contents of this year from our year query !
        solr.deleteByQuery(filterQuery.toString());
        solr.commit(true, true);

        log.info("Moved " + totalRecords + " records into core: " + coreName);
    }

    FileUtils.deleteDirectory(tempDirectory);
}

From source file:org.dspace.util.SolrImportExport.java

License:BSD License

/**
 * Exports documents from the given index to the specified target directory in batches of #ROWS_PER_FILE, starting at fromWhen (or all documents).
 * See #makeExportFilename for the file names that are generated.
 *
 * @param indexName The index to export.
 * @param toDir The target directory for the export. Will be created if it doesn't exist yet. The directory must be writeable.
 * @param solrUrl The solr URL for the index to export. Must not be null.
 * @param timeField The time field to use for sorting the export. Must not be null.
 * @param fromWhen Optionally, from when to export. See options for allowed values. If null or empty, all documents will be exported.
 * @throws SolrServerException if there is a problem with exporting the index.
 * @throws IOException if there is a problem creating the files or communicating with Solr.
 * @throws SolrImportExportException if there is a problem in communicating with Solr.
 */// w  ww.  j  a  v  a 2  s .c  o m
public static void exportIndex(String indexName, File toDir, String solrUrl, String timeField, String fromWhen)
        throws SolrServerException, IOException, SolrImportExportException {
    if (StringUtils.isBlank(solrUrl)) {
        throw new SolrImportExportException(
                "Could not construct solr URL for index" + indexName + ", aborting export.");
    }

    if (!toDir.exists() || !toDir.canWrite()) {
        throw new SolrImportExportException("Target directory " + toDir
                + " doesn't exist or is not writable, aborting export of index " + indexName);
    }

    HttpSolrServer solr = new HttpSolrServer(solrUrl);

    SolrQuery query = new SolrQuery("*:*");
    if (StringUtils.isNotBlank(fromWhen)) {
        String lastValueFilter = makeFilterQuery(timeField, fromWhen);
        if (StringUtils.isNotBlank(lastValueFilter)) {
            query.addFilterQuery(lastValueFilter);
        }
    }

    query.setRows(0);
    query.setGetFieldStatistics(timeField);
    Map<String, FieldStatsInfo> fieldInfo = solr.query(query).getFieldStatsInfo();
    if (fieldInfo == null || !fieldInfo.containsKey(timeField)) {
        log.warn("Cannot get earliest date, not exporting index " + indexName + ", time field " + timeField
                + ", from " + fromWhen);
        return;
    }
    FieldStatsInfo timeFieldInfo = fieldInfo.get(timeField);
    if (timeFieldInfo == null || timeFieldInfo.getMin() == null) {
        log.warn("Cannot get earliest date, not exporting index " + indexName + ", time field " + timeField
                + ", from " + fromWhen);
        return;
    }
    Date earliestTimestamp = (Date) timeFieldInfo.getMin();

    query.setGetFieldStatistics(false);
    query.clearSorts();
    query.setRows(0);
    query.setFacet(true);
    query.add(FacetParams.FACET_RANGE, timeField);
    query.add(FacetParams.FACET_RANGE_START, SOLR_DATE_FORMAT.format(earliestTimestamp) + "/MONTH");
    query.add(FacetParams.FACET_RANGE_END, "NOW/MONTH+1MONTH");
    query.add(FacetParams.FACET_RANGE_GAP, "+1MONTH");
    query.setFacetMinCount(1);

    List<RangeFacet.Count> monthFacets = solr.query(query).getFacetRanges().get(0).getCounts();

    for (RangeFacet.Count monthFacet : monthFacets) {
        Date monthStartDate;
        String monthStart = monthFacet.getValue();
        try {
            monthStartDate = SOLR_DATE_FORMAT_NO_MS.parse(monthStart);
        } catch (java.text.ParseException e) {
            throw new SolrImportExportException("Could not read start of month batch as date: " + monthStart,
                    e);
        }
        int docsThisMonth = monthFacet.getCount();

        SolrQuery monthQuery = new SolrQuery("*:*");
        monthQuery.setRows(ROWS_PER_FILE);
        monthQuery.set("wt", "csv");
        monthQuery.set("fl", "*");

        monthQuery.addFilterQuery(timeField + ":[" + monthStart + " TO " + monthStart + "+1MONTH]");

        for (int i = 0; i < docsThisMonth; i += ROWS_PER_FILE) {
            monthQuery.setStart(i);
            URL url = new URL(solrUrl + "/select?" + monthQuery.toString());

            File file = new File(toDir.getCanonicalPath(),
                    makeExportFilename(indexName, monthStartDate, docsThisMonth, i));
            if (file.createNewFile()) {
                FileUtils.copyURLToFile(url, file);
                log.info("Exported batch " + i + " to " + file.getCanonicalPath());
            } else {
                throw new SolrImportExportException("Could not create file " + file.getCanonicalPath()
                        + " while exporting index " + indexName + ", month" + monthStart + ", batch " + i);
            }
        }
    }
}

From source file:org.jahia.services.search.facets.SimpleJahiaJcrFacets.java

License:Open Source License

private <T extends Comparable<T>> NamedList<Object> getFacetRangeCounts(final SchemaField sf, final String f,
        final RangeEndpointCalculator<T> calc) throws IOException {
    String prefix = params.getFieldParam(f, FacetParams.FACET_PREFIX);

    final NamedList<Object> res = new SimpleOrderedMap<Object>();
    final NamedList<Object> counts = new NamedList<Object>();
    res.add("counts", counts);

    final T start = calc.getValue(required.getFieldParam(f, FacetParams.FACET_RANGE_START));
    // not final, hardend may change this
    T end = calc.getValue(required.getFieldParam(f, FacetParams.FACET_RANGE_END));
    if (end.compareTo(start) < 0) {
        throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,
                "range facet 'end' comes before 'start': " + end + " < " + start);
    }/*from  w  w w. jav  a2  s .  co m*/

    final String gap = required.getFieldParam(f, FacetParams.FACET_RANGE_GAP);
    // explicitly return the gap.  compute this early so we are more 
    // likely to catch parse errors before attempting math
    res.add("gap", calc.getGap(gap));

    final int minCount = params.getFieldInt(f, FacetParams.FACET_MINCOUNT, 0);

    final EnumSet<FacetRangeInclude> include = FacetRangeInclude
            .parseParam(params.getFieldParams(f, FacetParams.FACET_RANGE_INCLUDE));

    T low = start;

    while (low.compareTo(end) < 0) {
        T high = calc.addGap(low, gap);
        if (end.compareTo(high) < 0) {
            if (params.getFieldBool(f, FacetParams.FACET_RANGE_HARD_END, false)) {
                high = end;
            } else {
                end = high;
            }
        }
        if (high.compareTo(low) < 0) {
            throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,
                    "range facet infinite loop (is gap negative? did the math overflow?)");
        }

        final boolean includeLower = (include.contains(FacetRangeInclude.LOWER)
                || (include.contains(FacetRangeInclude.EDGE) && 0 == low.compareTo(start)));
        final boolean includeUpper = (include.contains(FacetRangeInclude.UPPER)
                || (include.contains(FacetRangeInclude.EDGE) && 0 == high.compareTo(end)));

        final String lowS = calc.formatValue(low);
        final String highS = calc.formatValue(high);

        Query rangeQ = getRangeQuery(sf.getType(), null, sf, prefix, lowS, highS, includeLower, includeUpper);
        final int count = rangeCount(rangeQ);
        if (count >= minCount) {
            counts.add(lowS + PROPNAME_INDEX_SEPARATOR + rangeQ.toString(), count);
        }

        low = high;
    }

    // explicitly return the start and end so all the counts 
    // (including before/after/between) are meaningful - even if mincount
    // has removed the neighboring ranges
    res.add("start", start);
    res.add("end", end);

    final String[] othersP = params.getFieldParams(f, FacetParams.FACET_RANGE_OTHER);
    if (null != othersP && 0 < othersP.length) {
        Set<FacetRangeOther> others = EnumSet.noneOf(FacetRangeOther.class);

        for (final String o : othersP) {
            others.add(FacetRangeOther.get(o));
        }

        // no matter what other values are listed, we don't do
        // anything if "none" is specified.
        if (!others.contains(FacetRangeOther.NONE)) {

            boolean all = others.contains(FacetRangeOther.ALL);
            final String startS = calc.formatValue(start);
            final String endS = calc.formatValue(end);

            if (all || others.contains(FacetRangeOther.BEFORE)) {
                // include upper bound if "outer" or if first gap doesn't already include it
                Query rangeQ = getRangeQuery(sf.getType(), null, sf, prefix, null, startS, false,
                        (include.contains(FacetRangeInclude.OUTER)
                                || (!(include.contains(FacetRangeInclude.LOWER)
                                        || include.contains(FacetRangeInclude.EDGE)))));
                int count = rangeCount(rangeQ);
                if (count >= minCount) {
                    res.add(FacetRangeOther.BEFORE.toString(), count);
                    counts.add(FacetRangeOther.BEFORE.toString() + PROPNAME_INDEX_SEPARATOR + rangeQ.toString(),
                            count);
                }
            }
            if (all || others.contains(FacetRangeOther.AFTER)) {
                // include lower bound if "outer" or if last gap doesn't already include it
                Query rangeQ = getRangeQuery(sf.getType(), null, sf, prefix, endS, null,
                        (include.contains(FacetRangeInclude.OUTER)
                                || (!(include.contains(FacetRangeInclude.UPPER)
                                        || include.contains(FacetRangeInclude.EDGE)))),
                        false);
                int count = rangeCount(rangeQ);
                if (count >= minCount) {
                    res.add(FacetRangeOther.AFTER.toString(), count);
                    counts.add(FacetRangeOther.AFTER.toString() + PROPNAME_INDEX_SEPARATOR + rangeQ.toString(),
                            count);
                }
            }
            if (all || others.contains(FacetRangeOther.BETWEEN)) {
                Query rangeQ = getRangeQuery(sf.getType(), null, sf, prefix, startS, endS,
                        (include.contains(FacetRangeInclude.LOWER) || include.contains(FacetRangeInclude.EDGE)),
                        (include.contains(FacetRangeInclude.UPPER)
                                || include.contains(FacetRangeInclude.EDGE)));
                int count = rangeCount(rangeQ);
                if (count >= minCount) {
                    res.add(FacetRangeOther.BETWEEN.toString(), count);
                    counts.add(
                            FacetRangeOther.BETWEEN.toString() + PROPNAME_INDEX_SEPARATOR + rangeQ.toString(),
                            count);
                }
            }
        }
    }
    return res;
}

From source file:org.springframework.data.solr.core.query.FacetOptionsTests.java

License:Apache License

@Test // DATSOLR-86
public void testDateRangeFacetAccessors() {
    Date start = new Date(100);
    Date end = new Date(10000000);
    String gap = "+1DAY";
    boolean hardEnd = true;
    FacetRangeInclude include = FacetRangeInclude.LOWER;
    FacetRangeOther other = FacetRangeOther.BEFORE;

    FieldWithDateRangeParameters dateRangeField = new FieldWithDateRangeParameters( //
            "name", //
            start, //
            end, //
            gap//
    )////from  w w w.  j a  v a  2s . c om
            .setHardEnd(hardEnd) //
            .setInclude(include) //
            .setOther(other);

    Assert.assertEquals("name", dateRangeField.getName());
    Assert.assertEquals(start, dateRangeField.getStart());
    Assert.assertEquals(end, dateRangeField.getEnd());
    Assert.assertEquals(gap, dateRangeField.getGap());
    Assert.assertEquals(hardEnd, dateRangeField.getHardEnd());
    Assert.assertEquals(include, dateRangeField.getInclude());
    Assert.assertEquals(other, dateRangeField.getOther());

    Assert.assertEquals(start, dateRangeField.getQueryParameter(FacetParams.FACET_RANGE_START).getValue());
    Assert.assertEquals(end, dateRangeField.getQueryParameter(FacetParams.FACET_RANGE_END).getValue());
    Assert.assertEquals(gap, dateRangeField.getQueryParameter(FacetParams.FACET_RANGE_GAP).getValue());
    Assert.assertEquals(hardEnd, dateRangeField.getQueryParameter(FacetParams.FACET_RANGE_HARD_END).getValue());
    Assert.assertEquals(include, dateRangeField.getQueryParameter(FacetParams.FACET_RANGE_INCLUDE).getValue());
    Assert.assertEquals(other, dateRangeField.getQueryParameter(FacetParams.FACET_RANGE_OTHER).getValue());
}

From source file:org.springframework.data.solr.core.query.FacetOptionsTests.java

License:Apache License

@Test // DATSOLR-86
public void testNumericRangeFacetAccessors() {
    int start = 100;
    int end = 10000000;
    int gap = 200;
    boolean hardEnd = true;
    FacetRangeInclude include = FacetRangeInclude.LOWER;
    FacetRangeOther other = FacetRangeOther.BEFORE;

    FieldWithNumericRangeParameters numRangeField = new FieldWithNumericRangeParameters( //
            "name", //
            start, //
            end, //
            gap //
    )///*from   w ww.  j ava2  s.c  om*/
            .setHardEnd(hardEnd) //
            .setInclude(include) //
            .setOther(other);

    Assert.assertEquals("name", numRangeField.getName());
    Assert.assertEquals(start, numRangeField.getStart());
    Assert.assertEquals(end, numRangeField.getEnd());
    Assert.assertEquals(gap, numRangeField.getGap());
    Assert.assertEquals(hardEnd, numRangeField.getHardEnd());
    Assert.assertEquals(include, numRangeField.getInclude());
    Assert.assertEquals(other, numRangeField.getOther());

    Assert.assertEquals(start, numRangeField.getQueryParameter(FacetParams.FACET_RANGE_START).getValue());
    Assert.assertEquals(end, numRangeField.getQueryParameter(FacetParams.FACET_RANGE_END).getValue());
    Assert.assertEquals(gap, numRangeField.getQueryParameter(FacetParams.FACET_RANGE_GAP).getValue());
    Assert.assertEquals(hardEnd, numRangeField.getQueryParameter(FacetParams.FACET_RANGE_HARD_END).getValue());
    Assert.assertEquals(include, numRangeField.getQueryParameter(FacetParams.FACET_RANGE_INCLUDE).getValue());
    Assert.assertEquals(other, numRangeField.getQueryParameter(FacetParams.FACET_RANGE_OTHER).getValue());
}