aboutsummaryrefslogtreecommitdiffstats
path: root/container-search/src/main/java/com/yahoo/search/query/parser/ParserFactory.java
blob: feabf7f76f1081e49553afdd3216572c33e9b954 (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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.search.query.parser;

import com.yahoo.prelude.query.parser.*;
import com.yahoo.search.Query;
import com.yahoo.search.query.SelectParser;
import com.yahoo.search.yql.YqlParser;

/**
 * Implements a factory for {@link Parser}.
 *
 * @author Simon Thoresen Hult
 */
public final class ParserFactory {

    private ParserFactory() {
        // hide
    }

    /**
     * Creates a {@link Parser} appropriate for the given <code>Query.Type</code>, providing the Parser with access to
     * the {@link ParserEnvironment} given.
     *
     * @param type        the query type for which to create a Parser
     * @param environment the environment settings to attach to the Parser
     * @return the created Parser
     */
    @SuppressWarnings("deprecation")
    public static Parser newInstance(Query.Type type, ParserEnvironment environment) {
        switch (type) {
            case ALL:
                return new AllParser(environment, false);
            case ANY:
                return new AnyParser(environment);
            case PHRASE:
                return new PhraseParser(environment);
            case ADVANCED:
                return new AdvancedParser(environment);
            case WEB:
                return new WebParser(environment);
            case PROGRAMMATIC:
                return new ProgrammaticParser();
            case YQL:
                return new YqlParser(environment);
            case SELECT:
                return new SelectParser(environment);
            case WEAKAND:
                return new AllParser(environment, true);
            case TOKENIZE:
                return new TokenizeParser(environment);
            default:
                throw new UnsupportedOperationException(type.toString());
        }
    }

}