org.apache.lucene.search.suggest.analyzing
Class BlendedInfixSuggester

java.lang.Object
  extended by org.apache.lucene.search.suggest.Lookup
      extended by org.apache.lucene.search.suggest.analyzing.AnalyzingInfixSuggester
          extended by org.apache.lucene.search.suggest.analyzing.BlendedInfixSuggester
All Implemented Interfaces:
Closeable

public class BlendedInfixSuggester
extends AnalyzingInfixSuggester

Extension of the AnalyzingInfixSuggester which transforms the weight after search to take into account the position of the searched term into the indexed text. Please note that it increases the number of elements searched and applies the ponderation after. It might be costly for long suggestions.


Nested Class Summary
static class BlendedInfixSuggester.BlenderType
          The different types of blender.
 
Nested classes/interfaces inherited from class org.apache.lucene.search.suggest.Lookup
Lookup.LookupPriorityQueue, Lookup.LookupResult
 
Field Summary
static int DEFAULT_NUM_FACTOR
          Default factor
protected static double LINEAR_COEF
          Coefficient used for linear blending
 
Fields inherited from class org.apache.lucene.search.suggest.analyzing.AnalyzingInfixSuggester
DEFAULT_MIN_PREFIX_CHARS, indexAnalyzer, payloadsDV, queryAnalyzer, searcher, TEXT_FIELD_NAME, textDV, weightsDV
 
Fields inherited from class org.apache.lucene.search.suggest.Lookup
CHARSEQUENCE_COMPARATOR
 
Constructor Summary
BlendedInfixSuggester(Version matchVersion, File indexPath, Analyzer analyzer)
          Create a new instance, loading from a previously built directory, if it exists.
BlendedInfixSuggester(Version matchVersion, File indexPath, Analyzer indexAnalyzer, Analyzer queryAnalyzer, int minPrefixChars, BlendedInfixSuggester.BlenderType blenderType, int numFactor)
          Create a new instance, loading from a previously built directory, if it exists.
 
Method Summary
protected  double calculateCoefficient(int position)
          Calculate the weight coefficient based on the position of the first matching word.
protected  List<Lookup.LookupResult> createResults(TopDocs hits, int num, CharSequence key, boolean doHighlight, Set<String> matchedTokens, String prefixToken)
          Create the results based on the search hits.
protected  FieldType getTextFieldType()
          Subclass can override this method to change the field type of the text field e.g.
 List<Lookup.LookupResult> lookup(CharSequence key, boolean onlyMorePopular, int num)
          Look up a key and return possible completion for this key.
 List<Lookup.LookupResult> lookup(CharSequence key, int num, boolean allTermsRequired, boolean doHighlight)
          Retrieve suggestions, specifying whether all terms must match (allTermsRequired) and whether the hits should be highlighted (doHighlight).
 
Methods inherited from class org.apache.lucene.search.suggest.analyzing.AnalyzingInfixSuggester
addNonMatch, addPrefixMatch, addWholeMatch, build, close, finishQuery, getCount, getDirectory, getIndexWriterConfig, getLastTokenQuery, highlight, load, sizeInBytes, store
 
Methods inherited from class org.apache.lucene.search.suggest.Lookup
build, load, store
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LINEAR_COEF

protected static double LINEAR_COEF
Coefficient used for linear blending


DEFAULT_NUM_FACTOR

public static int DEFAULT_NUM_FACTOR
Default factor

Constructor Detail

BlendedInfixSuggester

public BlendedInfixSuggester(Version matchVersion,
                             File indexPath,
                             Analyzer analyzer)
                      throws IOException
Create a new instance, loading from a previously built directory, if it exists.

Throws:
IOException

BlendedInfixSuggester

public BlendedInfixSuggester(Version matchVersion,
                             File indexPath,
                             Analyzer indexAnalyzer,
                             Analyzer queryAnalyzer,
                             int minPrefixChars,
                             BlendedInfixSuggester.BlenderType blenderType,
                             int numFactor)
                      throws IOException
Create a new instance, loading from a previously built directory, if it exists.

Parameters:
blenderType - Type of blending strategy, see BlenderType for more precisions
numFactor - Factor to multiply the number of searched elements before ponderate
Throws:
IOException - If there are problems opening the underlying Lucene index.
Method Detail

lookup

public List<Lookup.LookupResult> lookup(CharSequence key,
                                        boolean onlyMorePopular,
                                        int num)
Description copied from class: Lookup
Look up a key and return possible completion for this key.

Overrides:
lookup in class AnalyzingInfixSuggester
Parameters:
key - lookup key. Depending on the implementation this may be a prefix, misspelling, or even infix.
onlyMorePopular - return only more popular results
num - maximum number of results to return
Returns:
a list of possible completions, with their relative weight (e.g. popularity)

lookup

public List<Lookup.LookupResult> lookup(CharSequence key,
                                        int num,
                                        boolean allTermsRequired,
                                        boolean doHighlight)
Description copied from class: AnalyzingInfixSuggester
Retrieve suggestions, specifying whether all terms must match (allTermsRequired) and whether the hits should be highlighted (doHighlight).

Overrides:
lookup in class AnalyzingInfixSuggester

getTextFieldType

protected FieldType getTextFieldType()
Description copied from class: AnalyzingInfixSuggester
Subclass can override this method to change the field type of the text field e.g. to change the index options

Overrides:
getTextFieldType in class AnalyzingInfixSuggester

createResults

protected List<Lookup.LookupResult> createResults(TopDocs hits,
                                                  int num,
                                                  CharSequence key,
                                                  boolean doHighlight,
                                                  Set<String> matchedTokens,
                                                  String prefixToken)
                                           throws IOException
Description copied from class: AnalyzingInfixSuggester
Create the results based on the search hits. Can be overridden by subclass to add particular behavior (e.g. weight transformation)

Overrides:
createResults in class AnalyzingInfixSuggester
Throws:
IOException - If there are problems reading fields from the underlying Lucene index.

calculateCoefficient

protected double calculateCoefficient(int position)
Calculate the weight coefficient based on the position of the first matching word. Subclass should override it to adapt it to particular needs

Parameters:
position - of the first matching word in text
Returns:
the coefficient


Copyright © 2000-2014 Apache Software Foundation. All Rights Reserved.