source: trunk/grails-app/controllers/SearchableController.groovy @ 193

Last change on this file since 193 was 193, checked in by ademcan, 10 years ago

the Searchable controller for querying

File size: 1.6 KB
Line 
1
2/*
3 * Copyright 2007 the original author or authors.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 *      http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18import org.compass.core.engine.SearchEngineQueryParseException
19
20/**
21 * Basic web interface for Grails Searchable Plugin
22 *
23 * @author Maurice Nicholson
24 */
25class SearchableController {
26    def searchableService
27
28    def selectsample = {
29
30    }
31    /**
32     * Index page with search form and results
33     */
34    def index = {
35        if (!params.q?.trim()) {
36            return [:]
37        }
38        try {
39            return [searchResult: searchableService.search(params.q, params)]
40        } catch (SearchEngineQueryParseException ex) {
41            return [parseException: true]
42        }
43    }
44
45    /**
46     * Perform a bulk index of every searchable object in the database
47     */
48    def indexAll = {
49        Thread.start {
50            searchableService.index()
51        }
52        render("bulk index started in a background thread")
53    }
54
55    /**
56     * Perform a bulk index of every searchable object in the database
57     */
58    def unindexAll = {
59        searchableService.unindex()
60        render("unindexAll done")
61    }
62}
Note: See TracBrowser for help on using the repository browser.