當前位置: 首頁>>代碼示例>>Java>>正文


Java QueryParser.escape方法代碼示例

本文整理匯總了Java中org.apache.lucene.queryParser.QueryParser.escape方法的典型用法代碼示例。如果您正苦於以下問題:Java QueryParser.escape方法的具體用法?Java QueryParser.escape怎麽用?Java QueryParser.escape使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.lucene.queryParser.QueryParser的用法示例。


在下文中一共展示了QueryParser.escape方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: escapeKeywords

import org.apache.lucene.queryParser.QueryParser; //導入方法依賴的package包/類
protected String escapeKeywords(String keywords) {
    keywords = keywords.trim();
    if (keywords.isEmpty()) {
        return keywords;
    }

    if (keywords.charAt(0) == '*') {
        if (keywords.length() == 1) {
            return "";
        } else {
            keywords = keywords.substring(1).trim();
        }
    }

    keywords = QueryParser.escape(keywords);

    return keywords;
}
 
開發者ID:Glamdring,項目名稱:welshare,代碼行數:19,代碼來源:BaseDao.java

示例2: search

import org.apache.lucene.queryParser.QueryParser; //導入方法依賴的package包/類
public List<Document> search (String queryString, SearchScope luceneFields) throws Exception {
    // using stop analyzer in search
    Analyzer analyzer = new StopAnalyzer(Version.LUCENE_30,  new File(ApplicationConstants.STOP_WORD_FILE));
    
    String[] fields = getSupportedFileds(luceneFields);
    
    MultiFieldQueryParser parser = new MultiFieldQueryParser(Version.LUCENE_30, fields, analyzer);
    
    // scpaing special characters
    queryString = QueryParser.escape(queryString);
    
    Query query = parser.parse(queryString);
    TopDocs topDocs = searcher.search(query, MAX_RESULT);

    List<Document> documents = new ArrayList<Document>();
    for(ScoreDoc scoreDocs: topDocs.scoreDocs) {
        Document document = searcher.doc(scoreDocs.doc);
        documents.add(document);
    }
    
    return documents;
}
 
開發者ID:CoEIA,項目名稱:DEM,代碼行數:23,代碼來源:LuceneSearcher.java

示例3: search

import org.apache.lucene.queryParser.QueryParser; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
@Transactional(readOnly = true)
public Page<Article> search(String keyword, Pageable pageable) {
	if (StringUtils.isEmpty(keyword)) {
		return new Page<Article>();
	}
	if (pageable == null) {
		pageable = new Pageable();
	}
	try {
		String text = QueryParser.escape(keyword);
		QueryParser titleParser = new QueryParser(Version.LUCENE_35, "title", new IKAnalyzer());
		titleParser.setDefaultOperator(QueryParser.AND_OPERATOR);
		Query titleQuery = titleParser.parse(text);
		FuzzyQuery titleFuzzyQuery = new FuzzyQuery(new Term("title", text), FUZZY_QUERY_MINIMUM_SIMILARITY);
		Query contentQuery = new TermQuery(new Term("content", text));
		Query isPublicationQuery = new TermQuery(new Term("isPublication", "true"));
		BooleanQuery textQuery = new BooleanQuery();
		BooleanQuery query = new BooleanQuery();
		textQuery.add(titleQuery, Occur.SHOULD);
		textQuery.add(titleFuzzyQuery, Occur.SHOULD);
		textQuery.add(contentQuery, Occur.SHOULD);
		query.add(isPublicationQuery, Occur.MUST);
		query.add(textQuery, Occur.MUST);
		FullTextEntityManager fullTextEntityManager = Search.getFullTextEntityManager(entityManager);
		FullTextQuery fullTextQuery = fullTextEntityManager.createFullTextQuery(query, Article.class);
		fullTextQuery.setSort(new Sort(new SortField[] { new SortField("isTop", SortField.STRING, true), new SortField(null, SortField.SCORE), new SortField("createDate", SortField.LONG, true) }));
		fullTextQuery.setFirstResult((pageable.getPageNumber() - 1) * pageable.getPageSize());
		fullTextQuery.setMaxResults(pageable.getPageSize());
		return new Page<Article>(fullTextQuery.getResultList(), fullTextQuery.getResultSize(), pageable);
	} catch (ParseException e) {
		e.printStackTrace();
	}
	return new Page<Article>();
}
 
開發者ID:justinbaby,項目名稱:my-paper,代碼行數:36,代碼來源:SearchServiceImpl.java

示例4: escapeSearchString

import org.apache.lucene.queryParser.QueryParser; //導入方法依賴的package包/類
public String escapeSearchString() {
	// Anführungszeichen und * nicht escapen!!!
	this.wildcardQuery = this.searchString.contains("*") || this.searchString.contains("?");
	String escapedString = QueryParser.escape(this.searchString);
	escapedString = escapedString.replaceAll("\\\\([\"*?])", "$1");
	System.out.println("\nresulting query string: "+escapedString);
	return escapedString;
}
 
開發者ID:cplutte,項目名稱:bts,代碼行數:9,代碼來源:BTSQueryRequest.java

示例5: getQueryForContext

import org.apache.lucene.queryParser.QueryParser; //導入方法依賴的package包/類
public Query getQueryForContext(Text context) throws ParseException {
	LOG.debug("[getQueryForContext] - BEGIN");
	Query result;
	QueryParser parser = new QueryParser(Version.LUCENE_36,
		"CONTEXT", this.getLuceneDefaultAnalyzer());
	LOG.debug("Analyzer used here: " + getLuceneDefaultAnalyzer());
	// Escape special characters:
	String queryText = context.getText().replaceAll(
			"[\\+\\-\\|!\\(\\)\\{\\}\\[\\]\\^~\\*\\?\"\\\\:&]", " ");
	queryText = QueryParser.escape(queryText);
	result = parser.parse(queryText);
	LOG.debug("Main query from Classify: " + result);
	LOG.debug("[getQueryForContext] - END");
	return result;
}
 
開發者ID:TellMeFirst,項目名稱:tmfcore,代碼行數:16,代碼來源:LuceneManager.java

示例6: search

import org.apache.lucene.queryParser.QueryParser; //導入方法依賴的package包/類
public TopScoreDocCollector search(String queryString, int lucHits, String fieldName, Analyzer analyzer) {
	queryString = QueryParser.escape(queryString.trim());		
	if(queryString.equalsIgnoreCase("")) 
		return null;
	Query query = null;
	try {
		QueryParser queryParser = new QueryParser(Version.LUCENE_36, fieldName, analyzer);			
		query = queryParser.parse(queryString);
	} catch (ParseException e) {
		e.printStackTrace();
	}						
	return search(query, lucHits);	
}
 
開發者ID:kasooja,項目名稱:cl-esa,代碼行數:14,代碼來源:Searcher.java

示例7: buildAutoCompleteResult

import org.apache.lucene.queryParser.QueryParser; //導入方法依賴的package包/類
private AutoCompleteResult buildAutoCompleteResult(String value, boolean term)
{
	return new AutoCompleteResult(value, QueryParser.escape(value), term);
}
 
開發者ID:equella,項目名稱:Equella,代碼行數:5,代碼來源:AutoCompleteServiceImpl.java

示例8: makeBooleanClause

import org.apache.lucene.queryParser.QueryParser; //導入方法依賴的package包/類
/**
 *  Make a Lucene boolean clause suitable for use with the Lucene QueryParser. <p>
 *
 *  Examples:<p>
 *
 *  input: strings=['car','train station','airplane'], operator=OR, asPhrases=true, escape=false<br/>
 *  output: ("car" OR "train station" OR "airplane")<p>
 *
 *  input: strings=['car','train station','airplane'], operator=AND, asPhrases=false, escape=false<br/>
 *  output: ((car) AND (train station) AND (airplane))
 *
 * @param  strings        One or more Strings
 * @param  operator       The String OR, AND, or NOT
 * @param  asPhrases      True to treat each String as a phrase (e.g. surround in quotes)
 * @param  escape         True to return a String where characters that QueryParser expects to be escaped are
 *      escaped by a preceding \.
 * @return                A boolean clause
 * @exception  Exception  If error
 * @see                   org.apache.lucene.queryParser.QueryParser
 */
public final static String makeBooleanClause(String[] strings, String operator, boolean asPhrases, boolean escape) throws Exception {
	if (operator == null || (!operator.equals("OR") && !operator.equals("AND") && !operator.equals("NOT")))
		throw new Exception("boolean operator must be 'OR' or 'AND' or 'NOT'");

	if (strings == null || strings.length == 0)
		return "";
	String queryClause = "(";
	for (int i = 0; i < strings.length; i++) {
		if (escape)
			queryClause += (asPhrases ? "\"" : "(") + QueryParser.escape(strings[i]) + (asPhrases ? "\"" : ")");
		else
			queryClause += (asPhrases ? "\"" : "(") + strings[i] + (asPhrases ? "\"" : ")");
		if (i < strings.length - 1)
			queryClause += " " + operator + " ";
	}
	queryClause += ")";
	return queryClause;
}
 
開發者ID:NCAR,項目名稱:dls-repository-stack,代碼行數:39,代碼來源:LuceneUtils.java

示例9: escapeQuery

import org.apache.lucene.queryParser.QueryParser; //導入方法依賴的package包/類
public static String escapeQuery( String query ) {
    return QueryParser.escape( query );
}
 
開發者ID:webdsl,項目名稱:webdsl,代碼行數:4,代碼來源:AbstractEntitySearcher.java

示例10: escape

import org.apache.lucene.queryParser.QueryParser; //導入方法依賴的package包/類
public String escape(final String in) {
  return QueryParser.escape(in);
}
 
開發者ID:CoreFiling,項目名稱:reviki,代碼行數:4,代碼來源:LuceneSearcher.java

示例11: escapeStrings

import org.apache.lucene.queryParser.QueryParser; //導入方法依賴的package包/類
private static void escapeStrings(String[] queryStrings) {
	for(int i=0; i<queryStrings.length; i++) {
		queryStrings[i] = QueryParser.escape(queryStrings[i]);
	}
}
 
開發者ID:kasooja,項目名稱:cl-esa,代碼行數:6,代碼來源:Searcher.java


注:本文中的org.apache.lucene.queryParser.QueryParser.escape方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。