Package org.apache.lucene.queryparser.classic

Examples of org.apache.lucene.queryparser.classic.QueryParser


  }

  private void checkMatches(String qString, String expectedVals)
      throws Exception {
    QueryParser qp = new ComplexPhraseQueryParser(TEST_VERSION_CURRENT, defaultFieldName, analyzer);
    qp.setFuzzyPrefixLength(1); // usually a good idea

    Query q = qp.parse(qString);

    HashSet<String> expecteds = new HashSet<String>();
    String[] vals = expectedVals.split(",");
    for (int i = 0; i < vals.length; i++) {
      if (vals[i].length() > 0)
View Full Code Here


    doc.add(field);
    writer.addDocument(doc);
    writer.close();
    DirectoryReader ir = DirectoryReader.open(ramDir);
    IndexSearcher is = new IndexSearcher(ir);
    QueryParser qp = new AnalyzingQueryParser(TEST_VERSION_CURRENT, "content", analyzer);
    Query q = qp.parse("[เข TO เข]");
    assertEquals(1, is.search(q, 10).totalHits);
    ir.close();
    ramDir.close();
  }
View Full Code Here

   */
  public void assertAllQueries(MemoryIndex memory, Directory ramdir, Analyzer analyzer) throws Exception {
    IndexReader reader = DirectoryReader.open(ramdir);
    IndexSearcher ram = newSearcher(reader);
    IndexSearcher mem = memory.createSearcher();
    QueryParser qp = new QueryParser(TEST_VERSION_CURRENT, "foo", analyzer);
    for (String query : queries) {
      TopDocs ramDocs = ram.search(qp.parse(query), 1);
      TopDocs memDocs = mem.search(qp.parse(query), 1);
      assertEquals(query, ramDocs.totalHits, memDocs.totalHits);
    }
    reader.close();
  }
View Full Code Here

      in = new BufferedReader(new InputStreamReader(new FileInputStream(queries), StandardCharsets.UTF_8));
    } else {
      in = new BufferedReader(new InputStreamReader(System.in, StandardCharsets.UTF_8));
    }
    // :Post-Release-Update-Version.LUCENE_XY:
    QueryParser parser = new QueryParser(Version.LUCENE_4_9, field, analyzer);
    while (true) {
      if (queries == null && queryString == null) {                        // prompt the user
        System.out.println("Enter query: ");
      }

      String line = queryString != null ? queryString : in.readLine();

      if (line == null || line.length() == -1) {
        break;
      }

      line = line.trim();
      if (line.length() == 0) {
        break;
      }
     
      Query query = parser.parse(line);
      System.out.println("Searching for: " + query.toString(field));
           
      if (repeat > 0) {                           // repeat & time as benchmark
        Date start = new Date();
        for (int i = 0; i < repeat; i++) {
View Full Code Here

    indexReader = IndexReader.open(FSDirectory.open(new File(indexPath)));
    numDocs = indexReader.numDocs();
    indexSearcher = new IndexSearcher(indexReader);
    standardAnalyzer = new StandardAnalyzer(Version.LUCENE_40);
    queryParser = new QueryParser(Version.LUCENE_40, searchField, standardAnalyzer);
    lastQuery = new Cache();
  }
View Full Code Here

    // check if there is a redirect
    if(redirectTitle == null) {
      return scoreDoc;
    }
   
    QueryParser redirectQueryParser = new QueryParser(Version.LUCENE_30, "title", standardAnalyzer);

    String redirectTitleNoUnderscores = redirectTitle.replaceAll("_", " ");
    String redirectTitleQuoted = '"' + redirectTitleNoUnderscores + '"';
    String redirectTitleEscaped = QueryParser.escape(redirectTitleQuoted);
    Query redirectQuery  = redirectQueryParser.parse(redirectTitleEscaped);

    ScoreDoc[] redirectScoreDocs = indexSearcher.search(redirectQuery, null, 1).scoreDocs;
    if(redirectScoreDocs.length < 1) {
      System.out.println("failed redirect: " + redirectTitle + " -> " + redirectTitle);
      return scoreDoc; // redirect query did not return any results
View Full Code Here

    Query query = DEFAULT_QUERY;
    if (hasOption(OPTION_QUERY)) {
      try {
        String queryString = COMPILE.matcher(getOption(OPTION_QUERY)).replaceAll("");
        QueryParser queryParser = new QueryParser(Version.LUCENE_43, queryString,
            new StandardAnalyzer(Version.LUCENE_43));
        query = queryParser.parse(queryString);
      } catch (ParseException e) {
        throw new IllegalArgumentException(e.getMessage(), e);
      }
    }
    lucene2SeqConf.setQuery(query);
View Full Code Here

      for (String indexPath : indexPaths) {
        this.indexPaths.add(new Path(indexPath));
      }
      idField = in.readUTF();
      fields = Arrays.asList(in.readUTF().split(SEPARATOR_FIELDS));
      query = new QueryParser(LUCENE_43, "query", new StandardAnalyzer(LUCENE_43)).parse(in.readUTF());
      maxHits = in.readInt();
    } catch (ParseException e) {
      throw new RuntimeException("Could not deserialize " + this.getClass().getName(), e);
    }
  }
View Full Code Here

    }

    private List<Map<String, Node>> get$(IndexReader indexReader, String uri) throws ParseException, IOException {
        String escaped = QueryParser.escape(uri) ;
        String qs = docDef.getEntityField() + ":" + escaped ;
        QueryParser queryParser = new QueryParser(VER, docDef.getPrimaryField(), analyzer) ;
        Query query = queryParser.parse(qs) ;
        IndexSearcher indexSearcher = new IndexSearcher(indexReader) ;
        ScoreDoc[] sDocs = indexSearcher.search(query, 1).scoreDocs ;
        List<Map<String, Node>> records = new ArrayList<Map<String, Node>>() ;

        // Align and DRY with Solr.
View Full Code Here

        }
    }

    private List<Node> query$(IndexReader indexReader, String qs, int limit) throws ParseException, IOException {
        IndexSearcher indexSearcher = new IndexSearcher(indexReader) ;
        QueryParser queryParser = new QueryParser(VER, docDef.getPrimaryField(), analyzer) ;
        Query query = queryParser.parse(qs) ;

        if ( limit <= 0 )
            limit = MAX_N ;
        ScoreDoc[] sDocs = indexSearcher.search(query, limit).scoreDocs ;
View Full Code Here

TOP

Related Classes of org.apache.lucene.queryparser.classic.QueryParser

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.