summaryrefslogtreecommitdiffstats
path: root/container-search/src/main/java/com/yahoo/search/query/parser/ParserFactory.java
diff options
context:
space:
mode:
Diffstat (limited to 'container-search/src/main/java/com/yahoo/search/query/parser/ParserFactory.java')
-rw-r--r--container-search/src/main/java/com/yahoo/search/query/parser/ParserFactory.java48
1 files changed, 48 insertions, 0 deletions
diff --git a/container-search/src/main/java/com/yahoo/search/query/parser/ParserFactory.java b/container-search/src/main/java/com/yahoo/search/query/parser/ParserFactory.java
new file mode 100644
index 00000000000..e0a3338fec2
--- /dev/null
+++ b/container-search/src/main/java/com/yahoo/search/query/parser/ParserFactory.java
@@ -0,0 +1,48 @@
+// Copyright 2016 Yahoo Inc. 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.yql.YqlParser;
+
+/**
+ * <p>Implements a factory for {@link Parser}.</p>
+ *
+ * @author <a href="mailto:simon@yahoo-inc.com">Simon Thoresen</a>
+ * @since 5.1.4
+ */
+public final class ParserFactory {
+
+ private ParserFactory() {
+ // hide
+ }
+
+ /**
+ * Creates a {@link Parser} appropriate for the given <tt>Query.Type</tt>, 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
+ */
+ public static Parser newInstance(Query.Type type, ParserEnvironment environment) {
+ switch (type) {
+ case ALL:
+ return new AllParser(environment);
+ 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);
+ default:
+ throw new UnsupportedOperationException(type.toString());
+ }
+ }
+}