📄 blogsearch.java
字号:
/*
* This library is part of the code for the book: OpenCms for Developers
*
* Copyright (c) 2007, 2008 Dan Liliedahl
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package com.deepthoughts.search;
import java.util.Arrays;
import org.opencms.file.CmsObject;
import org.opencms.search.CmsSearch;
import org.opencms.search.CmsSearchParameters;
/**
* This bean overrides the base CmsSearch implementation to provide search support for
* Blog Content.
*/
public class BlogSearch extends CmsSearch {
/** Constant for the fields we will search */
static final String[] DOC_QRY_FIELDS = new String[] {"blogtext", "category", "title"};
/** The names of our search index files */
static final String OFFLINE_INDEX = "Blogs - Offline";
static final String ONLINE_INDEX = "Blogs - Online";
/**
* Empty constructor for bean usage. We override the base class and initialize with parameters
* needed for Blog searching.
*/
public BlogSearch() {
super();
m_parameters.setMatchesPerPage(4);
m_parameters.setSort(CmsSearchParameters.SORT_DEFAULT);
m_parameters.setFields(Arrays.asList(BlogSearch.DOC_QRY_FIELDS));
m_parameters.setIndex(OFFLINE_INDEX);
}
/**
* Override the init method in order to set the proper search index. We automatically select
* the proper index based on the current project in use.
*/
public void init(CmsObject cms) {
super.init(cms);
// set search index to offline or online based on current user project
if (cms.getRequestContext().currentProject().isOnlineProject()) {
m_parameters.setIndex(ONLINE_INDEX);
} else {
m_parameters.setIndex(OFFLINE_INDEX);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -