Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* 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.lucene.search.suggest.fst;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Spliterator;
import java.util.function.Consumer;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
import org.apache.lucene.util.ArrayUtil;
import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.fst.FST;
import org.apache.lucene.util.fst.FST.Arc;
/**
* Finite state automata based implementation of "autocomplete" functionality.
*
* @see FSTCompletionBuilder
* @lucene.experimental
*/
// TODO: we could store exact weights as outputs from the FST (int4 encoded
// floats). This would provide exact outputs from this method and to some
// degree allowed post-sorting on a more fine-grained weight.
// TODO: support for Analyzers (infix suggestions, synonyms?)
public class FSTCompletion {
/** A single completion for a given key. */
public static final class Completion implements Comparable {
/** UTF-8 bytes of the suggestion */
public final BytesRef utf8;
/** source bucket (weight) of the suggestion */
public final int bucket;
Completion(BytesRef key, int bucket) {
this.utf8 = BytesRef.deepCopyOf(key);
this.bucket = bucket;
}
@Override
public String toString() {
return utf8.utf8ToString() + "/" + bucket;
}
/** Completions are equal when their {@link #utf8} images are equal (bucket is not compared). */
@Override
public int compareTo(Completion o) {
return this.utf8.compareTo(o.utf8);
}
}
/** Default number of buckets. */
public static final int DEFAULT_BUCKETS = 10;
/**
* An empty result. Keep this an {@link ArrayList} to keep all the returned lists of single type
* (monomorphic calls).
*/
private static final ArrayList EMPTY_RESULT = new ArrayList<>();
/** Finite state automaton encoding all the lookup terms. See class notes for details. */
private final FST