/** * Builds a phrase query over the default text field in LuceneOptions. * * @param searchString * @return */ public QueryBuilder setPhraseQuery(String searchString) { return setPhraseQuery(searcher.getOptions().elements, searchString); }
/** * Builds a MoreLikeThis query for the specified luceneId over the * default text field in LuceneOptions. * * @param luceneId * @return * @throws DaoException */ public QueryBuilder setMoreLikeThisQuery(int luceneId) throws DaoException { return setMoreLikeThisQuery( searcher.getOptions().elements, luceneId); }
/** * Builds a phrase query over the specified field. * * @param fieldName the name of the field on which to search * @param searchString * @return */ public QueryBuilder setPhraseQuery(String fieldName, String searchString) { QueryParser parser = new QueryParser( searcher.getOptions().matchVersion, fieldName, searcher.getAnalyzerByLanguage(language)); try { searchString = QueryParserUtil.escape(searchString); // Lucene doesn't escape forward slash, but it needs to searchString = StringUtils.replace(searchString, "/", "\\/"); query = parser.parse(searchString); return this; } catch (ParseException e) { throw new RuntimeException(e); // should never happen after escaping } }