Search in sources :

Example 1 with SortedInputIterator

use of org.apache.lucene.search.suggest.SortedInputIterator in project lucene-solr by apache.

the class TSTLookup method build.

@Override
public void build(InputIterator iterator) throws IOException {
    if (iterator.hasPayloads()) {
        throw new IllegalArgumentException("this suggester doesn't support payloads");
    }
    if (iterator.hasContexts()) {
        throw new IllegalArgumentException("this suggester doesn't support contexts");
    }
    root = new TernaryTreeNode();
    // make sure it's sorted and the comparator uses UTF16 sort order
    iterator = new SortedInputIterator(tempDir, tempFileNamePrefix, iterator, utf8SortedAsUTF16SortOrder);
    count = 0;
    ArrayList<String> tokens = new ArrayList<>();
    ArrayList<Number> vals = new ArrayList<>();
    BytesRef spare;
    CharsRefBuilder charsSpare = new CharsRefBuilder();
    while ((spare = iterator.next()) != null) {
        charsSpare.copyUTF8Bytes(spare);
        tokens.add(charsSpare.toString());
        vals.add(Long.valueOf(iterator.weight()));
        count++;
    }
    autocomplete.balancedTree(tokens.toArray(), vals.toArray(), 0, tokens.size() - 1, root);
}
Also used : SortedInputIterator(org.apache.lucene.search.suggest.SortedInputIterator) ArrayList(java.util.ArrayList) CharsRefBuilder(org.apache.lucene.util.CharsRefBuilder) BytesRef(org.apache.lucene.util.BytesRef)

Aggregations

ArrayList (java.util.ArrayList)1 SortedInputIterator (org.apache.lucene.search.suggest.SortedInputIterator)1 BytesRef (org.apache.lucene.util.BytesRef)1 CharsRefBuilder (org.apache.lucene.util.CharsRefBuilder)1