1 /*
2 * ModeShape (http://www.modeshape.org)
3 * See the COPYRIGHT.txt file distributed with this work for information
4 * regarding copyright ownership. Some portions may be licensed
5 * to Red Hat, Inc. under one or more contributor license agreements.
6 * See the AUTHORS.txt file in the distribution for a full listing of
7 * individual contributors.
8 *
9 * ModeShape is free software. Unless otherwise indicated, all code in ModeShape
10 * is licensed to you under the terms of the GNU Lesser General Public License as
11 * published by the Free Software Foundation; either version 2.1 of
12 * the License, or (at your option) any later version.
13 *
14 * ModeShape is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this software; if not, write to the Free
21 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
22 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
23 */
24 package org.modeshape.graph.request;
25
26 import java.util.List;
27 import org.modeshape.common.util.CheckArg;
28 import org.modeshape.graph.query.QueryResults.Columns;
29 import org.modeshape.graph.query.QueryResults.Statistics;
30
31 /**
32 * A {@link Request} to perform a full-text search on a graph.
33 */
34 public class FullTextSearchRequest extends SearchRequest {
35
36 private static final long serialVersionUID = 1L;
37
38 private final String expression;
39 private final String workspaceName;
40 private final int maxResults;
41 private final int offset;
42
43 /**
44 * Create a new request to execute the supplied query against the name workspace.
45 *
46 * @param fullTextSearch the full-text search to be performed; may not be null
47 * @param workspace the name of the workspace to be queried
48 * @param maxResults the maximum number of results that are to be returned; always positive
49 * @param offset the number of initial results to skip, or 0 if the first results are to be returned
50 * @throws IllegalArgumentException if the query or workspace name is null, if the maxResults is not positive, or if the
51 * offset is negative
52 */
53 public FullTextSearchRequest( String fullTextSearch,
54 String workspace,
55 int maxResults,
56 int offset ) {
57 CheckArg.isNotEmpty(fullTextSearch, "fullTextSearch");
58 CheckArg.isNotNull(workspace, "workspace");
59 CheckArg.isPositive(maxResults, "maxResults");
60 CheckArg.isNonNegative(offset, "offset");
61 this.expression = fullTextSearch;
62 this.workspaceName = workspace;
63 this.maxResults = maxResults;
64 this.offset = offset;
65 }
66
67 /**
68 * Get the full-text search expression that is to be executed.
69 *
70 * @return the full-text search expression; never null and never empty
71 */
72 public String expression() {
73 return expression;
74 }
75
76 /**
77 * Get the name of the workspace in which the node exists.
78 *
79 * @return the name of the workspace; never null
80 */
81 public String workspace() {
82 return workspaceName;
83 }
84
85 /**
86 * Get the maximum number of results that should be returned.
87 *
88 * @return the maximum number of results that are to be returned; always positive
89 */
90 public int maxResults() {
91 return maxResults;
92 }
93
94 /**
95 * Get the number of initial search results that should be excluded from the {@link #getTuples() tuples} included on this
96 * request.
97 *
98 * @return the number of initial results to skip, or 0 if the first results are to be returned
99 */
100 public int offset() {
101 return offset;
102 }
103
104 /**
105 * {@inheritDoc}
106 *
107 * @see java.lang.Object#hashCode()
108 */
109 @Override
110 public int hashCode() {
111 return expression.hashCode();
112 }
113
114 /**
115 * Get the specification of the columns for the {@link #getTuples() results}.
116 *
117 * @return the column specifications; never null
118 */
119 public Columns getResultColumns() {
120 return super.columns();
121 }
122
123 /**
124 * Set the results for this request.
125 *
126 * @param resultColumns the definition of the result columns
127 * @param tuples the result values
128 * @param statistics the statistics, or null if there are none
129 */
130 public void setResults( Columns resultColumns,
131 List<Object[]> tuples,
132 Statistics statistics ) {
133 super.doSetResults(resultColumns, tuples, statistics);
134 }
135
136 /**
137 * {@inheritDoc}
138 *
139 * @see java.lang.Object#equals(java.lang.Object)
140 */
141 @Override
142 public boolean equals( Object obj ) {
143 if (obj == this) return true;
144 if (this.getClass().isInstance(obj)) {
145 FullTextSearchRequest that = (FullTextSearchRequest)obj;
146 if (!this.expression().equals(that.expression())) return false;
147 if (!this.workspace().equals(that.workspace())) return false;
148 if (this.offset() != that.offset()) return false;
149 if (this.maxResults() != that.maxResults()) return false;
150 return true;
151 }
152 return false;
153 }
154
155 /**
156 * {@inheritDoc}
157 *
158 * @see java.lang.Object#toString()
159 */
160 @Override
161 public String toString() {
162 return "search the \"" + workspaceName + "\" workspace with \"" + expression + "\"";
163 }
164
165 @Override
166 public RequestType getType() {
167 return RequestType.FULL_TEXT_SEARCH;
168 }
169 }