69cddb0a4f548510cbb188293091de276fe8b81e
[aai/search-data-service.git] / src / main / java / org / onap / aai / sa / searchdbabstraction / searchapi / SuggestionStatement.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
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
11  *
12  *       http://www.apache.org/licenses/LICENSE-2.0
13  *
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=========================================================
20  */
21 package org.onap.aai.sa.searchdbabstraction.searchapi;
22
23 import org.radeox.util.logging.Logger;
24
25 import com.fasterxml.jackson.annotation.JsonProperty;
26
27 /**
28  * This class represents the structure of a search statement.
29  *
30  * <p>
31  * The expected JSON structure to represent a Completion suggest search statement is as follows:
32  *
33  * { "suggest-vnf" : { "text" : "VNFs", "completion" : { "field" : "entity_suggest", "size": 1 } } }
34  */
35 public class SuggestionStatement {
36
37     @JsonProperty("results-size")
38     private Integer size;
39
40     @JsonProperty("suggest-field")
41     private String field;
42
43     @JsonProperty("suggest-text")
44     private String text;
45
46     public Integer getSize() {
47         return size;
48     }
49
50     public void setSize(Integer size) {
51         this.size = size;
52     }
53
54     public String getField() {
55         return field;
56     }
57
58     public void setField(String field) {
59         this.field = field;
60     }
61
62     public String getText() {
63         return text;
64     }
65
66     public void setText(String text) {
67         this.text = text;
68     }
69
70     /**
71      * This method returns a string which represents this statement in syntax that is understandable
72      * by ElasticSearch and is suitable for inclusion in an ElasticSearch query string.
73      *
74      * @return - ElasticSearch syntax string.
75      */
76     public String toElasticSearch() {
77
78         StringBuilder sb = new StringBuilder();
79
80         sb.append("{");
81         sb.append("\"suggest-vnf\": {");
82         sb.append("\"text\": ").append("\"" + text + "\"").append(", ");
83         sb.append("\"completion\": {");
84         sb.append("\"field\": ").append("\"" + field + "\"").append(", ");
85         sb.append("\"size\": ").append(size);
86         sb.append("}");
87         sb.append("}");
88         sb.append("}");
89
90         Logger.debug("Generated raw ElasticSearch suggest statement: " + sb.toString());
91         return sb.toString();
92     }
93
94 }