mirror of https://github.com/apache/lucene.git
LUCENE-6093: don't throw NPE when BlendedInfixSuggester.lookup doesn't have a prefix token
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1656173 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
a705371bfc
commit
b5db48c783
|
@ -484,6 +484,10 @@ Bug Fixes
|
||||||
high frequency terms in extremely large indices (Robert Muir, Mike
|
high frequency terms in extremely large indices (Robert Muir, Mike
|
||||||
McCandless)
|
McCandless)
|
||||||
|
|
||||||
|
* LUCENE-6093: Don't throw NullPointerException from
|
||||||
|
BlendedInfixSuggester for lookups that do not end in a prefix
|
||||||
|
token. (jane chang via Mike McCandless)
|
||||||
|
|
||||||
Documentation
|
Documentation
|
||||||
|
|
||||||
* LUCENE-5392: Add/improve analysis package documentation to reflect
|
* LUCENE-5392: Add/improve analysis package documentation to reflect
|
||||||
|
|
|
@ -576,7 +576,11 @@ public class AnalyzingInfixSuggester extends Lookup implements Closeable {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create the results based on the search hits.
|
* Create the results based on the search hits.
|
||||||
* Can be overridden by subclass to add particular behavior (e.g. weight transformation)
|
* Can be overridden by subclass to add particular behavior (e.g. weight transformation).
|
||||||
|
* Note that there is no prefix toke (the {@code prefixToken} argument will
|
||||||
|
* be null) whenever the final token in the incoming request was in fact finished
|
||||||
|
* (had trailing characters, such as white-space).
|
||||||
|
*
|
||||||
* @throws IOException If there are problems reading fields from the underlying Lucene index.
|
* @throws IOException If there are problems reading fields from the underlying Lucene index.
|
||||||
*/
|
*/
|
||||||
protected List<LookupResult> createResults(IndexSearcher searcher, TopFieldDocs hits, int num,
|
protected List<LookupResult> createResults(IndexSearcher searcher, TopFieldDocs hits, int num,
|
||||||
|
|
|
@ -261,7 +261,7 @@ public class BlendedInfixSuggester extends AnalyzingInfixSuggester {
|
||||||
|
|
||||||
String docTerm = term.utf8ToString();
|
String docTerm = term.utf8ToString();
|
||||||
|
|
||||||
if (matchedTokens.contains(docTerm) || docTerm.startsWith(prefixToken)) {
|
if (matchedTokens.contains(docTerm) || (prefixToken != null && docTerm.startsWith(prefixToken))) {
|
||||||
|
|
||||||
DocsAndPositionsEnum docPosEnum = it.docsAndPositions(null, null, DocsAndPositionsEnum.FLAG_OFFSETS);
|
DocsAndPositionsEnum docPosEnum = it.docsAndPositions(null, null, DocsAndPositionsEnum.FLAG_OFFSETS);
|
||||||
docPosEnum.nextDoc();
|
docPosEnum.nextDoc();
|
||||||
|
|
|
@ -165,6 +165,33 @@ public class BlendedInfixSuggesterTest extends LuceneTestCase {
|
||||||
suggester.close();
|
suggester.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle trailing spaces that result in no prefix token LUCENE-6093
|
||||||
|
*/
|
||||||
|
public void testNullPrefixToken() throws IOException {
|
||||||
|
|
||||||
|
BytesRef payload = new BytesRef("lake");
|
||||||
|
|
||||||
|
Input keys[] = new Input[]{
|
||||||
|
new Input("top of the lake", 8, payload)
|
||||||
|
};
|
||||||
|
|
||||||
|
Path tempDir = createTempDir("BlendedInfixSuggesterTest");
|
||||||
|
|
||||||
|
Analyzer a = new StandardAnalyzer(CharArraySet.EMPTY_SET);
|
||||||
|
BlendedInfixSuggester suggester = new BlendedInfixSuggester(newFSDirectory(tempDir), a, a,
|
||||||
|
AnalyzingInfixSuggester.DEFAULT_MIN_PREFIX_CHARS,
|
||||||
|
BlendedInfixSuggester.BlenderType.POSITION_LINEAR,
|
||||||
|
BlendedInfixSuggester.DEFAULT_NUM_FACTOR, false);
|
||||||
|
suggester.build(new InputArrayIterator(keys));
|
||||||
|
|
||||||
|
getInResults(suggester, "of ", payload, 1);
|
||||||
|
getInResults(suggester, "the ", payload, 1);
|
||||||
|
getInResults(suggester, "lake ", payload, 1);
|
||||||
|
|
||||||
|
suggester.close();
|
||||||
|
}
|
||||||
|
|
||||||
public void /*testT*/rying() throws IOException {
|
public void /*testT*/rying() throws IOException {
|
||||||
|
|
||||||
BytesRef lake = new BytesRef("lake");
|
BytesRef lake = new BytesRef("lake");
|
||||||
|
|
Loading…
Reference in New Issue