Package org.apache.lucene.queryparser.classic

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


      factory.init(params);
      Similarity simLMDir = factory.getSimilarity();
      searcher.setSimilarity(simLMDir);
    }

    QueryParser p = new QueryParser(Version.LUCENE_43, StatusField.TEXT.name,
        IndexStatuses.ANALYZER);

    TrecTopicSet topics = TrecTopicSet.fromFile(new File(topicsFile));
    for ( TrecTopic topic : topics ) {
      Query query = p.parse(topic.getQuery());
      Filter filter = NumericRangeFilter.newLongRange(StatusField.ID.name, 0L,
          topic.getQueryTweetTime(), true, true);

      TopDocs rs = searcher.search(query, filter, numResults);
View Full Code Here


      factory.init(params);
      Similarity simLMDir = factory.getSimilarity();
      searcher.setSimilarity(simLMDir);
    }

    QueryParser p = new QueryParser(Version.LUCENE_43, IndexStatuses.StatusField.TEXT.name, IndexStatuses.ANALYZER);
    Query query = p.parse(queryText);
    Filter filter = NumericRangeFilter.newLongRange(StatusField.ID.name, 0L, maxId, true, true);

    TopDocs rs = searcher.search(query, filter, numResults);

    int i = 1;
View Full Code Here

        if (fields.length > flags.length)
            throw new IllegalArgumentException("fields.length != flags.length");
        BooleanQuery bQuery = new BooleanQuery();
        for (int i = 0; i < fields.length; i++)
        {
            QueryParser qp = new HebrewQueryParser(matchVersion, fields[i], analyzer);
            Query q = qp.parse(query);
            if (q != null && (!(q instanceof BooleanQuery) || ((BooleanQuery)q).getClauses().length > 0))
            {
                bQuery.add(q, flags[i]);
            }
        }
View Full Code Here

        if (queries.length != fields.length)
            throw new IllegalArgumentException("queries.length != fields.length");
        BooleanQuery bQuery = new BooleanQuery();
        for (int i = 0; i < fields.length; i++)
        {
            QueryParser qp = new HebrewQueryParser(matchVersion, fields[i], analyzer);
            Query q = qp.parse(queries[i]);
            if (q != null && (!(q instanceof BooleanQuery) || ((BooleanQuery)q).getClauses().length > 0))
            {
                bQuery.add(q, BooleanClause.Occur.SHOULD);
            }
        }
View Full Code Here

        if (!(queries.length == fields.length && queries.length == flags.length))
            throw new IllegalArgumentException("queries, fields, and flags array have have different length");
        BooleanQuery bQuery = new BooleanQuery();
        for (int i = 0; i < fields.length; i++)
        {
            QueryParser qp = new HebrewQueryParser(matchVersion, fields[i], analyzer);
            Query q = qp.parse(queries[i]);
            if (q != null && (!(q instanceof BooleanQuery) || ((BooleanQuery)q).getClauses().length > 0))
            {
                bQuery.add(q, flags[i]);
            }
        }
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

   */
  public boolean deleteAll(RepositoryModel repository) {
    try {
      IndexWriter writer = getWriter();
      StandardAnalyzer analyzer = new StandardAnalyzer(luceneVersion);
      QueryParser qp = new QueryParser(luceneVersion, Lucene.rid.name(), analyzer);
      BooleanQuery query = new BooleanQuery();
      query.add(qp.parse(repository.getRID()), Occur.MUST);

      int numDocsBefore = writer.numDocs();
      writer.deleteDocuments(query);
      writer.commit();
      closeSearcher();
View Full Code Here

   * @throws Exception
   * @return true, if deleted, false if no record was deleted
   */
  private boolean delete(String repository, long ticketId, IndexWriter writer) throws Exception {
    StandardAnalyzer analyzer = new StandardAnalyzer(luceneVersion);
    QueryParser qp = new QueryParser(luceneVersion, Lucene.did.name(), analyzer);
    BooleanQuery query = new BooleanQuery();
    query.add(qp.parse(StringUtils.getSHA1(repository + ticketId)), Occur.MUST);

    int numDocsBefore = writer.numDocs();
    writer.deleteDocuments(query);
    writer.commit();
    closeSearcher();
View Full Code Here

    Set<QueryResult> results = new LinkedHashSet<QueryResult>();
    StandardAnalyzer analyzer = new StandardAnalyzer(luceneVersion);
    try {
      // search the title, description and content
      BooleanQuery query = new BooleanQuery();
      QueryParser qp;

      qp = new QueryParser(luceneVersion, Lucene.title.name(), analyzer);
      qp.setAllowLeadingWildcard(true);
      query.add(qp.parse(text), Occur.SHOULD);

      qp = new QueryParser(luceneVersion, Lucene.body.name(), analyzer);
      qp.setAllowLeadingWildcard(true);
      query.add(qp.parse(text), Occur.SHOULD);

      qp = new QueryParser(luceneVersion, Lucene.content.name(), analyzer);
      qp.setAllowLeadingWildcard(true);
      query.add(qp.parse(text), Occur.SHOULD);

      IndexSearcher searcher = getSearcher();
      Query rewrittenQuery = searcher.rewrite(query);

      log.debug(rewrittenQuery.toString());
View Full Code Here

    }

    Set<QueryResult> results = new LinkedHashSet<QueryResult>();
    StandardAnalyzer analyzer = new StandardAnalyzer(luceneVersion);
    try {
      QueryParser qp = new QueryParser(luceneVersion, Lucene.content.name(), analyzer);
      Query query = qp.parse(queryText);

      IndexSearcher searcher = getSearcher();
      Query rewrittenQuery = searcher.rewrite(query);

      log.debug(rewrittenQuery.toString());
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.