aboutsummaryrefslogtreecommitdiffstats
path: root/container-search/src/main/java/com/yahoo/prelude/semantics/rule/CompositeItemCondition.java
blob: 3f20229799daf836489c29a2138f380fe0639d9e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.prelude.semantics.rule;

import com.yahoo.prelude.query.PhraseItem;
import com.yahoo.prelude.semantics.engine.Choicepoint;
import com.yahoo.prelude.semantics.engine.RuleEvaluation;

/**
 * A condition on the presense of a particular kind of composite item (possibly also with a particular content)
 *
 * @author bratseth
 * @since 5.1.15
 */
public class CompositeItemCondition extends CompositeCondition {

    @Override
    protected boolean doesMatch(RuleEvaluation e) {
        Choicepoint choicepoint = e.getChoicepoint(this,true);
        choicepoint.updateState();
        boolean matches = e.currentItem().getItem().getParent() instanceof PhraseItem
                          && allSubConditionsMatches(e);
        if ( ! matches)
            choicepoint.backtrack();
        return matches;

    }

    @Override
    protected String toInnerString() {
        if (getLabel()!=null)
            return getLabel() + ":(" + toInnerStringBody() + ")";
        else if (useParentheses())
            return "(" + toInnerStringBody() + ")";
        else
            return toInnerStringBody();
    }

    private String toInnerStringBody() {
        return "\"" + conditionsToString(" ") + "\"";
    }

}