Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 505737
Collapse All | Expand All

(-)a/bundles/org.eclipse.orion.server.search/src/org/eclipse/orion/internal/server/search/FileGrepper.java (-6 / +11 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2014, 2015 IBM Corporation and others.
2
 * Copyright (c) 2014, 2016 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 195-200 Link Here
195
	 */
195
	 */
196
	public List<SearchResult> search(SearchOptions options) throws SearchException {
196
	public List<SearchResult> search(SearchOptions options) throws SearchException {
197
		List<SearchResult> files = new LinkedList<SearchResult>();
197
		List<SearchResult> files = new LinkedList<SearchResult>();
198
		if(!options.isFileContentsSearch() && options.getFilenamePattern() == null) {
199
			return files;
200
		}
198
		try {
201
		try {
199
			for (SearchScope scope : options.getScopes()) {
202
			for (SearchScope scope : options.getScopes()) {
200
				currentWorkspace = scope.getWorkspace();
203
				currentWorkspace = scope.getWorkspace();
Lines 252-262 Link Here
252
	 * @return the correct search term.
255
	 * @return the correct search term.
253
	 */
256
	 */
254
	private String undoLuceneEscape(String searchTerm) {
257
	private String undoLuceneEscape(String searchTerm) {
255
		String specialChars = "+-&|!(){}[]^\"~:\\";
258
		if(searchTerm != null) {
256
		for (int i = 0; i < specialChars.length(); i++) {
259
			String specialChars = "+-&|!(){}[]^\"~:\\";
257
			String character = specialChars.substring(i, i + 1);
260
			for (int i = 0; i < specialChars.length(); i++) {
258
			String escaped = "\\" + character;
261
				String character = specialChars.substring(i, i + 1);
259
			searchTerm = searchTerm.replaceAll(Pattern.quote(escaped), character);
262
				String escaped = "\\" + character;
263
				searchTerm = searchTerm.replaceAll(Pattern.quote(escaped), character);
264
			}
260
		}
265
		}
261
		return searchTerm;
266
		return searchTerm;
262
	}
267
	}
(-)a/bundles/org.eclipse.orion.server.search/src/org/eclipse/orion/internal/server/search/SearchServlet.java (-4 / +10 lines)
Lines 130-135 Link Here
130
							}
130
							}
131
						}
131
						}
132
					}
132
					}
133
				} else if(term.indexOf(":") > -1) {
134
					//unknown search term, ignore
135
					continue;
133
				} else {
136
				} else {
134
					//decode the term string now
137
					//decode the term string now
135
					try {
138
					try {
Lines 162-174 Link Here
162
		JSONObject resultsJSON = new JSONObject();
165
		JSONObject resultsJSON = new JSONObject();
163
		JSONObject responseJSON = new JSONObject();
166
		JSONObject responseJSON = new JSONObject();
164
		try {
167
		try {
165
			resultsJSON.put("numFound", files.size());
166
			resultsJSON.put("start", 0);
168
			resultsJSON.put("start", 0);
167
168
			JSONArray docs = new JSONArray();
169
			JSONArray docs = new JSONArray();
169
			for (SearchResult file : files) {
170
			int found = 0;
170
				docs.put(file.toJSON(contextPath));
171
			if(files != null) {
172
				found = files.size();
173
				for (SearchResult file : files) {
174
					docs.put(file.toJSON(contextPath));
175
				}
171
			}
176
			}
177
			resultsJSON.put("numFound", found);
172
			resultsJSON.put("docs", docs);
178
			resultsJSON.put("docs", docs);
173
			// Add to parent JSON
179
			// Add to parent JSON
174
			JSONObject responseHeader = new JSONObject();
180
			JSONObject responseHeader = new JSONObject();
(-)a/tests/org.eclipse.orion.server.tests/src/org/eclipse/orion/server/tests/search/SearchTest.java (-1 / +44 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2012, 2015 IBM Corporation and others.
2
 * Copyright (c) 2012, 2016 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 35-40 Link Here
35
import org.json.JSONArray;
35
import org.json.JSONArray;
36
import org.json.JSONException;
36
import org.json.JSONException;
37
import org.json.JSONObject;
37
import org.json.JSONObject;
38
import org.junit.Assert;
38
import org.junit.Before;
39
import org.junit.Before;
39
import org.junit.BeforeClass;
40
import org.junit.BeforeClass;
40
import org.junit.Test;
41
import org.junit.Test;
Lines 155-160 Link Here
155
	}
156
	}
156
157
157
	/**
158
	/**
159
	 * @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=505737
160
	 * @throws Exception
161
	 */
162
	@Test
163
	public void testUnknownTerm() throws Exception {
164
		try {
165
			JSONObject result = doSearch("Unknown:'hello'");
166
			assertNoMatch(result);
167
		} catch(NullPointerException npe) {
168
			Assert.fail("No NPE should have been thrown");
169
		}
170
	}
171
	
172
	/**
173
	 * @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=505737
174
	 * @throws Exception
175
	 */
176
	@Test
177
	public void testUnknownTermMixedTail() throws Exception {
178
		try {
179
			JSONObject result = doSearch("Name:'Foo'+NameLower:'foo'+Unknown:'hello'");
180
			assertNoMatch(result);
181
		} catch(NullPointerException npe) {
182
			Assert.fail("No NPE should have been thrown");
183
		}
184
	}
185
	
186
	/**
187
	 * @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=505737
188
	 * @throws Exception
189
	 */
190
	@Test
191
	public void testUnknownTermMixedMid() throws Exception {
192
		try {
193
			JSONObject result = doSearch("Name:'Foo'+Unknown:'hello'+NameLower:'foo'");
194
			assertNoMatch(result);
195
		} catch(NullPointerException npe) {
196
			Assert.fail("No NPE should have been thrown");
197
		}
198
	}
199
	
200
	/**
158
	 * Tests finding search results on a part of a word.
201
	 * Tests finding search results on a part of a word.
159
	 */
202
	 */
160
	@Test
203
	@Test

Return to bug 505737