/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.solr.client.solrj.response;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import org.apache.solr.client.solrj.util.ClientUtils;
/**
* A utility class to hold the facet response. It could use the NamedList container,
* but for JSTL, it is nice to have something that implements List so it can be iterated
*
* @version $Id: FacetField.java 638357 2008-03-18 13:12:27Z gsingers $
* @since solr 1.3
*/
public class FacetField implements Serializable
{
public static class Count implements Serializable
{
private String _name = null;
private long _count = 0;
private ArrayList<String> _extList = null;
// hang onto the FacetField for breadcrumb creation convenience
private FacetField _ff = null;
public Count( FacetField ff, String n, long c ,ArrayList<String> l)
{
_name = n;
_count = c;
_extList = l;
_ff = ff;
}
public String getName() {
return _name;
}
public void setName( String n )
{
_name = n;
}
public long getCount() {
return _count;
}
public void setCount( long c )
{
_count = c;
}
public void setExtList( ArrayList<String> l )
{
_extList = l;
}
public ArrayList<String> getExtList()
{
return _extList;
}
public FacetField getFacetField() {
return _ff;
}
@Override
public String toString()
{
return _name+" ("+_count+")";
}
public String getAsFilterQuery() {
if (_ff.getName().equals("facet_queries")) {
return _name;
}
return
ClientUtils.escapeQueryChars( _ff._name ) + ":" +
ClientUtils.escapeQueryChars( _name );
}
}
private String _name = null;
private List<Count> _values = null;
private String _gap = null;
private Date _end = null;
private long _total = 0;
public long getTotal()
{
return _total;
}
public void setTotal(long v)
{
_total = v;
}
public FacetField( final String n )
{
_name = n;
}
public FacetField(String name, String gap, Date end) {
_name = name;
_gap = gap;
_end = end;
}
/**
* Date Gap Facet parameter
*
* @return the value specified for facet.date.gap
*/
public String getGap() {
return _gap;
}
/**
* Date End Facet parameter
*
* @return the value specified for facet.date.end
*/
public Date getEnd() {
return _end;
}
/**
* Insert at the end of the list
*/
public void add( String name, long cnt , ArrayList<String> l)
{
if( _values == null ) {
_values = new ArrayList<Count>( 30 );
}
_values.add( new Count( this, name, cnt, l) );
}
/**
* Insert at the beginning of the list.
*/
public void insert( String name, long cnt, ArrayList<String> l)
{
if( _values == null ) {
_values = new ArrayList<Count>( 30 );
}
_values.add( 0, new Count( this, name, cnt, l) );
}
public String getName() {
return _name;
}
public List<Count> getValues() {
return _values;
}
public int getValueCount()
{
return _values == null ? 0 : _values.size();
}
public FacetField getLimitingFields(long max)
{
FacetField ff = new FacetField( _name );
if( _values != null ) {
ff._values = new ArrayList<Count>( _values.size() );
for( Count c : _values ) {
if( c._count < max ) { // !equal to
ff._values.add( c );
}
}
}
return ff;
}
@Override
public String toString()
{
return _name + ":" + _values;
}
}