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.
28 * <p>A 'parsed query' specifies a document field to inspect and a query
29 * string which will be parsed by the document store to generate the
30 * exact query to be performed.
32 * <p>The query string will be tokenized into 'terms' and 'operators' where:
34 * <p>Terms may be any of the following:
36 * <li> single words </li>
37 * <li> exact phrases (denoted by surrounding the phrase with '"' characters) </li>
38 * <li> regular expressions (denoted by surrounding the phrase with '/' characters) </li>
41 * <p>Operators may be any of the following:
43 * <li> + -- The term to the right of the operator MUST be present to produce a match. </li>
44 * <li> - -- The term to the right of the operator MUST NOT be present to produce a match. </li>
45 * <li> AND -- Both the terms to the left and right of the operator MUST be present to produce a match. </li>
46 * <li> OR -- Either the term to the left or right of the operator MUST be present to produce a match. </li>
47 * <li> NOT -- The term to the right of the operator MUST NOT be present to produce a match. </li>
50 * <p>The expected JSON structure for a parsed query is as follows:
54 * "field": "fieldname",
55 * "query-string": "string"
60 public class ParsedQuery {
63 * The name of the field which the query is to be applied to.
68 * The string to be parsed to generate the full query.
70 @JsonProperty("query-string")
71 private String queryString;
74 public String getField() {
78 public void setField(String field) {
82 public String getQueryString() {
86 public void setQueryString(String queryString) {
87 this.queryString = queryString;
92 * This method returns a string which represents this query in syntax
93 * that is understandable by ElasticSearch and is suitable for inclusion
94 * in an ElasticSearch query string.
96 * @return - ElasticSearch syntax string.
98 public String toElasticSearch() {
100 StringBuilder sb = new StringBuilder();
103 sb.append("\"query_string\": {");
104 sb.append("\"default_field\": \"").append(field).append("\", ");
105 sb.append("\"query\": \"").append(queryString).append("\"");
109 return sb.toString();
113 public String toString() {
114 return "{field:" + field + ", query-string: '" + queryString + "'}";