2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017 AT&T Intellectual Property.
6 * Copyright © 2017 Amdocs
8 * ================================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License ati
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=========================================================
22 * ECOMP and OpenECOMP are trademarks
23 * and service marks of AT&T Intellectual Property.
25 package org.openecomp.sa.searchdbabstraction.searchapi;
27 import com.fasterxml.jackson.annotation.JsonProperty;
30 * This class represents a simple parsed query statement.
32 * <p>A 'parsed query' specifies a document field to inspect and a query
33 * string which will be parsed by the document store to generate the
34 * exact query to be performed.
36 * <p>The query string will be tokenized into 'terms' and 'operators' where:
38 * <p>Terms may be any of the following:
40 * <li> single words </li>
41 * <li> exact phrases (denoted by surrounding the phrase with '"' characters) </li>
42 * <li> regular expressions (denoted by surrounding the phrase with '/' characters) </li>
45 * <p>Operators may be any of the following:
47 * <li> + -- The term to the right of the operator MUST be present to produce a match. </li>
48 * <li> - -- The term to the right of the operator MUST NOT be present to produce a match. </li>
49 * <li> AND -- Both the terms to the left and right of the operator MUST be present to produce a match. </li>
50 * <li> OR -- Either the term to the left or right of the operator MUST be present to produce a match. </li>
51 * <li> NOT -- The term to the right of the operator MUST NOT be present to produce a match. </li>
54 * <p>The expected JSON structure for a parsed query is as follows:
58 * "field": "fieldname",
59 * "query-string": "string"
64 public class ParsedQuery {
67 * The name of the field which the query is to be applied to.
72 * The string to be parsed to generate the full query.
74 @JsonProperty("query-string")
75 private String queryString;
78 public String getField() {
82 public void setField(String field) {
86 public String getQueryString() {
90 public void setQueryString(String queryString) {
91 this.queryString = queryString;
96 * This method returns a string which represents this query in syntax
97 * that is understandable by ElasticSearch and is suitable for inclusion
98 * 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 + "'}";