public void testWildCardQuery() throws ParseException {
   Analyzer a = new ASCIIAnalyzer();
   QueryParser parser = new QueryParser(FIELD, a);
   parser.setAllowLeadingWildcard(true);
   assertEquals("*bersetzung uber*ung", parser.parse("*bersetzung über*ung").toString(FIELD));
   parser.setAllowLeadingWildcard(false);
   assertEquals(
       "motley crue motl?* cru?", parser.parse("Mötley Cr\u00fce Mötl?* Crü?").toString(FIELD));
   assertEquals(
       "renee zellweger ren?? zellw?ger",
       parser.parse("Renée Zellweger Ren?? Zellw?ger").toString(FIELD));
 }
  public void testWildcardAlone() throws ParseException {
    // seems like crazy edge case, but can be useful in concordance
    QueryParser parser = new QueryParser(FIELD, new ASCIIAnalyzer());
    parser.setAllowLeadingWildcard(false);
    expectThrows(
        ParseException.class,
        () -> {
          parser.parse("*");
        });

    QueryParser parser2 = new QueryParser("*", new ASCIIAnalyzer());
    parser2.setAllowLeadingWildcard(false);
    assertEquals(new MatchAllDocsQuery(), parser2.parse("*"));
  }
  private QueryExpression create(Request request, ResourceDefinition resourceDefinition)
      throws InvalidQueryException {
    String queryString;
    if (request.getCardinality() == Request.Cardinality.INSTANCE) {
      String idPropertyName = resourceDefinition.getIdPropertyName();
      queryString =
          String.format("%s:%s", idPropertyName, request.<String>getProperty(idPropertyName));
    } else {
      queryString = request.getQueryString();
    }

    QueryExpression queryExpression;
    if (queryString != null && !queryString.isEmpty()) {
      QueryParser queryParser = new QueryParser(Version.LUCENE_48, "name", new KeywordAnalyzer());
      queryParser.setLowercaseExpandedTerms(false);
      queryParser.setAllowLeadingWildcard(true);
      Query query;
      try {
        query = queryParser.parse((String) escape(queryString));
      } catch (ParseException e) {
        throw new InvalidQueryException(e.getMessage());
      }
      LOG.info("LuceneQuery: " + query);
      queryExpression = create(query, resourceDefinition);
    } else {
      queryExpression = new AlwaysQueryExpression();
    }
    // add query properties to request so that they are returned
    request.addAdditionalSelectProperties(queryExpression.getProperties());
    return queryExpression;
  }
 private List<T> search(
     final String queryString,
     final int pageNumber,
     final int pageSize,
     final PagingStrategy paging) {
   final QueryParser parser = new QueryParser(DEFAULT_FIELD, new StandardAnalyzer());
   parser.setAllowLeadingWildcard(true);
   parser.setDefaultOperator(Operator.AND);
   final FullTextSession searchSession = getSearchSession();
   try {
     final FullTextQuery query =
         searchSession.createFullTextQuery(parser.parse(queryString), this.type);
     paging.setup(query, pageNumber, pageSize);
     return query.list();
   } catch (final ParseException e) {
     throw new EGOVRuntimeException("invalid.search.string", e);
   }
 }