The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.
/* 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.
 */

parcel Lucy;

/** Read Lexicon data.
 *
 * LexiconReader reads term dictionary information.
 */
public abstract class Lucy::Index::LexiconReader nickname LexReader
    inherits Lucy::Index::DataReader {

    inert LexiconReader*
    init(LexiconReader *self, Schema *schema = NULL, Folder *folder = NULL,
        Snapshot *snapshot = NULL, Vector *segments = NULL,
        int32_t seg_tick = -1);

    /** Return a new Lexicon for the given `field`.  Will return
     * [](cfish:@null) if either the field is not indexed, or if no documents
     * contain a value for the field.
     *
     * @param field Field name.
     * @param term Pre-locate the Lexicon to this term.
     */
    public abstract incremented nullable Lexicon*
    Lexicon(LexiconReader *self, String *field, Obj *term = NULL);

    /** Return the number of documents where the specified term is present.
     */
    public abstract uint32_t
    Doc_Freq(LexiconReader *self, String *field, Obj *term);

    /** If the term can be found, return a term info, otherwise return
     * [](cfish:@null).
     */
    abstract incremented nullable TermInfo*
    Fetch_Term_Info(LexiconReader *self, String *field, Obj *term);

    /** Return a LexiconReader which merges the output of other
     * LexiconReaders.
     *
     * @param readers An array of LexiconReaders.
     * @param offsets Doc id start offsets for each reader.
     */
    public incremented nullable LexiconReader*
    Aggregator(LexiconReader *self, Vector *readers, I32Array *offsets);
}

class Lucy::Index::PolyLexiconReader nickname PolyLexReader
    inherits Lucy::Index::LexiconReader {

    Vector   *readers;
    I32Array *offsets;

    inert incremented PolyLexiconReader*
    new(Vector *readers, I32Array *offsets);

    inert PolyLexiconReader*
    init(PolyLexiconReader *self, Vector *readers, I32Array *offsets);

    public incremented nullable Lexicon*
    Lexicon(PolyLexiconReader *self, String *field, Obj *term = NULL);

    public uint32_t
    Doc_Freq(PolyLexiconReader *self, String *field, Obj *term);

    void
    Close(PolyLexiconReader *self);

    public void
    Destroy(PolyLexiconReader *self);
}

class Lucy::Index::DefaultLexiconReader nickname DefLexReader
    inherits Lucy::Index::LexiconReader {

    Vector *lexicons;

    inert incremented DefaultLexiconReader*
    new(Schema *schema, Folder *folder, Snapshot *snapshot, Vector *segments,
        int32_t seg_tick);

    inert DefaultLexiconReader*
    init(DefaultLexiconReader *self, Schema *schema, Folder *folder,
         Snapshot *snapshot, Vector *segments, int32_t seg_tick);

    public incremented nullable Lexicon*
    Lexicon(DefaultLexiconReader *self, String *field,
            Obj *term = NULL);

    /** Return the number of documents in which the term appears.
     */
    public uint32_t
    Doc_Freq(DefaultLexiconReader *self, String *field, Obj *term);

    incremented nullable TermInfo*
    Fetch_Term_Info(DefaultLexiconReader *self, String *field,
                    Obj *term);

    void
    Close(DefaultLexiconReader *self);

    public void
    Destroy(DefaultLexiconReader *self);
}