org.apache.solr.request.LocalSolrQueryRequest Java Examples

The following examples show how to use org.apache.solr.request.LocalSolrQueryRequest. 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 File: SentryIndexAuthorizationSingleton.java    From incubator-sentry with Apache License 2.0 6 votes vote down vote up
/**
 * Get the user name associated with the request
 *
 * @param req the request
 * @return the user name associated with the request
 */
public String getUserName(SolrQueryRequest req) throws SolrException {
  if (binding == null) {
    throw new SolrException(SolrException.ErrorCode.UNAUTHORIZED,
      "Solr binding was not created successfully.  Defaulting to no access");
  }
  SolrCore solrCore = req.getCore();
  HttpServletRequest httpServletRequest = (HttpServletRequest)req.getContext().get("httpRequest");

  // LocalSolrQueryRequests won't have the HttpServletRequest because there is no
  // http request associated with it.
  if (httpServletRequest == null && !(req instanceof LocalSolrQueryRequest)) {
    StringBuilder builder = new StringBuilder("Unable to locate HttpServletRequest");
    if (solrCore != null && solrCore.getSolrConfig().getBool(
      "requestDispatcher/requestParsers/@addHttpRequestToContext", true) == false) {
      builder.append(", ensure requestDispatcher/requestParsers/@addHttpRequestToContext is set to true");
    }
    throw new SolrException(SolrException.ErrorCode.UNAUTHORIZED, builder.toString());
  }

  String superUser = System.getProperty("solr.authorization.superuser", "solr");
  // If a local request, treat it like a super user request; i.e. it is equivalent to an
  // http request from the same process.
  return req instanceof LocalSolrQueryRequest?
    superUser:(String)httpServletRequest.getAttribute(USER_NAME);
}
 
Example #2
Source File: SuggestionRequestHandlerTest.java    From vind with Apache License 2.0 6 votes vote down vote up
@Test
public void testFacetTypesSingle() {
    ModifiableSolrParams params = new ModifiableSolrParams();

    params.add(SuggestionRequestParams.SUGGESTION,"true");
    params.add(CommonParams.QT,"/suggester");
    params.add(CommonParams.Q,"s");
    params.add(SuggestionRequestParams.SUGGESTION_FIELD,"dynamic_multi_stored_suggest_analyzed_name");
    params.add(SuggestionRequestParams.SUGGESTION_FIELD,"dynamic_multi_stored_suggest_analyzed_place");

    SolrQueryRequest req = new LocalSolrQueryRequest( core, params );

    assertQ(req,
            "//response/lst[@name='suggestions']/int[@name='suggestion_count'][.='3']",
            "//response/lst[@name='suggestions']/lst[@name='suggestion_facets']/lst[@name='dynamic_multi_stored_suggest_analyzed_name']/int[@name='sebastian vettel'][.='2']",
            "//response/lst[@name='suggestions']/lst[@name='suggestion_facets']/lst[@name='dynamic_multi_stored_suggest_analyzed_name']/int[@name='stefan Bradl'][.='1']",
            "//response/lst[@name='suggestions']/lst[@name='suggestion_facets']/lst[@name='dynamic_multi_stored_suggest_analyzed_place']/int[@name='suzuka'][.='2']");

}
 
Example #3
Source File: AbstractXJoinTestCase.java    From BioSolr with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("rawtypes")
protected NamedList test(ModifiableSolrParams params, String componentName) {
  SolrCore core = h.getCore();

  SearchComponent sc = core.getSearchComponent(componentName);
  assertTrue("XJoinSearchComponent not found in solrconfig", sc != null);
    
  QParserPlugin qp = core.getQueryPlugin("xjoin");
  assertTrue("XJoinQParserPlugin not found in solrconfig", qp != null);
  
  params.add("q", "*:*");
  params.add("fq", "{!xjoin}" + componentName);

  SolrQueryResponse rsp = new SolrQueryResponse();
  rsp.add("responseHeader", new SimpleOrderedMap<>());
  SolrQueryRequest req = new LocalSolrQueryRequest(core, params);

  SolrRequestHandler handler = core.getRequestHandler("standard");
  handler.handleRequest(req, rsp);
  req.close();
  assertNull(rsp.getException());
    
  return rsp.getValues();
}
 
Example #4
Source File: SuggestionRequestHandlerTest.java    From vind with Apache License 2.0 6 votes vote down vote up
@Test
@Ignore //At the moment synonyms are not supported in suggestions
public void testSynonyms() {
    ModifiableSolrParams params = new ModifiableSolrParams();

    params.add(SuggestionRequestParams.SUGGESTION,"true");
    params.add(CommonParams.QT,"/suggester");
    params.add(CommonParams.Q,"xfighter");
    params.add(SuggestionRequestParams.SUGGESTION_FIELD,"dynamic_multi_stored_suggest_analyzed_name");

    SolrQueryRequest req = new LocalSolrQueryRequest( core, params );

    assertQ("suggester - test synonym mapping for single facet", req,
            "//response/lst[@name='suggestions']/int[@name='suggestion_count'][.='2']",
            "//response/lst[@name='suggestions']/lst[@name='suggestion_facets']/lst[@name='dynamic_multi_stored_suggest_analyzed_name']/int[@name='RBXF'][.='1']",
            "//response/lst[@name='suggestions']/lst[@name='suggestion_facets']/lst[@name='dynamic_multi_stored_suggest_analyzed_name']/int[@name='X-fighters'][.='1']");

    /* TODO does not work for multifacets
    params.add(SuggestionRequestParams.SUGGESTION_MULTIVALUE,"true");
    params.set(CommonParams.Q,"RB x-fighter");

    assertQ("suggester - test synonym mapping for multi facet",req,
            "//response/lst[@name='suggestions']/lst[@name='suggestion_facets']/lst[1]/int[@name='count'][.='2']");
    */
}
 
Example #5
Source File: DistributedUpdateProcessorTest.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Test
public void testVersionDelete() throws IOException {
  SolrQueryRequest req = new LocalSolrQueryRequest(h.getCore(), new ModifiableSolrParams());

  int threads = 5;
  Function<DistributedUpdateProcessor,Boolean> versionDeleteFunc = (DistributedUpdateProcessor process) -> {
    try {
      DeleteUpdateCommand cmd = new DeleteUpdateCommand(req);
      cmd.id = "1";
      return process.versionDelete(cmd);
    } catch (IOException e) {
      throw new RuntimeException(e);
    }
  };

  int succeeded = runCommands(threads, 1000, req, versionDeleteFunc);
  // only one should succeed
  assertThat(succeeded, is(1));

  succeeded = runCommands(threads, -1, req, versionDeleteFunc);
  // all should succeed
  assertThat(succeeded, is(threads));
}
 
Example #6
Source File: SuggestionRequestHandlerTest.java    From vind with Apache License 2.0 6 votes vote down vote up
@Test
public void sortingTest2() {
    ModifiableSolrParams params = new ModifiableSolrParams();

    params.add(SuggestionRequestParams.SUGGESTION,"true");
    params.add(CommonParams.QT,"/suggester");
    params.add(CommonParams.Q,"ku");
    params.add(SuggestionRequestParams.SUGGESTION_FIELD,"dynamic_multi_stored_suggest_analyzed_place");

    SolrQueryRequest req = new LocalSolrQueryRequest( core, params );

    assertQ("suggester - test single sorting for 'ku' with 2 facets", req,
            "//response/lst[@name='suggestions']/lst[@name='suggestion_facets']/lst[@name='dynamic_multi_stored_suggest_analyzed_place']/int[@name='kuala Lumpur'][.='2']",
            "//response/lst[@name='suggestions']/lst[@name='suggestion_facets']/lst[@name='dynamic_multi_stored_suggest_analyzed_place']/int[1][.='2']",
            "//response/lst[@name='suggestions']/lst[@name='suggestion_facets']/lst[@name='dynamic_multi_stored_suggest_analyzed_place']/int[@name='Havanna kuba'][.='1']");
}
 
Example #7
Source File: SuggestionRequestHandlerTest.java    From vind with Apache License 2.0 6 votes vote down vote up
@Test
public void fqParameterTest() {

    ModifiableSolrParams params = new ModifiableSolrParams();

    params.add(SuggestionRequestParams.SUGGESTION,"true");
    params.add(CommonParams.QT,"/suggester");
    params.add(CommonParams.Q,"sebastian");
    params.add(SuggestionRequestParams.SUGGESTION_FIELD,"dynamic_multi_stored_suggest_analyzed_name");
    params.add(CommonParams.FQ,"dynamic_multi_stored_suggest_analyzed_place:\"(1328869589310-619798898)\"");

    SolrQueryRequest req = new LocalSolrQueryRequest( core, params );

    assertQ("suggester - spellcheck suggestion for 'sepastian'",req,
            "//response/lst[@name='suggestions']/int[@name='suggestion_count'][.='1']",
            "//response/lst[@name='suggestions']/lst[@name='suggestion_facets']/lst[@name='dynamic_multi_stored_suggest_analyzed_name']/int[@name='sebastian vettel'][.='1']");

}
 
Example #8
Source File: BasicFunctionalityTest.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Test
@SuppressWarnings({"unchecked"})
public void testLocalSolrQueryRequestParams() {
  @SuppressWarnings({"rawtypes"})
  HashMap args = new HashMap();
  args.put("string", "string value");
  args.put("array", new String[] {"array", "value"});
  SolrQueryRequest req = new LocalSolrQueryRequest(null, null, null, 0, 20, args);
  assertEquals("string value", req.getParams().get("string"));
  assertEquals("array", req.getParams().get("array"));

  String[] stringParams = req.getParams().getParams("string");
  assertEquals(1, stringParams.length);
  assertEquals("string value", stringParams[0]);

  String[] arrayParams = req.getParams().getParams("array");
  assertEquals(2, arrayParams.length);
  assertEquals("array", arrayParams[0]);
  assertEquals("value", arrayParams[1]);
  req.close();
}
 
Example #9
Source File: AbstractXJoinTestCase.java    From BioSolr with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("rawtypes")
protected NamedList test(ModifiableSolrParams params, String componentName) {
  SolrCore core = h.getCore();

  SearchComponent sc = core.getSearchComponent(componentName);
  assertTrue("XJoinSearchComponent not found in solrconfig", sc != null);
    
  QParserPlugin qp = core.getQueryPlugin("xjoin");
  assertTrue("XJoinQParserPlugin not found in solrconfig", qp != null);
  
  params.add("q", "*:*");
  params.add("fq", "{!xjoin}" + componentName);

  SolrQueryResponse rsp = new SolrQueryResponse();
  rsp.add("responseHeader", new SimpleOrderedMap<>());
  SolrQueryRequest req = new LocalSolrQueryRequest(core, params);

  SolrRequestHandler handler = core.getRequestHandler("standard");
  handler.handleRequest(req, rsp);
  req.close();
  assertNull(rsp.getException());
    
  return rsp.getValues();
}
 
Example #10
Source File: IssueExampleTest.java    From vind with Apache License 2.0 6 votes vote down vote up
@Test
public void test_PSD_3756() {

    ModifiableSolrParams params = new ModifiableSolrParams();

    params.add(SuggestionRequestParams.SUGGESTION,"true");
    params.add(CommonParams.QT,"/suggester");
    params.add(CommonParams.Q,"The Real Dingo");
    params.add(SuggestionRequestParams.SUGGESTION_FIELD,"dynamic_multi_stored_suggest_analyzed_source");
    params.add(SuggestionRequestParams.SUGGESTION_DF,"suggestions");

    SolrQueryRequest req = new LocalSolrQueryRequest( core, params );

    assertQ("suggester - test path hierarchy", req,
            "//response/lst[@name='suggestions']/int[@name='suggestion_count'][.='1']",
            "//response/lst[@name='suggestions']/lst[@name='suggestion_facets']/lst[@name='dynamic_multi_stored_suggest_analyzed_source']/int[@name='The Real Dingo'][.='1']");

}
 
Example #11
Source File: IssueExampleTest.java    From vind with Apache License 2.0 6 votes vote down vote up
public void test_MBC_3646_1() {

        ModifiableSolrParams params = new ModifiableSolrParams();

        params.add(SuggestionRequestParams.SUGGESTION,"true");
        params.add(CommonParams.QT,"/suggester");
        params.add(CommonParams.Q,"MI123");
        params.add(SuggestionRequestParams.SUGGESTION_FIELD,"dynamic_multi_stored_suggest_analyzed_id");
        params.add(SuggestionRequestParams.SUGGESTION_DF,"suggestions");

        SolrQueryRequest req = new LocalSolrQueryRequest( core, params );

        assertQ("suggester - test number search without result", req,
                "//response/lst[@name='suggestions']/int[@name='suggestion_count'][.='1']",
                "//response/lst[@name='suggestions']/lst[@name='suggestion_facets']/lst[@name='dynamic_multi_stored_suggest_analyzed_id']/int[@name='MI123-456-789'][.='1']");
    }
 
Example #12
Source File: IssueExampleTest.java    From vind with Apache License 2.0 6 votes vote down vote up
public void test_MBC_3646_2() {

        ModifiableSolrParams params = new ModifiableSolrParams();

        params.add(SuggestionRequestParams.SUGGESTION,"true");
        params.add(CommonParams.QT,"/suggester");
        params.add(CommonParams.Q,"MI123-456-788");
        params.add(CommonParams.FQ,"dynamic_multi_stored_suggest_analyzed_id:MI123-456-788"); //filter for non existing facet -> no suggestion should be returned
        params.add(SuggestionRequestParams.SUGGESTION_FIELD,"dynamic_multi_stored_suggest_analyzed_id");
        params.add(SuggestionRequestParams.SUGGESTION_DF,"suggestions");

        SolrQueryRequest req = new LocalSolrQueryRequest( core, params );

        assertQ("suggester - test number search without result", req,
                "not(//response/lst[@name='spellcheck'])");
    }
 
Example #13
Source File: SuggestionRequestHandlerTest.java    From vind with Apache License 2.0 6 votes vote down vote up
@Test
public void spellcheckSuggestionTest() {

    ModifiableSolrParams params = new ModifiableSolrParams();

    params.add(SuggestionRequestParams.SUGGESTION,"true");
    params.add(CommonParams.QT,"/suggester");
    params.add(CommonParams.Q,"sepastian");
    params.add(SuggestionRequestParams.SUGGESTION_FIELD,"dynamic_multi_stored_suggest_analyzed_name");
    params.add(SuggestionRequestParams.SUGGESTION_DF,"suggestions");

    SolrQueryRequest req = new LocalSolrQueryRequest( core, params );

    assertQ("suggester - spellcheck suggestion for 'sepastian'",req,
            "//response/lst[@name='suggestions']/int[@name='suggestion_count'][.='1']",
            "//response/lst[@name='suggestions']/lst[@name='suggestion_facets']/lst[@name='dynamic_multi_stored_suggest_analyzed_name']/int[@name='sebastian vettel'][.='2']",
            "//response/lst[@name='spellcheck']/lst[@name='collations']/str[@name='collation'][.='sebastian']");

}
 
Example #14
Source File: DistributedUpdateProcessorTest.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Test
public void testShouldBufferUpdateZk() throws IOException {
  SolrQueryRequest req = new LocalSolrQueryRequest(h.getCore(), new ModifiableSolrParams());
  try (DistributedUpdateProcessor processor = new DistributedUpdateProcessor(
      req, null, null, null)) {
    AddUpdateCommand cmd = new AddUpdateCommand(req);
    // applying buffer updates, isReplayOrPeerSync flag doesn't matter
    assertFalse(processor.shouldBufferUpdate(cmd, false, UpdateLog.State.APPLYING_BUFFERED));
    assertFalse(processor.shouldBufferUpdate(cmd, true, UpdateLog.State.APPLYING_BUFFERED));

    assertTrue(processor.shouldBufferUpdate(cmd, false, UpdateLog.State.BUFFERING));
    // this is not an buffer updates and it depend on other updates
    cmd.prevVersion = 10;
    assertTrue(processor.shouldBufferUpdate(cmd, false, UpdateLog.State.APPLYING_BUFFERED));
  }
}
 
Example #15
Source File: AbstractXJoinTestCase.java    From BioSolr with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("rawtypes")
protected NamedList test(ModifiableSolrParams params, String componentName) {
  SolrCore core = h.getCore();

  SearchComponent sc = core.getSearchComponent(componentName);
  assertTrue("XJoinSearchComponent not found in solrconfig", sc != null);
    
  QParserPlugin qp = core.getQueryPlugin("xjoin");
  assertTrue("XJoinQParserPlugin not found in solrconfig", qp != null);
  
  params.add("q", "*:*");
  params.add("fq", "{!xjoin}" + componentName);

  SolrQueryResponse rsp = new SolrQueryResponse();
  rsp.add("responseHeader", new SimpleOrderedMap<>());
  SolrQueryRequest req = new LocalSolrQueryRequest(core, params);

  SolrRequestHandler handler = core.getRequestHandler("standard");
  handler.handleRequest(req, rsp);
  req.close();
  assertNull(rsp.getException());
    
  return rsp.getValues();
}
 
Example #16
Source File: IgnoreCommitOptimizeUpdateProcessorFactoryTest.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
SolrQueryResponse processCommit(final String chain, boolean optimize, Boolean commitEndPoint) throws IOException {
  SolrCore core = h.getCore();
  UpdateRequestProcessorChain pc = core.getUpdateProcessingChain(chain);
  assertNotNull("No Chain named: " + chain, pc);

  SolrQueryResponse rsp = new SolrQueryResponse();
  SolrQueryRequest req = new LocalSolrQueryRequest(core, new ModifiableSolrParams());

  if (commitEndPoint != null) {
    ((ModifiableSolrParams)req.getParams()).set(
        DistributedUpdateProcessor.COMMIT_END_POINT, commitEndPoint.booleanValue());
  }

  try {
    SolrRequestInfo.setRequestInfo(new SolrRequestInfo(req,rsp));
    CommitUpdateCommand cmd = new CommitUpdateCommand(req, false);
    cmd.optimize = optimize;
    UpdateRequestProcessor processor = pc.createProcessor(req, rsp);
    processor.processCommit(cmd);
  } finally {
    SolrRequestInfo.clearRequestInfo();
    req.close();
  }
  return rsp;
}
 
Example #17
Source File: MoreLikeThisComponentTest.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Test
public void testMLT_baseParamsInterestingTermsList_shouldReturnSimilarDocumentsAndInterestingTermsList()
{
  SolrCore core = h.getCore();
  ModifiableSolrParams params = new ModifiableSolrParams();

  initCommonMoreLikeThisParams(params);
  params.set(MoreLikeThisParams.INTERESTING_TERMS, "list");

  params.set(CommonParams.Q, "id:42");
  SolrQueryRequest mltreq = new LocalSolrQueryRequest( core, params);
  assertQ("morelikethis - tom cruise",mltreq
      ,"//result/doc[1]/str[@name='id'][.='46']"
      ,"//result/doc[2]/str[@name='id'][.='43']",
      "//lst[@name='interestingTerms']/arr[@name='42'][count(*)>0]",
      "//lst[@name='interestingTerms']/arr[@name='42']/str[.='name:Cruise']");
  mltreq.close();
}
 
Example #18
Source File: AtomicUpdateProcessorFactoryTest.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
public void testNoUniqueIdPassed() throws Exception { //TODO
  ModifiableSolrParams params = new ModifiableSolrParams()
      .add("processor", "atomic")
      .add("atomic.cat", "add")
      .add("commit", "true");
  try (SolrQueryRequest req = new LocalSolrQueryRequest(h.getCore(), params)) {
    AddUpdateCommand cmd = new AddUpdateCommand(req);
    cmd.solrDoc = new SolrInputDocument();
    cmd.solrDoc.addField("title", 1);
    AtomicUpdateProcessorFactory factory = new AtomicUpdateProcessorFactory();
    factory.inform(h.getCore());
    factory.getInstance(cmd.getReq(), new SolrQueryResponse(),
        null).processAdd(cmd);
  } catch (SolrException e) {
    assertEquals("Document passed with no unique field: 'id'", e.getMessage());
  }
}
 
Example #19
Source File: AtomicUpdateProcessorFactoryTest.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
public void testWrongAtomicOpPassed() throws Exception {
  ModifiableSolrParams params = new ModifiableSolrParams()
      .add("processor", "Atomic")
      .add("atomic.cat", "delete")
      .add("commit", "true");
  try (SolrQueryRequest req = new LocalSolrQueryRequest(h.getCore(), params)) {
    AddUpdateCommand cmd = new AddUpdateCommand(req);
    AtomicUpdateProcessorFactory factory = new AtomicUpdateProcessorFactory();
    factory.inform(h.getCore());
    factory.getInstance(cmd.getReq(), new SolrQueryResponse(),
        null).processAdd(cmd);
  } catch (SolrException e) {
    assertEquals("Unexpected param(s) for AtomicUpdateProcessor, invalid atomic op passed: 'delete'",
        e.getMessage());
  }
}
 
Example #20
Source File: UpdateProcessorTestBase.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
protected void processCommit(final String chain) throws IOException {
  SolrCore core = h.getCore();
  UpdateRequestProcessorChain pc = core.getUpdateProcessingChain(chain);
  assertNotNull("No Chain named: " + chain, pc);

  SolrQueryResponse rsp = new SolrQueryResponse();

  SolrQueryRequest req = new LocalSolrQueryRequest(core, new ModifiableSolrParams());

  CommitUpdateCommand cmd = new CommitUpdateCommand(req,false);
  UpdateRequestProcessor processor = pc.createProcessor(req, rsp);
  try {
    processor.processCommit(cmd);
  } finally {
    req.close();
  }
}
 
Example #21
Source File: UpdateProcessorTestBase.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
protected void processDeleteById(final String chain, String id) throws IOException {
  SolrCore core = h.getCore();
  UpdateRequestProcessorChain pc = core.getUpdateProcessingChain(chain);
  assertNotNull("No Chain named: " + chain, pc);

  SolrQueryResponse rsp = new SolrQueryResponse();

  SolrQueryRequest req = new LocalSolrQueryRequest(core, new ModifiableSolrParams());

  DeleteUpdateCommand cmd = new DeleteUpdateCommand(req);
  cmd.setId(id);
  UpdateRequestProcessor processor = pc.createProcessor(req, rsp);
  try {
    processor.processDelete(cmd);
  } finally {
    req.close();
  }
}
 
Example #22
Source File: UpdateProcessorTestBase.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
protected void finish(final String chain) throws IOException {
  SolrCore core = h.getCore();
  UpdateRequestProcessorChain pc = core.getUpdateProcessingChain(chain);
  assertNotNull("No Chain named: " + chain, pc);

  SolrQueryResponse rsp = new SolrQueryResponse();
  SolrQueryRequest req = new LocalSolrQueryRequest(core, new ModifiableSolrParams());

  UpdateRequestProcessor processor = pc.createProcessor(req, rsp);
  try {
    processor.finish();
  } finally {
    IOUtils.closeQuietly(processor);
    req.close();
  }
}
 
Example #23
Source File: SolrFeature.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
private LocalSolrQueryRequest makeRequest(SolrCore core, String solrQuery,
    List<String> fqs, String df) {
  final NamedList<String> returnList = new NamedList<String>();
  if ((solrQuery != null) && !solrQuery.isEmpty()) {
    returnList.add(CommonParams.Q, solrQuery);
  }
  if (fqs != null) {
    for (final String fq : fqs) {
      returnList.add(CommonParams.FQ, fq);
    }
  }
  if ((df != null) && !df.isEmpty()) {
    returnList.add(CommonParams.DF, df);
  }
  if (returnList.size() > 0) {
    return new LocalSolrQueryRequest(core, returnList);
  } else {
    return null;
  }
}
 
Example #24
Source File: UUIDUpdateProcessorFallbackTest.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
public void testProcessorPrefixReqParam() throws Exception {
  List<UpdateRequestProcessorFactory> processors = UpdateRequestProcessorChain.getReqProcessors("uuid", h.getCore());
  UpdateRequestProcessorFactory processorFactory = processors.get(0);
  assertTrue(processorFactory instanceof UUIDUpdateProcessorFactory);

  SolrQueryResponse rsp = new SolrQueryResponse();
  SolrQueryRequest req = new LocalSolrQueryRequest(h.getCore(), new ModifiableSolrParams());
  AddUpdateCommand cmd = new AddUpdateCommand(req);
  cmd.solrDoc = new SolrInputDocument();
  cmd.solrDoc.addField("random_s", "random_val");

  processorFactory.getInstance(req, rsp, null).processAdd(cmd);
  assertNotNull(cmd.solrDoc);
  assertNotNull(cmd.solrDoc.get("id"));
  assertNotNull(cmd.solrDoc.get("id").getValue());
}
 
Example #25
Source File: MoreLikeThisComponentTest.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Test
public void testMLT_baseParamsInterestingTermsDetails_shouldReturnSimilarDocumentsAndInterestingTermsDetails()
{
  SolrCore core = h.getCore();
  ModifiableSolrParams params = new ModifiableSolrParams();

  initCommonMoreLikeThisParams(params);
  params.set(MoreLikeThisParams.INTERESTING_TERMS, "details");
  
  params.set(CommonParams.Q, "id:42");
  SolrQueryRequest mltreq = new LocalSolrQueryRequest( core, params);
  assertQ("morelikethis - tom cruise",mltreq
      ,"//result/doc[1]/str[@name='id'][.='46']"
      ,"//result/doc[2]/str[@name='id'][.='43']",
      "//lst[@name='interestingTerms']/lst[1][count(*)>0]",
      "//lst[@name='interestingTerms']/lst[1]/float[.=1.0]");
  mltreq.close();
}
 
Example #26
Source File: KnowledgeGraphResponseWriterTest.java    From semantic-knowledge-graph with Apache License 2.0 6 votes vote down vote up
@Before
public void init()
{

    new MockUp<SolrQueryResponse>()
    {
        @Mock public NamedList<Object> getResponseHeader()
        {
            NamedList<Object> headers = new NamedList<>();
            headers.add("status", 400);
            return headers;
        }
    };
    request = new LocalSolrQueryRequest(null, dummy);
    response = new SolrQueryResponse();
    response.setHttpHeader("status", "400");
}
 
Example #27
Source File: TestZKPropertiesWriter.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
/**
 * Code copied with some adaptations from {@link org.apache.solr.util.TestHarness.LocalRequestFactory#makeRequest(String...)}.
 */
@SuppressWarnings({"unchecked"})
private static LocalSolrQueryRequest localMakeRequest(SolrCore core, String ... q) {
  if (q.length==1) {
    Map<String, String> args = new HashMap<>();
    args.put(CommonParams.VERSION,"2.2");

    return new LocalSolrQueryRequest(core, q[0], "", 0, 20, args);
  }
  if (q.length%2 != 0) {
    throw new RuntimeException("The length of the string array (query arguments) needs to be even");
  }
  @SuppressWarnings({"rawtypes"})
  Map.Entry<String, String> [] entries = new NamedList.NamedListEntry[q.length / 2];
  for (int i = 0; i < q.length; i += 2) {
    entries[i/2] = new NamedList.NamedListEntry<>(q[i], q[i+1]);
  }
  @SuppressWarnings({"rawtypes"})
  NamedList nl = new NamedList(entries);
  if(nl.get("wt" ) == null) nl.add("wt","xml");
  return new LocalSolrQueryRequest(core, nl);
}
 
Example #28
Source File: StatelessScriptUpdateProcessorFactory.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Override
public void inform(SolrCore core) {
  if (!core.getCoreDescriptor().isConfigSetTrusted()) {
    throw new SolrException(ErrorCode.UNAUTHORIZED, "The configset for this collection was uploaded without any authentication in place,"
        + " and this operation is not available for collections with untrusted configsets. To use this component, re-upload the configset"
        + " after enabling authentication and authorization.");
  }
  resourceLoader = core.getResourceLoader();

  // test that our engines & scripts are valid

  SolrQueryResponse rsp = new SolrQueryResponse();
  SolrQueryRequest req = new LocalSolrQueryRequest(core, new ModifiableSolrParams());
  try {
    initEngines(req, rsp);
  } catch (Exception e) {
    String msg = "Unable to initialize scripts: " + e.getMessage();
    log.error(msg, e);
    throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, msg, e);
  } finally {
    req.close();
  }

  
}
 
Example #29
Source File: IssueExampleTest.java    From vind with Apache License 2.0 6 votes vote down vote up
/**
 * Tests MBC-1203 (Static synonyms)
 * Attention! To enable this, make sure that you use the WhiteSpaceTokenizer (for query and index).
 */
@Test
@Ignore //At the moment synonyms are not supported in suggestions
public void testSynonymes() {

    ModifiableSolrParams params = new ModifiableSolrParams();

    params.add(SuggestionRequestParams.SUGGESTION, "true");
    params.add(CommonParams.QT,"/suggester");
    params.add(CommonParams.Q, "xalps");
    params.add(SuggestionRequestParams.SUGGESTION_FIELD, "dynamic_multi_stored_suggest_analyzed_name");
    params.add(SuggestionRequestParams.SUGGESTION_DF, "suggestions");

    SolrQueryRequest req = new LocalSolrQueryRequest( core, params );

    assertQ("suggester - test synonym mapping for single facet",req,
            "//response/lst[@name='suggestions']/int[@name='suggestion_count'][.='2']",
            "//response/lst[@name='suggestions']/lst[@name='suggestion_facets']/lst[@name='dynamic_multi_stored_suggest_analyzed_name']/int[@name='X-Alps'][.='1']",
            "//response/lst[@name='suggestions']/lst[@name='suggestion_facets']/lst[@name='dynamic_multi_stored_suggest_analyzed_name']/int[@name='My xa'][.='1']");
}
 
Example #30
Source File: HttpSolrCall.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
protected void autoCreateSystemColl(String corename) throws Exception {
  if (core == null &&
      SYSTEM_COLL.equals(corename) &&
      "POST".equals(req.getMethod()) &&
      !cores.getZkController().getClusterState().hasCollection(SYSTEM_COLL)) {
    log.info("Going to auto-create {} collection", SYSTEM_COLL);
    SolrQueryResponse rsp = new SolrQueryResponse();
    String repFactor = String.valueOf(Math.min(3, cores.getZkController().getClusterState().getLiveNodes().size()));
    cores.getCollectionsHandler().handleRequestBody(new LocalSolrQueryRequest(null,
        new ModifiableSolrParams()
            .add(ACTION, CREATE.toString())
            .add( NAME, SYSTEM_COLL)
            .add(REPLICATION_FACTOR, repFactor)), rsp);
    if (rsp.getValues().get("success") == null) {
      throw new SolrException(ErrorCode.SERVER_ERROR, "Could not auto-create " + SYSTEM_COLL + " collection: "+ Utils.toJSONString(rsp.getValues()));
    }
    TimeOut timeOut = new TimeOut(3, TimeUnit.SECONDS, TimeSource.NANO_TIME);
    for (; ; ) {
      if (cores.getZkController().getClusterState().getCollectionOrNull(SYSTEM_COLL) != null) {
        break;
      } else {
        if (timeOut.hasTimedOut()) {
          throw new SolrException(ErrorCode.SERVER_ERROR, "Could not find " + SYSTEM_COLL + " collection even after 3 seconds");
        }
        timeOut.sleep(50);
      }
    }

    action = RETRY;
  }
}