2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6 * Copyright © 2017 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 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
23 package org.onap.aai.sa.searchdbabstraction.searchapi;
25 import com.fasterxml.jackson.annotation.JsonProperty;
28 * This class represents a simple parsed query statement.
30 * <p>A 'parsed query' specifies a document field to inspect and a query
31 * string which will be parsed by the document store to generate the
32 * exact query to be performed.
34 * <p>The query string will be tokenized into 'terms' and 'operators' where:
36 * <p>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>
43 * <p>Operators may be any of the following:
45 * <li> + -- The term to the right of the operator MUST be present to produce a match. </li>
46 * <li> - -- The term to the right of the operator MUST NOT be present to produce a match. </li>
47 * <li> AND -- Both the terms to the left and right of the operator MUST be present to produce a match. </li>
48 * <li> OR -- Either the term to the left or right of the operator MUST be present to produce a match. </li>
49 * <li> NOT -- The term to the right of the operator MUST NOT be present to produce a match. </li>
52 * <p>The expected JSON structure for a parsed query is as follows:
56 * "field": "fieldname",
57 * "query-string": "string"
62 public class ParsedQuery {
65 * The name of the field which the query is to be applied to.
70 * The string to be parsed to generate the full query.
72 @JsonProperty("query-string")
73 private String queryString;
76 public String getField() {
80 public void setField(String field) {
84 public String getQueryString() {
88 public void setQueryString(String queryString) {
89 this.queryString = queryString;
94 * This method returns a string which represents this query in syntax
95 * that is understandable by ElasticSearch and is suitable for inclusion
96 * in an ElasticSearch query string.
98 * @return - ElasticSearch syntax string.
100 public String toElasticSearch() {
102 StringBuilder sb = new StringBuilder();
105 sb.append("\"query_string\": {");
106 sb.append("\"default_field\": \"").append(field).append("\", ");
107 sb.append("\"query\": \"").append(queryString).append("\"");
111 return sb.toString();
115 public String toString() {
116 return "{field:" + field + ", query-string: '" + queryString + "'}";