Class MultiFields

  • All Implemented Interfaces:
    java.lang.Iterable<java.lang.String>

    public final class MultiFields
    extends Fields
    Exposes flex API, merged from flex API of sub-segments. This is useful when you're interacting with an IndexReader implementation that consists of sequential sub-readers (eg DirectoryReader or MultiReader).

    NOTE: for composite readers, you'll get better performance by gathering the sub readers using IndexReader.getContext() to get the atomic leaves and then operate per-AtomicReader, instead of using this class.

    • Constructor Detail

      • MultiFields

        public MultiFields​(Fields[] subs,
                           ReaderSlice[] subSlices)
        Expert: construct a new MultiFields instance directly.
    • Method Detail

      • getFields

        public static Fields getFields​(IndexReader reader)
                                throws java.io.IOException
        Returns a single Fields instance for this reader, merging fields/terms/docs/positions on the fly. This method will return null if the reader has no postings.

        NOTE: this is a slow way to access postings. It's better to get the sub-readers and iterate through them yourself.

        Throws:
        java.io.IOException
      • getLiveDocs

        public static Bits getLiveDocs​(IndexReader reader)
        Returns a single Bits instance for this reader, merging live Documents on the fly. This method will return null if the reader has no deletions.

        NOTE: this is a very slow way to access live docs. For example, each Bits access will require a binary search. It's better to get the sub-readers and iterate through them yourself.

      • getTerms

        public static Terms getTerms​(IndexReader r,
                                     java.lang.String field)
                              throws java.io.IOException
        This method may return null if the field does not exist.
        Throws:
        java.io.IOException
      • getTermDocsEnum

        public static DocsEnum getTermDocsEnum​(IndexReader r,
                                               Bits liveDocs,
                                               java.lang.String field,
                                               BytesRef term)
                                        throws java.io.IOException
        Returns DocsEnum for the specified field & term. This will return null if the field or term does not exist.
        Throws:
        java.io.IOException
      • getTermDocsEnum

        public static DocsEnum getTermDocsEnum​(IndexReader r,
                                               Bits liveDocs,
                                               java.lang.String field,
                                               BytesRef term,
                                               int flags)
                                        throws java.io.IOException
        Returns DocsEnum for the specified field & term, with control over whether freqs are required. Some codecs may be able to optimize their implementation when freqs are not required. This will return null if the field or term does not exist. See TermsEnum.docs(Bits,DocsEnum,int).
        Throws:
        java.io.IOException
      • getTermPositionsEnum

        public static DocsAndPositionsEnum getTermPositionsEnum​(IndexReader r,
                                                                Bits liveDocs,
                                                                java.lang.String field,
                                                                BytesRef term,
                                                                int flags)
                                                         throws java.io.IOException
        Returns DocsAndPositionsEnum for the specified field & term, with control over whether offsets and payloads are required. Some codecs may be able to optimize their implementation when offsets and/or payloads are not required. This will return null if the field or term does not exist or positions were not indexed. See TermsEnum.docsAndPositions(Bits,DocsAndPositionsEnum,int).
        Throws:
        java.io.IOException
      • iterator

        public java.util.Iterator<java.lang.String> iterator()
        Description copied from class: Fields
        Returns an iterator that will step through all fields names. This will not return null.
        Specified by:
        iterator in interface java.lang.Iterable<java.lang.String>
        Specified by:
        iterator in class Fields
      • terms

        public Terms terms​(java.lang.String field)
                    throws java.io.IOException
        Description copied from class: Fields
        Get the Terms for this field. This will return null if the field does not exist.
        Specified by:
        terms in class Fields
        Throws:
        java.io.IOException
      • size

        public int size()
        Description copied from class: Fields
        Returns the number of fields or -1 if the number of distinct field names is unknown. If >= 0, Fields.iterator() will return as many field names.
        Specified by:
        size in class Fields
      • getMergedFieldInfos

        public static FieldInfos getMergedFieldInfos​(IndexReader reader)
        Call this to get the (merged) FieldInfos for a composite reader.

        NOTE: the returned field numbers will likely not correspond to the actual field numbers in the underlying readers, and codec metadata (FieldInfo.getAttribute(String) will be unavailable.

      • getIndexedFields

        public static java.util.Collection<java.lang.String> getIndexedFields​(IndexReader reader)
        Call this to get the (merged) FieldInfos representing the set of indexed fields only for a composite reader.

        NOTE: the returned field numbers will likely not correspond to the actual field numbers in the underlying readers, and codec metadata (FieldInfo.getAttribute(String) will be unavailable.