org.apache.lucene.queryParser.ParseException类的使用及代码示例

x33g5p2x  于2022-01-26 转载在 其他  
字(9.5k)|赞(0)|评价(0)|浏览(143)

本文整理了Java中org.apache.lucene.queryParser.ParseException类的一些代码示例,展示了ParseException类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ParseException类的具体详情如下:
包路径:org.apache.lucene.queryParser.ParseException
类名称:ParseException

ParseException介绍

[英]This exception is thrown when parse errors are encountered. You can explicitly create objects of this exception type by calling the method generateParseException in the generated parser. You can modify this class to customize your error reporting mechanisms so long as you retain the public fields.
[中]遇到分析错误时会引发此异常。通过在生成的解析器中调用generateParseException方法,可以显式创建这种异常类型的对象。只要保留公共字段,就可以修改此类以自定义错误报告机制。

代码示例

代码示例来源:origin: org.cytoscape/search-impl

@Override
  public void run() {
    JOptionPane.showMessageDialog(null, pe.getMessage(), "Invalid query.", JOptionPane.ERROR_MESSAGE);
  }
});

代码示例来源:origin: org.dspace.dependencies.solr/dspace-solr-core

private void checkRecurse() throws ParseException {
 if (recurseCount++ >= 100) {
  throw new ParseException("Infinite Recursion detected parsing query '" + qstr + "'");
 }
}

代码示例来源:origin: lucene/lucene

break;
retval += add_escapes(tok.image);
tok = tok.next;

代码示例来源:origin: org.apache.lucene/lucene-core-jfrog

/** Parses a query string, returning a {@link org.apache.lucene.search.Query}.
 *  @param query  the query string to be parsed.
 *  @throws ParseException if the parsing fails
 */
public Query parse(String query) throws ParseException {
 ReInit(new FastCharStream(new StringReader(query)));
 try {
  // TopLevelQuery is a Query followed by the end-of-input (EOF)
  Query res = TopLevelQuery(field);
  return res!=null ? res : newBooleanQuery(false);
 }
 catch (ParseException tme) {
  // rethrow to include the original query:
  throw new ParseException("Cannot parse '" +query+ "': " + tme.getMessage());
 }
 catch (TokenMgrError tme) {
  throw new ParseException("Cannot parse '" +query+ "': " + tme.getMessage());
 }
 catch (BooleanQuery.TooManyClauses tmc) {
  throw new ParseException("Cannot parse '" +query+ "': too many boolean clauses");
 }
}

代码示例来源:origin: com.github.monnetproject/clesa

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);	
}

代码示例来源:origin: org.apache.lucene/com.springsource.org.apache.lucene

/** Parses a query string, returning a {@link org.apache.lucene.search.Query}.
 *  @param query  the query string to be parsed.
 *  @throws ParseException if the parsing fails
 */
public Query parse(String query) throws ParseException {
 ReInit(new FastCharStream(new StringReader(query)));
 try {
  // TopLevelQuery is a Query followed by the end-of-input (EOF)
  Query res = TopLevelQuery(field);
  return res!=null ? res : newBooleanQuery(false);
 }
 catch (ParseException tme) {
  // rethrow to include the original query:
  throw new ParseException("Cannot parse '" +query+ "': " + tme.getMessage());
 }
 catch (TokenMgrError tme) {
  throw new ParseException("Cannot parse '" +query+ "': " + tme.getMessage());
 }
 catch (BooleanQuery.TooManyClauses tmc) {
  throw new ParseException("Cannot parse '" +query+ "': too many boolean clauses");
 }
}

代码示例来源:origin: com.github.monnetproject/clesa

public TopScoreDocCollector multiFieldSearch(String[] queryStrings, String[] fields, BooleanClause.Occur[] flags, Analyzer analyzer, int lucHits){		
  escapeStrings(queryStrings);
  Query query = null;
  try {
    query = MultiFieldQueryParser.parse(Version.LUCENE_36, queryStrings, fields, flags, analyzer);            
  } catch (ParseException e) {
    e.printStackTrace();
  }
  return search(query, lucHits);
}

代码示例来源:origin: org.apache.lucene/lucene-core-jfrog

/** Returns the numeric value of the hexadecimal character */
private static final int hexToInt(char c) throws ParseException {
 if ('0' <= c && c <= '9') {
  return c - '0';
 } else if ('a' <= c && c <= 'f'){
  return c - 'a' + 10;
 } else if ('A' <= c && c <= 'F') {
  return c - 'A' + 10;
 } else {
  throw new ParseException("None-hex character in unicode escape sequence: " + c);
 }
}

代码示例来源:origin: com.atlassian.jira/jira-api

/**
 * This method handles known lucene errors into user-friendly error message.
 */
@Nullable
private String translateException(final Exception ex, final I18nHelper i18n, final String fieldName,
    @Nullable final String sourceFunction, final boolean shortMessage, final String value)
{
  if (ex instanceof ParseException)
  {
    final ParseException parseException = (ParseException) ex;
    final String exMessage = parseException.getMessage();
    if (exMessage != null)
    {
      if (exMessage.endsWith("'*' or '?' not allowed as first character in WildcardQuery"))
      {
        return getErrorMessage(i18n, sourceFunction, shortMessage, fieldName, value, "jira.jql.text.clause.bad.start.in.wildcard");
      }
      else if (BAD_RANGEIN_PATTERN.matcher(exMessage).matches() || BAD_RANGEEX_PATTERN.matcher(exMessage).matches()) {
        return getErrorMessage(i18n, sourceFunction, shortMessage, fieldName, value, "jira.jql.text.clause.incorrect.range.query");
      }
    }
  }
  return null;
}

代码示例来源:origin: wks/ik-analyzer

/**
 * 组装Lucene Query
 * 处理关键字紧凑搜索
 * @param elements
 * @return
 */
private Query luceneQueryParse(String fieldName , String keyword){
  //截取头部^尾部$
  keyword = keyword.substring(1 , keyword.length() - 1);
  String luceneExp = fieldName + ":\"" + keyword + "\"";
  QueryParser luceneQueryParser = new QueryParser(Version.LUCENE_30 , "" ,new IKAnalyzer());
  try {
    Query lucenceQuery = luceneQueryParser.parse(luceneExp);
    return lucenceQuery;
  } catch (ParseException e) {
    e.printStackTrace();
  }                                
  return null;			
}

代码示例来源:origin: org.apache.lucene/com.springsource.org.apache.lucene

retval += add_escapes(tok.image);
retval += " \"";
tok = tok.next;

代码示例来源:origin: org.apache.lucene/com.springsource.org.apache.lucene

/** Returns the numeric value of the hexadecimal character */
private static final int hexToInt(char c) throws ParseException {
 if ('0' <= c && c <= '9') {
  return c - '0';
 } else if ('a' <= c && c <= 'f'){
  return c - 'a' + 10;
 } else if ('A' <= c && c <= 'F') {
  return c - 'A' + 10;
 } else {
  throw new ParseException("None-hex character in unicode escape sequence: " + c);
 }
}

代码示例来源:origin: org.dspace.dependencies.solr/dspace-solr-core

/**
 * Helper utility for parsing a query using the Lucene QueryParser syntax. 
 * @param qs query expression in standard Lucene syntax
 * @param defaultField default field used for unqualified search terms in the query expression
 * @param params used to determine the default operator, overriding the schema specified operator
 * @param schema used for default operator (overridden by params) and passed to the query parser for field format analysis information
 */
public static Query parseQuery(String qs, String defaultField, SolrParams params, IndexSchema schema) {
 try {
  SolrQueryParser parser = schema.getSolrQueryParser(defaultField);
  String opParam = params.get(OP);
  if (opParam != null) {
   parser.setDefaultOperator("AND".equals(opParam) ? QueryParser.Operator.AND : QueryParser.Operator.OR);
  }
  Query query = parser.parse(qs);
  if (SolrCore.log.isTraceEnabled() ) {
   SolrCore.log.trace("After QueryParser:" + query);
  }
  return query;
 } catch (ParseException e) {
  SolrCore.log(e);
  throw new SolrException( SolrException.ErrorCode.BAD_REQUEST,"Query parsing error: " + e.getMessage(),e);
 }
}

代码示例来源:origin: pebbleblog/pebble

pe.printStackTrace();
 searchResults.setMessage("Sorry, but there was an error. Please try another search");
} catch (Exception e) {

代码示例来源:origin: org.apache.lucene/lucene-core-jfrog

retval += add_escapes(tok.image);
retval += " \"";
tok = tok.next;

代码示例来源:origin: org.dspace.dependencies.solr/dspace-solr-core

void expect(String s) throws ParseException {
 eatws();
 int slen=s.length();
 if (val.regionMatches(pos, s, 0, slen)) {
  pos+=slen;
 } else {
  throw new ParseException("Expected '"+s+"' at position " + pos + " in '"+val+"'");
 }
}

代码示例来源:origin: omero/server

} catch (ParseException pe) {
  final String msg = queryStr + " caused a parse exception: " +
    pe.getMessage();

代码示例来源:origin: org.dspace.dependencies.solr/dspace-solr-core

String getId() throws ParseException {
 eatws();
 int id_start=pos;
 if (pos<end && Character.isJavaIdentifierStart(val.charAt(pos))) {
  pos++;
  while (pos<end) {
   char ch = val.charAt(pos);
   if (!Character.isJavaIdentifierPart(ch) && ch!='.') {
    break;
   }
   pos++;
  }
  return val.substring(id_start, pos);
 }
 throw new ParseException("Expected identifier at pos " + pos + " str='" + val + "'");
}

代码示例来源:origin: org.ow2.bonita/bonita-server

private FullTextQuery createFullTextQuery(final SearchQueryBuilder query, final Class<?> indexClass) {
 QueryParser parser = null;
 final String expression = query.getQuery();
 if (!expression.contains("\\:")) {
  parser = new QueryParser(LUCENE_VERSION, query.getIndex().getDefaultField(), new StandardAnalyzer(LUCENE_VERSION));
 } else {
  final List<String> list = query.getIndex().getAllFields();
  final String[] fields = list.toArray(new String[list.size()]);
  parser = new MultiFieldQueryParser(LUCENE_VERSION, fields, new StandardAnalyzer(LUCENE_VERSION));
 }
 final FullTextSession searchSession = Search.getFullTextSession(getSession());
 try {
  final org.apache.lucene.search.Query luceneQuery = parser.parse(query.getQuery());
  return searchSession.createFullTextQuery(luceneQuery, indexClass);
 } catch (final ParseException e) {
  throw new BonitaRuntimeException(e.getMessage());
 }
}

代码示例来源:origin: org.terracotta.modules/tim-searchable

protected Query getFieldQuery(String term, String value) throws ParseException{
    if(term.equals(RAMBufferedDataStore.KEY_STRING_INDEX_FILED)) 
      return new TermQuery(new Term(term,value));
    try { 
      Converter converter = ipp.getConverter(term);
      if(converter!=null){	
        String modifiedPart1 = converter.format(value);
        return new TermQuery(new Term(term,modifiedPart1));  
      } 
    }
    catch (NumberFormatException e) { 
      e.printStackTrace();
      throw new ParseException(e.getMessage()); 
    }
    return super.getFieldQuery(term, value);
  }
}

相关文章