当前位置: 首页>>代码示例>>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;未经允许,请勿转载。