Example usage for org.apache.lucene.util ArrayUtil timSort

List of usage examples for org.apache.lucene.util ArrayUtil timSort

Introduction

In this page you can find the example usage for org.apache.lucene.util ArrayUtil timSort.

Prototype

public static <T extends Comparable<? super T>> void timSort(T[] a) 

Source Link

Document

Sorts the given array in natural order.

Usage

From source file:org.apache.solr.search.GraphTermsQParserPlugin.java

License:Apache License

@Override
public QParser createParser(String qstr, SolrParams localParams, SolrParams params, SolrQueryRequest req) {
    return new QParser(qstr, localParams, params, req) {
        @Override/*from  ww  w.jav a 2  s  .  c o m*/
        public Query parse() throws SyntaxError {
            String fname = localParams.get(QueryParsing.F);
            FieldType ft = req.getSchema().getFieldTypeNoEx(fname);
            int maxDocFreq = localParams.getInt("maxDocFreq", Integer.MAX_VALUE);
            String qstr = localParams.get(QueryParsing.V);//never null

            if (qstr.length() == 0) {
                return new MatchNoDocsQuery();
            }

            final String[] splitVals = qstr.split(",");

            Term[] terms = new Term[splitVals.length];
            BytesRefBuilder term = new BytesRefBuilder();
            for (int i = 0; i < splitVals.length; i++) {
                String stringVal = splitVals[i].trim();
                if (ft != null) {
                    ft.readableToIndexed(stringVal, term);
                } else {
                    term.copyChars(stringVal);
                }
                BytesRef ref = term.toBytesRef();
                terms[i] = new Term(fname, ref);
            }

            ArrayUtil.timSort(terms);
            return new ConstantScoreQuery(new GraphTermsQuery(fname, terms, maxDocFreq));
        }
    };
}