Class PhraseQuery.Builder

  • Enclosing class:
    PhraseQuery

    public static class PhraseQuery.Builder
    extends java.lang.Object
    A builder for phrase queries.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.List<java.lang.Integer> positions  
      private int slop  
      private java.util.List<Term> terms  
    • Constructor Summary

      Constructors 
      Constructor Description
      Builder()
      Sole constructor.
    • Field Detail

      • slop

        private int slop
      • terms

        private final java.util.List<Term> terms
      • positions

        private final java.util.List<java.lang.Integer> positions
    • Constructor Detail

      • Builder

        public Builder()
        Sole constructor.
    • Method Detail

      • add

        public PhraseQuery.Builder add​(Term term)
        Adds a term to the end of the query phrase. The relative position of the term is the one immediately after the last term added.
      • add

        public PhraseQuery.Builder add​(Term term,
                                       int position)
        Adds a term to the end of the query phrase. The relative position of the term within the phrase is specified explicitly, but must be greater than or equal to that of the previously added term. A greater position allows phrases with gaps (e.g. in connection with stopwords). If the position is equal, you most likely should be using MultiPhraseQuery instead which only requires one term at each position to match; this class requires all of them.
      • build

        public PhraseQuery build()
        Build a phrase query based on the terms that have been added.