root/trunk/grails-app/controllers/SearchableController.groovy @ 1430

Revision 1430, 1.6 KB (checked in by work@…, 3 years ago)

- set keyword expansion

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