Java Code Examples for org.apache.lucene.queryparser.complexPhrase.ComplexPhraseQueryParser

The following examples show how to use org.apache.lucene.queryparser.complexPhrase.ComplexPhraseQueryParser. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: Stargraph   Source File:    License: MIT License 6 votes vote down vote up
private static Query fuzzyPhraseSearch(String field, String searchTerm, int maxEdits) {
    StringBuilder queryStr = new StringBuilder();

    String words[] = searchTerm.split("\\s+");
    for (int i = 0; i < words.length; i++) {
        if (i > 0) {
            queryStr.append(" AND ");

    try {
        return new ComplexPhraseQueryParser("value", new StandardAnalyzer()).parse(queryStr.toString());
    } catch (ParseException e) {
        throw new StarGraphException(e);
Example 2
Source Project: Quelea   Source File:    License: GNU General Public License v3.0 5 votes vote down vote up
 * Search for bible chapters that match the given filter.
 * @param queryString the query string to filter.
 * @param type ignored - may be null.
 * @return a list of all bible chapters that match the given filter.
public BibleChapter[] filter(String queryString, FilterType type) {
    String sanctifyQueryString = SearchIndexUtils.makeLuceneQuery(queryString);
    if(chapters.isEmpty() || sanctifyQueryString.isEmpty()) {
        return chapters.values().toArray(new BibleChapter[chapters.size()]);
    List<BibleChapter> ret;
    try (DirectoryReader dr = {
        IndexSearcher searcher = new IndexSearcher(dr);
        Query q = new ComplexPhraseQueryParser("text", analyzer).parse(sanctifyQueryString);
        TopScoreDocCollector collector = TopScoreDocCollector.create(10000,10000);, collector);
        ScoreDoc[] hits = collector.topDocs().scoreDocs;
        ret = new ArrayList<>();
        for(int i = 0; i < hits.length; ++i) {
            int docId = hits[i].doc;
            Document d = searcher.doc(docId);
            BibleChapter chapter = chapters.get(Integer.parseInt(d.get("number")));
        return ret.toArray(new BibleChapter[ret.size()]);
    catch (ParseException | IOException ex) {
        LOGGER.log(Level.WARNING, "Invalid query string: " + sanctifyQueryString, ex);
        return new BibleChapter[0];
Example 3
Source Project: lucene-solr   Source File:    License: Apache License 2.0 5 votes vote down vote up
public void testComplexPhraseQueryParser() throws Exception {

    ComplexPhraseQueryParser cpqp = new ComplexPhraseQueryParser(FIELD, new StandardAnalyzer());
    Query query = cpqp.parse("\"x b\"");
    try (Monitor monitor = newMonitor()) {
      monitor.register(new MonitorQuery("1", query));
      Document doc = buildDoc("x b c");
      MatchingQueries<HighlightsMatch> matches = monitor.match(doc, HighlightsMatch.MATCHER);
      HighlightsMatch m = matches.matches("1");
      assertEquals(2, m.getHitCount());