Package org.apache.solr.request

Examples of org.apache.solr.request.SolrQueryRequest


    assertU(adoc("id","1", "v_t","Hello Dude", "v_s","string1"));
    assertU(adoc("id","2", "v_t","Hello Yonik", "v_s","string2"));
    assertU(commit());

    SolrQueryRequest sr1 = req("q","foo");
    SolrIndexReader r1 = sr1.getSearcher().getReader();

    String sval1 = getStringVal(sr1, "v_s",0);
    assertEquals("string1", sval1);

    assertU(adoc("id","3", "v_s","{!literal}"));
    assertU(adoc("id","4", "v_s","other stuff"));
    assertU(commit());

    SolrQueryRequest sr2 = req("q","foo");
    SolrIndexReader r2 = sr2.getSearcher().getReader();

    // make sure the readers share the first segment
    // Didn't work w/ older versions of lucene2.9 going from segment -> multi
    assertEquals(r1.getLeafReaders()[0], r2.getLeafReaders()[0]);

    // make sure the String returned is the exact same instance (i.e. same FieldCache instance)
    assertTrue(sval1 == getStringVal(sr2,"v_s",0));

    assertU(adoc("id","5", "v_f","3.14159"));
    assertU(adoc("id","6", "v_f","8983", "v_s","string6"));
    assertU(commit());

    SolrQueryRequest sr3 = req("q","foo");
    SolrIndexReader r3 = sr3.getSearcher().getReader();
    // make sure the readers share segments
    // assertEquals(r1.getLeafReaders()[0], r3.getLeafReaders()[0]);
    assertEquals(r2.getLeafReaders()[0], r3.getLeafReaders()[0]);
    assertEquals(r2.getLeafReaders()[1], r3.getLeafReaders()[1]);

    sr1.close();
    sr2.close();           

    // should currently be 1, but this could change depending on future index management
    int baseRefCount = r3.getRefCount();
    assertEquals(1, baseRefCount);

    assertU(commit());
    SolrQueryRequest sr4 = req("q","foo");
    SolrIndexReader r4 = sr4.getSearcher().getReader();

    // force an index change so the registered searcher won't be the one we are testing (and
    // then we should be able to test the refCount going all the way to 0
    assertU(adoc("id","7", "v_f","7574"));
    assertU(commit());

    // test that reader didn't change (according to equals at least... which uses the wrapped reader)
    assertEquals(r3,r4);
    assertEquals(baseRefCount+1, r4.getRefCount());
    sr3.close();
    assertEquals(baseRefCount, r4.getRefCount());
    sr4.close();
    assertEquals(baseRefCount-1, r4.getRefCount());


    SolrQueryRequest sr5 = req("q","foo");
    SolrIndexReader r5 = sr5.getSearcher().getReader();
    String beforeDelete = getStringVal(sr5, "v_s",1);

    assertU(delI("1"));
    assertU(commit());
    SolrQueryRequest sr6 = req("q","foo");
    SolrIndexReader r6 = sr4.getSearcher().getReader();
    assertEquals(1, r6.getLeafReaders()[0].numDocs()); // only a single doc left in the first segment
    assertTrue( !r5.getLeafReaders()[0].equals(r6.getLeafReaders()[0]) )// readers now different
    String afterDelete = getStringVal(sr6, "v_s",1);
    assertTrue( beforeDelete == afterDelete )// same field cache is used even though deletions are different

    sr5.close();
    sr6.close();
  }
View Full Code Here


    assertU(commit());
   
    Map<String,String> args = new HashMap<String, String>();
    args.put( CommonParams.Q, "title:test" );
    args.put( "indent", "true" );
    SolrQueryRequest req = new LocalSolrQueryRequest( core, new MapSolrParams( args) );
   
    assertQ("Make sure they got in", req
            ,"//*[@numFound='1']"
            ,"//result/doc[1]/int[@name='id'][.='10']"
            );
View Full Code Here

    assertU(adoc("id", "10", "title", "test", fieldName, "aaa"));
    assertU(commit());

    SolrQuery query = new SolrQuery( fieldName+":aaa" );
    query.set( "indent", "true" );
    SolrQueryRequest req = new LocalSolrQueryRequest( core, query );
   
    assertQ("Make sure they got in", req
            ,"//*[@numFound='1']"
            ,"//result/doc[1]/int[@name='id'][.='10']"
            );
View Full Code Here

    args.put(CommonParams.Q, "lowerfilt:lazy lowerfilt:brown");
    args.put(CommonParams.QT, "spellCheckCompRH");
    args.put(SpellCheckComponent.SPELLCHECK_BUILD, "true");
    args.put(SpellCheckComponent.SPELLCHECK_EXTENDED_RESULTS, "true");
    args.put(SpellCheckComponent.COMPONENT_NAME, "true");
    SolrQueryRequest req = new LocalSolrQueryRequest(core, new MapSolrParams(
            args));

    assertQ("Make sure correct spellings are signalled in the response", req,
            "//*[@numFound='1']", "//result/doc[1]/int[@name='id'][.='1']",
            "//*/lst[@name='suggestions']");
 
View Full Code Here

    args.put(CommonParams.Q, "test");
    args.put(CommonParams.QT, "spellCheckCompRH");
    args.put(SpellCheckComponent.SPELLCHECK_BUILD, "true");
    args.put(SpellCheckComponent.COMPONENT_NAME, "true");
    SolrQueryRequest req = new LocalSolrQueryRequest(core, new MapSolrParams(
        args));

    File indexDir = new File(core.getDataDir() + File.separator
        + "spellchecker1");
    assertTrue(
View Full Code Here

  }
 
  public void testReloadOnStart() throws Exception {
    assertU(adoc("id", "0", "lowerfilt", "This is a title"));
    assertU(commit());
    SolrQueryRequest request = req("qt", "spellCheckCompRH", "q", "*:*",
        "spellcheck.q", "ttle", "spellcheck", "true", "spellcheck.dictionary",
        "default", "spellcheck.build", "true");
    assertQ(request, "//arr[@name='suggestion'][.='title']");

    NamedList args = new NamedList();
View Full Code Here

    }
  }
 
    @SuppressWarnings("unchecked")
  public void testRebuildOnCommit() throws Exception {
    SolrQueryRequest req = req("q", "lowerfilt:lucenejavt", "qt", "spellCheckCompRH", "spellcheck", "true");
    String response = h.query(req);
    assertFalse("No suggestions should be returned", response.contains("lucenejava"));
   
    assertU(adoc("id", "11231", "lowerfilt", "lucenejava"));
    assertU("commit", commit());
View Full Code Here

      core.close();
      throw new SolrException( SolrException.ErrorCode.BAD_REQUEST, "unknown handler: "+path );
    }

    try {
      SolrQueryRequest req = _parser.buildRequestFrom( core, params, request.getContentStreams() );
      req.getContext().put( "path", path );
      SolrQueryResponse rsp = new SolrQueryResponse();
      core.execute( handler, req, rsp );
      if( rsp.getException() != null ) {
        throw new SolrServerException( rsp.getException() );
      }
     
      // Now write it out
      NamedList<Object> normalized = getParsedResponse(req, rsp);
      req.close();
      return normalized;
    }
    catch( IOException iox ) {
      throw iox;
    }
View Full Code Here

    List<ContentStream> streams = new ArrayList<ContentStream>( 1 );
    if( body != null && body.length() > 0 ) {
      streams.add( new ContentStreamBase.StringStream( body ) );
    }
   
    SolrQueryRequest req = null;
    try {
      req = parser.buildRequestFrom( core, params, streams );
      SolrQueryResponse rsp = new SolrQueryResponse();
      core.execute( handler, req, rsp );
      if( rsp.getException() != null ) {
        throw rsp.getException();
      }
     
      // Now write it out
      QueryResponseWriter responseWriter = core.getQueryResponseWriter(req);
      StringWriter out = new StringWriter();
      responseWriter.write(out, req, rsp);
      return out.toString();
    } finally {
      if (req != null) {
        req.close();
      }
    }
  }
View Full Code Here

    // TODO -- in the future, we could pick a different parser based on the request
   
    // Pick the parser from the request...
    ArrayList<ContentStream> streams = new ArrayList<ContentStream>(1);
    SolrParams params = parser.parseParamsAndFillStreams( req, streams );
    SolrQueryRequest sreq = buildRequestFrom( core, params, streams );

    // Handlers and login will want to know the path. If it contains a ':'
    // the handler could use it for RESTful URLs
    sreq.getContext().put( "path", path );
    return sreq;
  }
View Full Code Here

TOP

Related Classes of org.apache.solr.request.SolrQueryRequest

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.