/* 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;

/** Query matching an ordered list of terms.
 *
 * PhraseQuery is a subclass of [](cfish:Query) for matching
 * against an ordered sequence of terms.
 */

public class Lucy::Search::PhraseQuery inherits Lucy::Search::Query {

    String        *field;
    Vector        *terms;

    /** Create a new PhraseQuery.
     *
     * @param field The field that the phrase must occur in.
     * @param terms The ordered array of terms that must match.
     */
    public inert incremented PhraseQuery*
    new(String *field, Vector *terms);

    /** Initialize a PhraseQuery.
     *
     * @param field The field that the phrase must occur in.
     * @param terms The ordered array of terms that must match.
     */
    public inert PhraseQuery*
    init(PhraseQuery *self, String *field, Vector *terms);

    /** Accessor for object's field attribute.
     */
    public String*
    Get_Field(PhraseQuery *self);

    /** Accessor for object's array of terms.
     */
    public Vector*
    Get_Terms(PhraseQuery *self);

    public incremented Compiler*
    Make_Compiler(PhraseQuery *self, Searcher *searcher, float boost,
                  bool subordinate = false);

    public bool
    Equals(PhraseQuery *self, Obj *other);

    public incremented String*
    To_String(PhraseQuery *self);

    void
    Serialize(PhraseQuery *self, OutStream *outstream);

    incremented PhraseQuery*
    Deserialize(decremented PhraseQuery *self, InStream *instream);

    public incremented Obj*
    Dump(PhraseQuery *self);

    public incremented Obj*
    Load(PhraseQuery *self, Obj *dump);

    public void
    Destroy(PhraseQuery *self);
}

class Lucy::Search::PhraseCompiler
    inherits Lucy::Search::Compiler {

    float idf;
    float raw_weight;
    float query_norm_factor;
    float normalized_weight;

    inert incremented PhraseCompiler*
    new(PhraseQuery *parent, Searcher *searcher, float boost);

    inert PhraseCompiler*
    init(PhraseCompiler *self, PhraseQuery *parent, Searcher *searcher,
         float boost);

    public incremented nullable Matcher*
    Make_Matcher(PhraseCompiler *self, SegReader *reader, bool need_score);

    public float
    Get_Weight(PhraseCompiler *self);

    public float
    Sum_Of_Squared_Weights(PhraseCompiler *self);

    public void
    Apply_Norm_Factor(PhraseCompiler *self, float factor);

    incremented Vector*
    Highlight_Spans(PhraseCompiler *self, Searcher *searcher,
                    DocVector *doc_vec, String *field);

    public bool
    Equals(PhraseCompiler *self, Obj *other);

    void
    Serialize(PhraseCompiler *self, OutStream *outstream);

    incremented PhraseCompiler*
    Deserialize(decremented PhraseCompiler *self, InStream *instream);
}