![JAR search and dependency download from the Maven repository](/logo.png)
com.day.cq.commons.servlets.AbstractSearchServlet Maven / Gradle / Ivy
Show all versions of aem-sdk-api Show documentation
/*
* Copyright 1997-2009 Day Management AG
* Barfuesserplatz 6, 4001 Basel, Switzerland
* All Rights Reserved.
*
* This software is the confidential and proprietary information of
* Day Management AG, ("Confidential Information"). You shall not
* disclose such Confidential Information and shall use it only in
* accordance with the terms of the license agreement you entered into
* with Day.
*/
package com.day.cq.commons.servlets;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.StringTokenizer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* AbstractSearchServlet
is a base class for search servlets.
* @deprecated use {@link com.day.cq.commons.predicates.servlets.AbstractSearchServlet} instead
*/
@Deprecated
public abstract class AbstractSearchServlet extends AbstractPredicateServlet {
private final Logger log = LoggerFactory.getLogger(AbstractSearchServlet.class);
private static final long serialVersionUID = 6105423525102347224L;
/** Query clause */
public static final String QUERY = "query";
/** Start index */
public static final String START = "start";
/** Result limit */
public static final String LIMIT = "limit";
/** tidy param */
public static final String TIDY = "tidy";
/**
* List of unicode blocks that contain characters that act as words.
*/
public static final List WORD_CHARS;
/**
* Split terms at these characters. This list might not bee complete and
* is only a quick hack to fix bug# 27080.
*/
public static final String SPLIT_CHARACTERS = " _-.,";
static {
// this list should be kept roughtly synchronized with
// the standard lucene tokenizer!
List list = new ArrayList();
// Chinese and Japanese
list.add(Character.UnicodeBlock.HIRAGANA);
list.add(Character.UnicodeBlock.KATAKANA);
list.add(Character.UnicodeBlock.KATAKANA_PHONETIC_EXTENSIONS);
list.add(Character.UnicodeBlock.BOPOMOFO);
list.add(Character.UnicodeBlock.CJK_COMPATIBILITY);
list.add(Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A);
list.add(Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS);
list.add(Character.UnicodeBlock.CJK_COMPATIBILITY_IDEOGRAPHS);
list.add(Character.UnicodeBlock.SPECIALS);
// Korean
list.add(Character.UnicodeBlock.HANGUL_SYLLABLES);
list.add(Character.UnicodeBlock.HANGUL_JAMO);
WORD_CHARS = Collections.unmodifiableList(list);
}
/**
* @param text the text to check.
* @return true
if text
is a single word;
* false
otherwise.
* @deprecated
*/
@Deprecated
protected boolean isSingleWord(String text) {
log.warn("AbstractSearchServlet.isSingleWord method has been deprecated. Please use com.day.cq.commons.predicates.servlets.AbstractSearchServlet.isSingleWord instead.");
for (int i = 0; i < text.length(); i++) {
if (WORD_CHARS.contains(Character.UnicodeBlock.of(text.charAt(i)))) {
return false;
}
}
return true;
}
/**
* Conditionally appends a wildcard to the query text
if the
* text is not considered a single word. This method also breaks
* the text into multiple terms as {@link #SPLIT_CHARACTERS}. The wildcard
* is only added to the last term.
*
* See also: {@link #isSingleWord(String)}.
*
* @param text the query text.
* @return the processed query text, possibly with appended '*' wildcard.
* @deprecated
*/
@Deprecated
protected String applyWildcard(String text) {
log.warn("AbstractSearchServlet.applyWildcard method has been deprecated. Please use com.day.cq.commons.predicates.servlets.AbstractSearchServlet.applyWildcard instead.");
// only append * if query string is a single word
if (!isSingleWord(text)) {
return text;
}
StringBuffer modified = new StringBuffer();
StringTokenizer t = new StringTokenizer(text, SPLIT_CHARACTERS);
String space = "";
while (t.hasMoreTokens()) {
modified.append(space);
space = " ";
modified.append(t.nextToken());
}
modified.append("*");
return modified.toString();
}
}