org.apache.lucene.queryparser.classic.ParseException.<init>()方法的使用及代码示例

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

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

ParseException.<init>介绍

[英]The following constructors are for use by you for whatever purpose you can think of. Constructing the exception in this manner makes the exception behave in the normal way - i.e., as documented in the class "Throwable". The fields "errorToken", "expectedTokenSequences", and "tokenImage" do not contain relevant information. The JavaCC generated code does not use these constructors.
[中]以下构造函数供您用于任何您能想到的目的。以这种方式构造异常会使异常以正常方式运行——即,如类“Throwable”中所述。字段“errorToken”、“expectedTokenSequences”和“tokenImage”不包含相关信息。JavaCC生成的代码不使用这些构造函数。

代码示例

代码示例来源:origin: jeremylong/DependencyCheck

/**
 * Parses the given string into a Lucene Query.
 *
 * @param searchString the search text
 * @return the Query object
 * @throws ParseException thrown if the search text cannot be parsed
 */
protected Query parseQuery(String searchString) throws ParseException {
  if (searchString == null || searchString.trim().isEmpty()) {
    throw new ParseException("Query is null or empty");
  }
  LOGGER.debug(searchString);
  final Query query = queryParser.parse(searchString);
  return query;
}

代码示例来源:origin: rnewson/couchdb-lucene

public TypedField(final String string) throws ParseException {
  final Matcher matcher = PATTERN.matcher(string);
  if (!matcher.matches()) {
    throw new ParseException("Field '" + string + "' not recognized.");
  }
  this.name = matcher.group(1);
  try {
    this.type = matcher.group(3) == null ? FieldType.TEXT : FieldType.valueOf(matcher.group(3).toUpperCase());
  } catch (final IllegalArgumentException e) {
    throw new ParseException("Unrecognized type '" + matcher.group(3) + "'");
  }
}

代码示例来源:origin: rnewson/couchdb-lucene

public static long toDate(final Object obj) throws ParseException {
  if (obj instanceof Date) {
    return ((Date) obj).getTime();
  }
  try {
    return DateUtils.parseDate(obj.toString().toUpperCase(), DATE_PATTERNS).getTime();
  } catch (final java.text.ParseException e) {
    throw new ParseException(e.getMessage());
  }
}

代码示例来源:origin: org.elasticsearch/elasticsearch

throw new ParseException(e.getMessage());
} finally {
  queryBuilder.setAnalyzer(oldAnalyzer);

代码示例来源:origin: org.elasticsearch/elasticsearch

@Override
protected Query getFieldQuery(String field, String queryText, int slop) throws ParseException {
  if (field != null && EXISTS_FIELD.equals(field)) {
    return existsQuery(queryText);
  }
  Map<String, Float> fields = extractMultiFields(field, true);
  if (fields.isEmpty()) {
    return newUnmappedFieldQuery(field);
  }
  Analyzer oldAnalyzer = queryBuilder.analyzer;
  int oldSlop = queryBuilder.phraseSlop;
  try {
    if (forceQuoteAnalyzer != null) {
      queryBuilder.setAnalyzer(forceQuoteAnalyzer);
    } else if (forceAnalyzer != null) {
      queryBuilder.setAnalyzer(forceAnalyzer);
    }
    queryBuilder.setPhraseSlop(slop);
    Query query = queryBuilder.parse(MultiMatchQueryBuilder.Type.PHRASE, fields, queryText, null);
    if (query == null) {
      return null;
    }
    return applySlop(query, slop);
  } catch (IOException e) {
    throw new ParseException(e.getMessage());
  } finally {
    queryBuilder.setAnalyzer(oldAnalyzer);
    queryBuilder.setPhraseSlop(oldSlop);
  }
}

代码示例来源:origin: harbby/presto-connectors

/** Returns the numeric value of the hexadecimal character */
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("Non-hex character in Unicode escape sequence: " + c);
 }
}

代码示例来源:origin: org.infinispan/infinispan-embedded-query

/** Returns the numeric value of the hexadecimal character */
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("Non-hex character in Unicode escape sequence: " + c);
 }
}

代码示例来源:origin: org.infinispan/infinispan-embedded-query

private void checkPhraseClauseIsForSameField(String field)
  throws ParseException {
 if (!field.equals(currentPhraseQuery.field)) {
  throw new ParseException("Cannot have clause for field \"" + field
    + "\" nested in phrase " + " for field \"" + currentPhraseQuery.field
    + "\"");
 }
}

代码示例来源:origin: harbby/presto-connectors

private void checkPhraseClauseIsForSameField(String field)
  throws ParseException {
 if (!field.equals(currentPhraseQuery.field)) {
  throw new ParseException("Cannot have clause for field \"" + field
    + "\" nested in phrase " + " for field \"" + currentPhraseQuery.field
    + "\"");
 }
}

代码示例来源:origin: org.infinispan/infinispan-embedded-query

Query handleBareFuzzy(String qfield, Token fuzzySlop, String termImage)
  throws ParseException {
 Query q;
 float fms = fuzzyMinSim;
 try {
  fms = Float.valueOf(fuzzySlop.image.substring(1)).floatValue();
 } catch (Exception ignored) { }
 if(fms < 0.0f){
  throw new ParseException("Minimum similarity for a FuzzyQuery has to be between 0.0f and 1.0f !");
 } else if (fms >= 1.0f && fms != (int) fms) {
  throw new ParseException("Fractional edit distances are not allowed!");
 }
 q = getFuzzyQuery(qfield, termImage, fms);
 return q;
}

代码示例来源:origin: harbby/presto-connectors

Query handleBareFuzzy(String qfield, Token fuzzySlop, String termImage)
  throws ParseException {
 Query q;
 float fms = fuzzyMinSim;
 try {
  fms = Float.valueOf(fuzzySlop.image.substring(1)).floatValue();
 } catch (Exception ignored) { }
 if(fms < 0.0f){
  throw new ParseException("Minimum similarity for a FuzzyQuery has to be between 0.0f and 1.0f !");
 } else if (fms >= 1.0f && fms != (int) fms) {
  throw new ParseException("Fractional edit distances are not allowed!");
 }
 q = getFuzzyQuery(qfield, termImage, fms);
 return q;
}

代码示例来源:origin: com.senseidb/sensei-core

@Override
public Filter buildFilter() throws ParseException {
 try {
  return FilterConstructor.constructFilter(filter, _qparser);
 } catch (Exception e) {
  logger.error(e.getMessage(), e);
  throw new ParseException(e.getMessage());
 }
}

代码示例来源:origin: org.owasp/dependency-check-core

/**
 * Parses the given string into a Lucene Query.
 *
 * @param searchString the search text
 * @return the Query object
 * @throws ParseException thrown if the search text cannot be parsed
 */
protected Query parseQuery(String searchString) throws ParseException {
  if (searchString == null || searchString.trim().isEmpty()) {
    throw new ParseException("Query is null or empty");
  }
  LOGGER.debug(searchString);
  final Query query = queryParser.parse(searchString);
  return query;
}

代码示例来源:origin: com.senseidb/sensei-core

@Override
public Query buildQuery() throws ParseException {
 try {
  Query q = QueryConstructor.constructQuery(query, _qparser);
  if (q == null) {
   q = new MatchAllDocsQuery();
  }
  return q;
 } catch (Exception e) {
  logger.error(e.getMessage(), e);
  throw new ParseException(e.getMessage());
 }
}

代码示例来源:origin: com.senseidb/sensei-core

protected void doBuild(SenseiQuery query, QueryParser parser) throws Exception {
 if (query != null) {
  byte[] bytes = query.toBytes();
  String qString = null;
  try {
   qString = new String(bytes, "UTF-8");
  } catch (UnsupportedEncodingException e) {
   throw new ParseException(e.getMessage());
  }
  if (qString.length() > 0) {
   synchronized (parser) {
    _query = parser.parse(qString);
   }
  }
 }
}

代码示例来源:origin: com.qwazr/qwazr-search

@Override
@JsonIgnore
final public SpanQuery getQuery(final QueryContext queryContext)
    throws IOException, ReflectiveOperationException, ParseException, QueryNodeException {
  final Query subQuery = wrappedQuery.getQuery(queryContext);
  if (subQuery instanceof SpanQuery)
    return (SpanQuery) subQuery;
  else if (subQuery instanceof MultiTermQuery)
    return new org.apache.lucene.search.spans.SpanMultiTermQueryWrapper((MultiTermQuery) subQuery);
  else if (subQuery instanceof org.apache.lucene.search.TermQuery)
    return new org.apache.lucene.search.spans.SpanTermQuery(
        ((org.apache.lucene.search.TermQuery) subQuery).getTerm());
  throw new ParseException("Cannot convert " + subQuery.getClass().getName() + " as SpanQuery");
}

代码示例来源:origin: org.infinispan/infinispan-embedded-query

/** 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).build();
 }
 catch (ParseException | TokenMgrError tme) {
  // rethrow to include the original query:
  ParseException e = new ParseException("Cannot parse '" +query+ "': " + tme.getMessage());
  e.initCause(tme);
  throw e;
 } catch (BooleanQuery.TooManyClauses tmc) {
  ParseException e = new ParseException("Cannot parse '" +query+ "': too many boolean clauses");
  e.initCause(tmc);
  throw e;
 }
}

代码示例来源:origin: rdelbru/SIREn

/**
 * Uses {@link SolrPluginUtils#parseFieldBoosts(String)} with the 'qf'
 * parameter. Falls back to the 'df' parameter or
 * {@link org.apache.solr.schema.IndexSchema#getDefaultSearchFieldName()}.
 */
public static Map<String, Float> parseQueryFields(final IndexSchema indexSchema, final SolrParams solrParams)
throws ParseException {
 final Map<String, Float> queryFields = SolrPluginUtils.parseFieldBoosts(solrParams.getParams(SirenParams.QF));
 if (queryFields.isEmpty()) {
  final String df = QueryParsing.getDefaultField(indexSchema, solrParams.get(CommonParams.DF));
  if (df == null) {
   throw new ParseException("Neither "+SirenParams.QF+", "+CommonParams.DF +", nor the default search field are present.");
  }
  queryFields.put(df, 1.0f);
 }
 checkFieldTypes(indexSchema, queryFields);
 return queryFields;
}

代码示例来源:origin: msokolov/lux

@Override
  public org.apache.lucene.search.Query parse(ExtensionQuery query) throws ParseException {
    String field = query.getField();
    String term = query.getRawQueryString();
    // create either a term query or a phrase query (or a span?)
    try {
      if (StringUtils.isEmpty(field)) {
        return queryBuilder.parseQueryTerm(textFieldName, field, term, 1.0f);
      } else if (field.charAt(0) == '@') {
        return queryBuilder.parseQueryTerm(attributeTextFieldName, field.substring(1), term, 1.0f);
      } else {
        return queryBuilder.parseQueryTerm(elementTextFieldName, field, term, 1.0f);
      }
    } catch (ParserException e) {
      throw new ParseException (e.getMessage());
    }
  }
}

代码示例来源:origin: epam/Wilma

@Test(expectedExceptions = QueryCannotBeParsedException.class)
public void testSearchForTextWhenCannotParseQueryShouldThrowError() throws IOException, ParseException {
  //GIVEN
  given(readerFactory.create(true)).willReturn(indexReader);
  given(searcherFactory.create(indexReader)).willReturn(indexSearcher);
  given(queryParser.parse(TEXT)).willThrow(new ParseException());
  //WHEN
  underTest.searchForText(TEXT);
  //THEN it should throw exception
}

相关文章