org.apache.solr.request.SolrQueryRequest Java Examples
The following examples show how to use
org.apache.solr.request.SolrQueryRequest.
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: InfoLoggingTest.java From querqy with Apache License 2.0 | 6 votes |
@Test public void testThatLogPropertyIsReturnedEvenIfIdIsConfigured() { String q = "k"; SolrQueryRequest req = req("q", q, DisMaxParams.QF, "f1 f2 f3", QuerqyDismaxParams.INFO_LOGGING, "on", "defType", "querqy" ); assertQ("Log not returned if ID is configured", req, "//lst[@name='querqy.infoLog']/arr[@name='common1']/lst/arr[@name='APPLIED_RULES']/" + "str[text() = 'LOG for k']", "count(//lst[@name='querqy.infoLog']/arr[@name='common1']/lst/arr[@name='APPLIED_RULES']/" + "str) = 1" ); req.close(); }
Example #2
Source File: InfoLoggingTest.java From querqy with Apache License 2.0 | 6 votes |
public void testThatLogOutputIsTurnedOffByDefault() { String q = "k"; SolrQueryRequest req = req("q", q, DisMaxParams.QF, "f1 f2 f3", "defType", "querqy" ); assertQ("Logging multiple logs for same input false", req, "count(//lst[@name='querqy.infoLog']/arr) = 0" ); req.close(); }
Example #3
Source File: SuggestionRequestHandlerTest.java From vind with Apache License 2.0 | 6 votes |
@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 #4
Source File: DefaultQuerqyDismaxQParserWithCommonRulesGZIPTest.java From querqy with Apache License 2.0 | 6 votes |
@Test public void testSolrFilterQuery() { String q = "a k"; SolrQueryRequest req = req("q", q, DisMaxParams.QF, "f1 f2 f3", DisMaxParams.MM, "1", QueryParsing.OP, "OR", "defType", "querqy" ); assertQ("Solr filter query fails", req, "//result[@name='response' and @numFound='1']" ); req.close(); }
Example #5
Source File: BasicFunctionalityTest.java From lucene-solr with Apache License 2.0 | 6 votes |
@Test public void testNotLazyField() throws IOException { assertU(adoc("id", "7777", "title", "keyword", "test_hlt", mkstr(20000))); assertU(commit()); SolrCore core = h.getCore(); SolrQueryRequest req = req("q", "id:7777", "fl", "id,title,test_hlt"); SolrQueryResponse rsp = new SolrQueryResponse(); core.execute(core.getRequestHandler(req.getParams().get(CommonParams.QT)), req, rsp); DocList dl = ((ResultContext) rsp.getResponse()).getDocList(); Document d = req.getSearcher().doc(dl.iterator().nextDoc()); // ensure field in fl is not lazy assertFalse( ((Field) d.getField("test_hlt")).getClass().getSimpleName().equals("LazyField")); assertFalse( ((Field) d.getField("title")).getClass().getSimpleName().equals("LazyField")); req.close(); }
Example #6
Source File: CommonRulesDeleteLastTermTest.java From querqy with Apache License 2.0 | 6 votes |
@Test public void testThatMatchAllQueryIsAppliedIfQueryContainsBoostUpQueryAndHasNoTerm() { String q = "d"; SolrQueryRequest req = req("q", q, DisMaxParams.QF, "f1", "debugQuery", "on", "defType", "querqy"); assertQ("", req, "//result[@name='response' and @numFound='4']" ); req.close(); }
Example #7
Source File: NeedsScoresTest.java From querqy with Apache License 2.0 | 6 votes |
@Test public void testBoostIsAddedForNeedsScoresTrue() { String q = "qup"; SolrQueryRequest req = req("q", q, DisMaxParams.QF, "f1 f2", QueryParsing.OP, "OR", NEEDS_SCORES, "true", "defType", "querqy", "debugQuery", "true" ); assertQ("Boost not added", req, "//result[@name='response'][@numFound='2']", // the parsed query must contain the boost terms: "//str[@name='parsedquery'][contains(.,'f1:u100')]", "//str[@name='parsedquery'][contains(.,'f2:u100')]", "//str[@name='parsedquery'][not(contains(.,'ConstantScore'))]"); req.close(); }
Example #8
Source File: DefaultQuerqyDismaxQParserWithCommonRulesTest.java From querqy with Apache License 2.0 | 6 votes |
@Test public void testThatNegativeRawQueryFilterIsApplied() { String q = "qnegraw2"; SolrQueryRequest req = req("q", q, DisMaxParams.QF, "f1 f2 f3", "defType", "querqy", "echoParams", "all", "debugQuery", "on" ); assertQ("Purely negative filter fails for raw query", req, "//result[@name='response' and @numFound='1']/doc[1]/str[@name='id'][text()='11']" ); req.close(); }
Example #9
Source File: SolrInformationServer.java From SearchServices with GNU Lesser General Public License v3.0 | 6 votes |
@Override public AclChangeSet getMaxAclChangeSetIdAndCommitTimeInIndex() { try (SolrQueryRequest request = newSolrQueryRequest()) { SolrDocument aclState = getState(core, request, "TRACKER!STATE!ACLTX"); if (aclState != null) { long id = this.getFieldValueLong(aclState, FIELD_S_ACLTXID); long commitTime = this.getFieldValueLong(aclState, FIELD_S_ACLTXCOMMITTIME); int aclCount = -1; // Irrelevant for this method return new AclChangeSet(id, commitTime, aclCount); } return new AclChangeSet(0, 0, -1); } }
Example #10
Source File: QuerqyDismaxQParserWithSolrSynonymsTest.java From querqy with Apache License 2.0 | 6 votes |
@Test public void testThatPF23FWorksWithSynonymRewriting() { SolrQueryRequest req = req("q", "a b c d", DisMaxParams.QF, "f1 f2^0.9", DisMaxParams.PF2, "f1~2^2.1", DisMaxParams.PF3, "f2~3^3.9", "defType", "querqy", "debugQuery", "true"); assertQ("ps2/3 with synonyms not working", req, "//str[@name='parsedquery'][contains(.,'(f1:\"a b\"~2 f1:\"b c\"~2 f1:\"c d\"~2)^2.1')]", "//str[@name='parsedquery'][contains(.,'f2:\"a b c\"~3 f2:\"b c d\"~3)^3.9')]"); req.close(); }
Example #11
Source File: RangeFacet.java From lucene-solr with Apache License 2.0 | 6 votes |
@Override public void createFacetValueExecuters(final Filter filter, SolrQueryRequest queryRequest, Consumer<FacetValueQueryExecuter> consumer) { // Computes the end points of the ranges in the rangeFacet final FacetRangeGenerator<? extends Comparable<?>> rec = FacetRangeGenerator.create(this); final SchemaField sf = field; // Create a rangeFacetAccumulator for each range and // collect the documents for that range. for (FacetRange range : rec.getRanges()) { Query q = sf.getType().getRangeQuery(null, sf, range.lower, range.upper, range.includeLower,range.includeUpper); // The searcher sends docIds to the RangeFacetAccumulator which forwards // them to <code>collectRange()</code> in this class for collection. Query rangeQuery = QueryUtils.combineQueryAndFilter(q, filter); ReductionDataCollection dataCol = collectionManager.newDataCollection(); reductionData.put(range.toString(), dataCol); consumer.accept(new FacetValueQueryExecuter(dataCol, rangeQuery)); } }
Example #12
Source File: TestXJoinValueSourceParser.java From BioSolr with Apache License 2.0 | 6 votes |
@BeforeClass public static void initialise() throws Exception { SolrCore core = h.getCore(); XJoinSearchComponent xjsc = (XJoinSearchComponent)core.getSearchComponent(componentName); DummyXJoinResultsFactory xjrf = (DummyXJoinResultsFactory)xjsc.getResultsFactory(); XJoinResults<?> results = xjrf.getResults(null); // mock SolrQueryRequest with join results in the context sqr = mock(SolrQueryRequest.class); Map<Object, Object> context = new HashMap<>(); context.put(xjsc.getResultsTag(), results); when(sqr.getContext()).thenReturn(context); when(sqr.getCore()).thenReturn(core); searcher = core.getRegisteredSearcher().get(); missingDoc = new Integer(xjrf.getMissingId()); }
Example #13
Source File: ExtractingDocumentLoader.java From lucene-solr with Apache License 2.0 | 6 votes |
public ExtractingDocumentLoader(SolrQueryRequest req, UpdateRequestProcessor processor, TikaConfig config, ParseContextConfig parseContextConfig, SolrContentHandlerFactory factory) { this.params = req.getParams(); this.core = req.getCore(); this.config = config; this.parseContextConfig = parseContextConfig; this.processor = processor; templateAdd = new AddUpdateCommand(req); templateAdd.overwrite = params.getBool(UpdateParams.OVERWRITE, true); templateAdd.commitWithin = params.getInt(UpdateParams.COMMIT_WITHIN, -1); //this is lightweight autoDetectParser = new AutoDetectParser(config); this.factory = factory; ignoreTikaException = params.getBool(ExtractingParams.IGNORE_TIKA_EXCEPTION, false); }
Example #14
Source File: JoinQParserPlugin.java From lucene-solr with Apache License 2.0 | 6 votes |
@Override public QParser createParser(String qstr, SolrParams localParams, SolrParams params, SolrQueryRequest req) { final JoinQParserPlugin plugin = this; return new QParser(qstr, localParams, params, req) { @Override public Query parse() throws SyntaxError { if (localParams != null && localParams.get(METHOD) != null) { // TODO Make sure 'method' is valid value here and give users a nice error final Method explicitMethod = Method.valueOf(localParams.get(METHOD)); return explicitMethod.makeFilter(this, plugin); } // Legacy join behavior before introduction of SOLR-13892 if(localParams!=null && localParams.get(ScoreJoinQParserPlugin.SCORE)!=null) { return new ScoreJoinQParserPlugin().createParser(qstr, localParams, params, req).parse(); } else { return Method.index.makeFilter(this, plugin); } } }; }
Example #15
Source File: TestCollectionAPIs.java From lucene-solr with Apache License 2.0 | 6 votes |
@Override void invokeAction(SolrQueryRequest req, SolrQueryResponse rsp, CoreContainer cores, CollectionParams.CollectionAction action, CollectionOperation operation) throws Exception { Map<String, Object> result = null; if (action == CollectionParams.CollectionAction.COLLECTIONPROP) { //Fake this action, since we don't want to write to ZooKeeper in this test result = new HashMap<>(); result.put(NAME, req.getParams().required().get(NAME)); result.put(PROPERTY_NAME, req.getParams().required().get(PROPERTY_NAME)); result.put(PROPERTY_VALUE, req.getParams().required().get(PROPERTY_VALUE)); } else { result = operation.execute(req, rsp, this); } if (result != null) { result.put(QUEUE_OPERATION, operation.action.toLower()); rsp.add(ZkNodeProps.class.getName(), new ZkNodeProps(result)); } }
Example #16
Source File: TestOverriddenPrefixQueryForCustomFieldType.java From lucene-solr with Apache License 2.0 | 6 votes |
/** * @see org.apache.lucene.search.QueryUtils#check * @see org.apache.lucene.search.QueryUtils#checkEqual */ protected void assertQueryEquals(final SolrQueryRequest req, final String... inputs) throws Exception { final Query[] queries = new Query[inputs.length]; try { SolrQueryResponse rsp = new SolrQueryResponse(); SolrRequestInfo.setRequestInfo(new SolrRequestInfo(req, rsp)); for (int i = 0; i < inputs.length; i++) { queries[i] = (QParser.getParser(inputs[i], req).getQuery()); } } finally { SolrRequestInfo.clearRequestInfo(); } for (int i = 0; i < queries.length; i++) { org.apache.lucene.search.QueryUtils.check(queries[i]); for (int j = i; j < queries.length; j++) { org.apache.lucene.search.QueryUtils.checkEqual(queries[i], queries[j]); } } }
Example #17
Source File: QuerqyDismaxQParserWithSolrSynonymsTest.java From querqy with Apache License 2.0 | 6 votes |
@Test public void testThatPFWorksWithSynonymRewriting() { SolrQueryRequest req = req("q", "a b", DisMaxParams.QF, "f1 f2^0.9", DisMaxParams.PF, "f1^0.5", "defType", "querqy", "debugQuery", "true"); assertQ("ps with synonyms not working", req, "//str[@name='parsedquery'][contains(.,'PhraseQuery(f1:\"a b\")^0.5')]"); req.close(); }
Example #18
Source File: CriteriaSelectionTest.java From querqy with Apache License 2.0 | 6 votes |
@Test public void testThatDefaultStrategyIsAppliedIfNoCriteriaParamIsSet() { SolrQueryRequest req = req("q", "input1 input2", DisMaxParams.QF, "f1", DisMaxParams.MM, "1", getStrategyParamName(REWRITER_ID_1), "criteria", "defType", "querqy", "debugQuery", "true" ); assertQ("default SelectionStrategy doesn't work", req, "//result[@name='response' and @numFound='3']" ); req.close(); }
Example #19
Source File: LTRScoringQuery.java From lucene-solr with Apache License 2.0 | 6 votes |
private void createWeightsParallel(IndexSearcher searcher, boolean needsScores, List<Feature.FeatureWeight > featureWeights, Collection<Feature> features) throws RuntimeException { final SolrQueryRequest req = getRequest(); List<Future<Feature.FeatureWeight> > futures = new ArrayList<>(features.size()); try{ for (final Feature f : features) { CreateWeightCallable callable = new CreateWeightCallable(f, searcher, needsScores, req); RunnableFuture<Feature.FeatureWeight> runnableFuture = new FutureTask<>(callable); querySemaphore.acquire(); // always acquire before the ltrSemaphore is acquired, to guarantee a that the current query is within the limit for max. threads ltrThreadMgr.acquireLTRSemaphore();//may block and/or interrupt ltrThreadMgr.execute(runnableFuture);//releases semaphore when done futures.add(runnableFuture); } //Loop over futures to get the feature weight objects for (final Future<Feature.FeatureWeight> future : futures) { featureWeights.add(future.get()); // future.get() will block if the job is still running } } catch (Exception e) { // To catch InterruptedException and ExecutionException log.info("Error while creating weights in LTR: InterruptedException", e); throw new RuntimeException("Error while creating weights in LTR: " + e.getMessage(), e); } }
Example #20
Source File: CommonRulesDeleteLastTermTest.java From querqy with Apache License 2.0 | 6 votes |
@Test public void testNoMatchAfterDeletingLastTerm() { String q = "b"; SolrQueryRequest req = req("q", q, DisMaxParams.QF, "f1", "debugQuery", "on", "defType", "querqy"); assertQ("", req, "//result[@name='response' and @numFound='0']" ); req.close(); }
Example #21
Source File: QueryEqualityTest.java From lucene-solr with Apache License 2.0 | 6 votes |
public void testFuncSingleValueMathFuncs() throws Exception { SolrQueryRequest req = req("myVal","45", "myField","foo_i"); for (final String func : new String[] {"abs","rad","deg","sqrt","cbrt", "log","ln","exp","sin","cos","tan", "asin","acos","atan", "sinh","cosh","tanh", "ceil","floor","rint"}) { try { assertFuncEquals(req, func + "(field(foo_i))", func + "(foo_i)", func + "($myField)"); assertFuncEquals(req, func + "(45)", func+ "($myVal)"); } finally { req.close(); } } }
Example #22
Source File: DebugComponentTest.java From lucene-solr with Apache License 2.0 | 5 votes |
@Test public void testPrepare() throws IOException { DebugComponent component = new DebugComponent(); List<SearchComponent> components = new ArrayList<>(1); components.add(component); SolrQueryRequest req; ResponseBuilder rb; for(int i = 0; i < 10; i++) { req = req("q", "test query", "distrib", "true"); rb = new ResponseBuilder(req, new SolrQueryResponse(), components); rb.isDistrib = true; //expecting the same results with debugQuery=true or debug=track if(random().nextBoolean()) { rb.setDebug(true); } else { rb.setDebug(false); rb.setDebugTrack(true); //should not depend on other debug options rb.setDebugQuery(random().nextBoolean()); rb.setDebugTimings(random().nextBoolean()); rb.setDebugResults(random().nextBoolean()); } component.prepare(rb); ensureRidPresent(rb, null); } req = req("q", "test query", "distrib", "true", CommonParams.REQUEST_ID, "123"); rb = new ResponseBuilder(req, new SolrQueryResponse(), components); rb.isDistrib = true; rb.setDebug(true); component.prepare(rb); ensureRidPresent(rb, "123"); }
Example #23
Source File: JsonLoaderTest.java From lucene-solr with Apache License 2.0 | 5 votes |
@Test public void testEmptyAnonymousChildDocs() throws Exception { String str = "{\n" + " \"add\": {\n" + " \"doc\": {\n" + " \"id\": \"1\",\n" + " \"_childDocuments_\": []\n" + " }\n" + " }\n" + "}"; SolrQueryRequest req = req("commit","true"); SolrQueryResponse rsp = new SolrQueryResponse(); BufferingRequestProcessor p = new BufferingRequestProcessor(null); JsonLoader loader = new JsonLoader(); loader.load(req, rsp, new ContentStreamBase.StringStream(str), p); assertEquals( 1, p.addCommands.size() ); AddUpdateCommand add = p.addCommands.get(0); SolrInputDocument d = add.solrDoc; SolrInputField f = d.getField( "id" ); assertEquals("1", f.getValue()); List<SolrInputDocument> cd = d.getChildDocuments(); assertNull(cd); req.close(); }
Example #24
Source File: TestMergePolicyConfig.java From lucene-solr with Apache License 2.0 | 5 votes |
public void testNoMergePolicyFactoryConfig() throws Exception { initCore("solrconfig-nomergepolicyfactory.xml","schema-minimal.xml"); IndexWriterConfig iwc = solrConfig.indexConfig.toIndexWriterConfig(h.getCore()); NoMergePolicy mergePolicy = assertAndCast(NoMergePolicy.class, iwc.getMergePolicy()); assertCommitSomeNewDocs(); assertCommitSomeNewDocs(); assertNumSegments(h.getCore(), 2); assertU(optimize()); assertNumSegments(h.getCore(), 2); deleteCore(); initCore("solrconfig-nomergepolicyfactory.xml","schema-minimal.xml"); iwc = solrConfig.indexConfig.toIndexWriterConfig(h.getCore()); assertEquals(mergePolicy, iwc.getMergePolicy()); UpdateHandler updater = h.getCore().getUpdateHandler(); SolrQueryRequest req = req(); CommitUpdateCommand cmtCmd = new CommitUpdateCommand(req, true); cmtCmd.maxOptimizeSegments = -1; expectThrows(IllegalArgumentException.class, () -> { updater.commit(cmtCmd); }); }
Example #25
Source File: SecureAdminHandlersTest.java From incubator-sentry with Apache License 2.0 | 5 votes |
private void verifyAuthorized(RequestHandlerBase handler, String collection, String user) throws Exception { SolrQueryRequest req = getRequest(); prepareCollAndUser(core, req, collection, user, false); // just ensure we don't get an unauthorized exception try { handler.handleRequestBody(req, new SolrQueryResponse()); } catch (SolrException ex) { assertFalse(ex.code() == SolrException.ErrorCode.UNAUTHORIZED.code); } catch (Throwable t) { // okay, we only want to verify we didn't get an Unauthorized exception, // going to treat each handler as a black box. } }
Example #26
Source File: AddBlockUpdateTest.java From lucene-solr with Apache License 2.0 | 5 votes |
private void indexSolrInputDocumentsDirectly(SolrInputDocument ... docs) throws IOException { SolrQueryRequest coreReq = new LocalSolrQueryRequest(h.getCore(), new ModifiableSolrParams()); AddUpdateCommand updateCmd = new AddUpdateCommand(coreReq); for (SolrInputDocument doc: docs) { updateCmd.solrDoc = doc; h.getCore().getUpdateHandler().addDoc(updateCmd); updateCmd.clear(); } assertU(commit()); }
Example #27
Source File: RuntimeLibReqHandler.java From lucene-solr with Apache License 2.0 | 5 votes |
@Override public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throws IOException { super.handleRequestBody(req, rsp); rsp.add("class", this.getClass().getName()); rsp.add("loader", getClass().getClassLoader().getClass().getName() ); }
Example #28
Source File: ReRankBoostMethodTest.java From querqy with Apache License 2.0 | 5 votes |
@Test public void testThatReRankWorksForNegativeBoostWithSimilarityOff() { String q = "qdown1 qdown2"; SolrQueryRequest req = req("q", q, DisMaxParams.QF, "f1", QueryParsing.OP, "OR", QBOOST_METHOD, QBOOST_METHOD_RERANK, QBOOST_SIMILARITY_SCORE, SIMILARITY_SCORE_OFF, "defType", "querqy", "debugQuery", "true" ); assertQ("Rerank does not work with negative boost'", req, "//result[@name='response'][@numFound='2']", // the parsed query must contain not the boost terms: "//str[@name='parsedquery'][not(contains(.,'f1:d1'))]", "//str[@name='parsedquery'][not(contains(.,'f1:d2'))]", // debug output must contain 'QuerqyReRankQuery' "//lst[@name='explain']/str[contains(.,'QuerqyReRankQuery')]", "//doc[1]/str[@name='id'][contains(.,'4')]", "//doc[2]/str[@name='id'][contains(.,'3')]", "//str[@name='4'][contains(.,'0.2 = AdditiveBoostFunction(-0.2,query(+f1:d2,def=0.0)=0.0)')]", "//str[@name='4'][contains(.,'0.05 = AdditiveBoostFunction(-0.1,query(+f1:d1,def=0.0)=1.0)')]", "//str[@name='3'][contains(.,'0.1 = AdditiveBoostFunction(-0.2,query(+f1:d2,def=0.0)=1.0)')]", "//str[@name='3'][contains(.,'0.1 = AdditiveBoostFunction(-0.1,query(+f1:d1,def=0.0)=0.0)')]" ); req.close(); }
Example #29
Source File: SentryIndexAuthorizationSingleton.java From incubator-sentry with Apache License 2.0 | 5 votes |
private String getImpersonatorName(SolrQueryRequest req) { HttpServletRequest httpServletRequest = (HttpServletRequest)req.getContext().get("httpRequest"); if (httpServletRequest != null) { return (String)httpServletRequest.getAttribute(DO_AS_USER_NAME); } return null; }
Example #30
Source File: SolrInformationServer.java From SearchServices with GNU Lesser General Public License v3.0 | 5 votes |
private void deleteErrorNode(UpdateRequestProcessor processor, SolrQueryRequest request, Node node) throws IOException { String errorDocId = PREFIX_ERROR + node.getId(); if (getDocListSize(FIELD_SOLR4_ID + ":" + errorDocId) > 0) { DeleteUpdateCommand delErrorDocCmd = new DeleteUpdateCommand(request); delErrorDocCmd.setId(errorDocId); processor.processDelete(delErrorDocCmd); } }