1 package com.liferay.portal.kernel.search;
3 import com.liferay.portal.kernel.util.StringPool;
5 public class SolrQueryUtil {
7 public static final String AND = "AND";
9 public static final String OR = "OR";
12 * Build a value query from a string
13 * Fuzzy search is an approximative search which is costly (performance killer) before SOLR 4.0 (example => keyword : bol, results : bol, bal, bob, sol...)
14 * @param keywords string that contains a list of keywords separated with spaces
15 * @param fuzzySearch boolean which activate fuzzysearch
16 * @return a query with the keywords
18 public static final String getQueryFromKeywords(String keywords, boolean fuzzySearch) {
20 StringBuilder query = new StringBuilder("");
22 if(!keywords.isEmpty()){
24 String[] words = keywords.split(" ");
27 for(int i = 0 ; i < words.length ; ++i){
28 String word = words[i];
30 query.append("(" + word + StringPool.STAR);
32 query.append(" " + SolrQueryUtil.OR + " ");
34 query.append(word + StringPool.TILDE + "0.8");
35 query.append(" " + SolrQueryUtil.OR + " ");
38 query.append(word + ")");
40 if (i < (words.length - 1)) {
41 query.append(" " + SolrQueryUtil.AND + " ");
48 return query.toString();