2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * Copyright © 2017-2018 Amdocs
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
21 package org.onap.aai.sa.searchdbabstraction.searchapi;
23 import com.fasterxml.jackson.annotation.JsonProperty;
26 * This class represents a simple parsed query statement.
29 * A 'parsed query' specifies a document field to inspect and a query string which will be parsed by the document store
30 * to generate the exact query to be performed.
33 * The query string will be tokenized into 'terms' and 'operators' where:
36 * Terms may be any of the following:
38 * <li>single words</li>
39 * <li>exact phrases (denoted by surrounding the phrase with '"' characters)</li>
40 * <li>regular expressions (denoted by surrounding the phrase with '/' characters)</li>
44 * Operators may be any of the following:
46 * <li>+ -- The term to the right of the operator MUST be present to produce a match.</li>
47 * <li>- -- The term to the right of the operator MUST NOT be present to produce a match.</li>
48 * <li>AND -- Both the terms to the left and right of the operator MUST be present to produce a match.</li>
49 * <li>OR -- Either the term to the left or right of the operator MUST be present to produce a match.</li>
50 * <li>NOT -- The term to the right of the operator MUST NOT be present to produce a match.</li>
54 * The expected JSON structure for a parsed query is as follows:
59 * "field": "fieldname",
60 * "query-string": "string"
65 public class ParsedQuery {
68 * The name of the field which the query is to be applied to.
73 * The string to be parsed to generate the full query.
75 @JsonProperty("query-string")
76 private String queryString;
79 public String getField() {
83 public void setField(String field) {
87 public String getQueryString() {
91 public void setQueryString(String queryString) {
92 this.queryString = queryString;
97 * This method returns a string which represents this query in syntax that is understandable by ElasticSearch and is
98 * suitable for inclusion in an ElasticSearch query string.
100 * @return - ElasticSearch syntax string.
102 public String toElasticSearch() {
104 StringBuilder sb = new StringBuilder();
107 sb.append("\"query_string\": {");
108 sb.append("\"default_field\": \"").append(field).append("\", ");
109 sb.append("\"query\": \"").append(queryString).append("\"");
113 return sb.toString();
117 public String toString() {
118 return "{field:" + field + ", query-string: '" + queryString + "'}";