Refine search
errorMsg = PARSE_ERROR_MSG + e.getMessage(); } catch (FileNotFoundException e) {
QueryParser qp = new QueryParser(hashesFieldName, new WhitespaceAnalyzer()); Query query = null; try { query = qp.parse(hashes); } catch (ParseException e) { e.printStackTrace();
/** * 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; }
QueryParser qp = new QueryParser(fieldName, new StandardAnalyzer()); qp.setDefaultOperator(QueryParser.AND_OPERATOR); qp.setAutoGeneratePhraseQueries(true); return qp.parse(keywordBuffer_Short.toString()); } catch (ParseException e) { e.printStackTrace(); return qp.parse(keywordBuffer.toString()); } catch (ParseException e) { e.printStackTrace();
/** {@inheritDoc} */ @Override public Query doQuery(Schema schema) { try { Analyzer analyzer = schema.analyzer; QueryParser queryParser = new QueryParser(defaultField, analyzer); queryParser.setAllowLeadingWildcard(true); queryParser.setLowercaseExpandedTerms(false); return queryParser.parse(query); } catch (ParseException e) { throw new IndexException("Error while parsing lucene syntax query: {}", e.getMessage()); } }
@Override public SearchResultIF search(String query) throws IOException { synchronized (READER_LOCK) { openReader(); IndexSearcher searcher = new IndexSearcher(reader); try { logger.debug("Searching for: '" + query + "'"); Query _query = new QueryParser(defaultField, ANALYZER).parse(query); return new LuceneSearchResult(searcher, searcher.search(_query, Integer.MAX_VALUE)); } catch (org.apache.lucene.queryparser.classic.ParseException e) { logger.error("Error parsing query: '" + e.getMessage() + "'"); throw new IOException(e.getMessage(), e); } } }
@Override public Page<PrDataset> searchByQuery(String query, Pageable pageable) { final FullTextEntityManager fullTextEntityManager = Search.getFullTextEntityManager(entityManager); FullTextQuery fullTextQuery; try { final QueryParser queryParser = new QueryParser("content", fullTextEntityManager.getSearchFactory().getAnalyzer(PrDataset.class)); fullTextQuery = fullTextEntityManager.createFullTextQuery(queryParser.parse(query), PrDataset.class); } catch (ParseException e) { e.printStackTrace(); throw new RuntimeException("Fail to search query : " + e.getMessage()); } fullTextQuery.setFirstResult(pageable.getOffset()); fullTextQuery.setMaxResults(pageable.getPageSize()); return new PageImpl<>(fullTextQuery.getResultList(), pageable, fullTextQuery.getResultSize()); }
public ImageSearchHits search(Document doc, IndexReader reader) throws IOException { SimpleImageSearchHits sh = null; IndexSearcher isearcher = new IndexSearcher(reader); isearcher.setSimilarity(similarity); String queryString = doc.getValues(fieldName)[0]; Query tq = null; try { tq = qp.parse(queryString); TopDocs docs = isearcher.search(tq, numMaxHits); LinkedList<SimpleResult> res = new LinkedList<SimpleResult>(); double maxDistance = 0d; for (int i = 0; i < docs.scoreDocs.length; i++) { double d = 1d / docs.scoreDocs[i].score; maxDistance = Math.max(d, maxDistance); SimpleResult sr = new SimpleResult(d, docs.scoreDocs[i].doc); res.add(sr); } sh = new SimpleImageSearchHits(res, maxDistance); } catch (ParseException e) { System.err.println(queryString); e.printStackTrace(); } return sh; }
private Query createQuery(final String query) { Query result = null; try { result = queryParser.parse(query); } catch (ParseException e) { throw new QueryCannotBeParsedException("Query " + query + "cannot be parsed. Reason:" + e.getMessage()); } return result; }
QueryParser parser = createQueryParser(prop); parser.setAllowLeadingWildcard(true); parser.setDefaultOperator(defaultOperator); Query query = parser.parse(sSearchTerm); throw new InvalidAccessException(InvalidAccessException.INVALID_INDEX, e.getMessage(), e); } catch (ParseException e) { logger.severe("Lucene search error: " + e.getMessage()); throw new QueryException(QueryException.QUERY_NOT_UNDERSTANDABLE, e.getMessage(), e);
public ScoreDoc[] runQuery(String qno, String queryTerms){ ScoreDoc[] hits = null; System.out.println("Query No.: " + qno + " " + queryTerms); try { Query query = parser.parse(QueryParser.escape(queryTerms)); try { TopDocs results = searcher.search(query, p.maxResults); hits = results.scoreDocs; } catch (IOException ioe){ ioe.printStackTrace(); System.exit(1); } } catch (ParseException pe){ pe.printStackTrace(); System.exit(1); } return hits; }
/** * Different from term query in that the query parameter specified is passed through an analyzer that may * remove certain stop words before constructing a Query. Desirable for full text search fields. Undesirable for keyword * searches (build a Term query instead). * * @param searchFields * @param query */ public Query buildStandardQuery(String[] searchFields, String query) { Query myquery; try { QueryParser qp = makeQueryParserForSearchFields(searchFields); qp.setDefaultOperator(QueryParser.Operator.AND); myquery = qp.parse(query); } catch (ParseException e) { throw new LuceneException("Couldn't parse the query successfully:" + e.getMessage()); } return myquery; }
queryParser.setAllowLeadingWildcard(true); Query query; try { query = queryParser.parse(strQuery); } catch (ParseException e) { String errorMessage = String.format( "failed to filter block with query %s, detail is %s", strQuery, e.getMessage()); LOGGER.error(errorMessage); return null;
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) + "'"); } }
final public int Conjunction() throws ParseException { int ret = CONJ_NONE; switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case AND: case OR: switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case AND: jj_consume_token(AND); ret = CONJ_AND; break; case OR: jj_consume_token(OR); ret = CONJ_OR; break; default: jj_la1[0] = jj_gen; jj_consume_token(-1); throw new ParseException(); } break; default: jj_la1[1] = jj_gen; ; } {if (true) return ret;} throw new Error("Missing return statement in function"); }
} catch (org.apache.lucene.queryparser.classic.ParseException e) { throw new AnalyticsIndexException("Error while parsing lucene query '" + languageQuery + "': " + e.getMessage(), e.getCause());
jj_rescan_token(); jj_add_error_token(0, 0); int[][] exptokseq = new int[jj_expentries.size()][]; for (int i = 0; i < jj_expentries.size(); i++) { exptokseq[i] = jj_expentries.get(i); return new ParseException(token, exptokseq, tokenImage);
/** 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; } }
private HashMap<String, List<Location>> resolveEntities(List<String> locationNames, int count, IndexReader reader) throws IOException { if (locationNames.size() >= 200) hitsPerPage = 5; // avoid heavy computation IndexSearcher searcher = new IndexSearcher(reader); Query q = null; HashMap<String, List<Location>> allCandidates = new HashMap<String, List<Location>>(); for (String name : locationNames) { if (!allCandidates.containsKey(name)) { try { //query is wrapped in additional quotes (") to avoid query tokenization on space q = new MultiFieldQueryParser(new String[] { FIELD_NAME_NAME, FIELD_NAME_ALTERNATE_NAMES }, analyzer).parse(String.format("\"%s\"", name) ); Sort sort = new Sort(populationSort); //Fetch 3 times desired values, these will be sorted on code and only desired number will be kept ScoreDoc[] hits = searcher.search(q, hitsPerPage * 3 , sort).scoreDocs; getMatchingCandidates(searcher, allCandidates, name, hits); } catch (org.apache.lucene.queryparser.classic.ParseException e) { e.printStackTrace(); } } } HashMap<String, List<Location>> resolvedEntities = new HashMap<String, List<Location>>(); pickBestCandidates(resolvedEntities, allCandidates, count); return resolvedEntities; }
retval += add_escapes(tok.image); retval += " \""; tok = tok.next;