Search in sources :

Example 6 with SearchComponent

use of org.apache.solr.handler.component.SearchComponent in project lucene-solr by apache.

the class SpellCheckCollatorTest method testWithCursorMark.

@Test
public void testWithCursorMark() throws Exception {
    SolrCore core = h.getCore();
    SearchComponent speller = core.getSearchComponent("spellcheck");
    assertTrue("speller is null and it shouldn't be", speller != null);
    ModifiableSolrParams params = new ModifiableSolrParams();
    params.add(SpellCheckComponent.COMPONENT_NAME, "true");
    params.add(SpellCheckComponent.SPELLCHECK_BUILD, "true");
    params.add(SpellCheckComponent.SPELLCHECK_COUNT, "10");
    params.add(SpellCheckComponent.SPELLCHECK_COLLATE, "true");
    params.add(SpellCheckComponent.SPELLCHECK_MAX_COLLATION_TRIES, "2");
    params.add(SpellCheckComponent.SPELLCHECK_MAX_COLLATIONS, "1");
    params.add(CommonParams.Q, "lowerfilt:(+fauth)");
    params.add(CommonParams.SORT, "id asc");
    params.add(CursorMarkParams.CURSOR_MARK_PARAM, CursorMarkParams.CURSOR_MARK_START);
    SolrRequestHandler handler = core.getRequestHandler("spellCheckCompRH");
    SolrQueryResponse rsp = new SolrQueryResponse();
    rsp.addResponseHeader(new SimpleOrderedMap());
    SolrQueryRequest req = new LocalSolrQueryRequest(core, params);
    handler.handleRequest(req, rsp);
    req.close();
    NamedList values = rsp.getValues();
    NamedList spellCheck = (NamedList) values.get("spellcheck");
    NamedList collationList = (NamedList) spellCheck.get("collations");
    List<?> collations = (List<?>) collationList.getAll("collation");
    assertTrue(collations.size() == 1);
}
Also used : LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) SolrCore(org.apache.solr.core.SolrCore) NamedList(org.apache.solr.common.util.NamedList) SearchComponent(org.apache.solr.handler.component.SearchComponent) NamedList(org.apache.solr.common.util.NamedList) List(java.util.List) SimpleOrderedMap(org.apache.solr.common.util.SimpleOrderedMap) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) SolrRequestHandler(org.apache.solr.request.SolrRequestHandler) Test(org.junit.Test)

Example 7 with SearchComponent

use of org.apache.solr.handler.component.SearchComponent in project lucene-solr by apache.

the class SpellCheckCollatorTest method testCollateWithFilter.

@Test
public void testCollateWithFilter() throws Exception {
    SolrCore core = h.getCore();
    SearchComponent speller = core.getSearchComponent("spellcheck");
    assertTrue("speller is null and it shouldn't be", speller != null);
    ModifiableSolrParams params = new ModifiableSolrParams();
    params.add(SpellCheckComponent.COMPONENT_NAME, "true");
    params.add(SpellingParams.SPELLCHECK_BUILD, "true");
    params.add(SpellingParams.SPELLCHECK_COUNT, "10");
    params.add(SpellingParams.SPELLCHECK_COLLATE, "true");
    params.add(SpellingParams.SPELLCHECK_MAX_COLLATION_TRIES, "10");
    params.add(SpellingParams.SPELLCHECK_MAX_COLLATIONS, "10");
    params.add(CommonParams.Q, "lowerfilt:(+fauth +home +loane)");
    params.add(CommonParams.FQ, "NOT(id:1)");
    //Because a FilterQuery is applied which removes doc id#1 from possible hits, we would
    //not want the collations to return us "lowerfilt:(+faith +hope +loaves)" as this only matches doc id#1.
    SolrRequestHandler handler = core.getRequestHandler("spellCheckCompRH");
    SolrQueryResponse rsp = new SolrQueryResponse();
    rsp.addResponseHeader(new SimpleOrderedMap());
    SolrQueryRequest req = new LocalSolrQueryRequest(core, params);
    handler.handleRequest(req, rsp);
    req.close();
    NamedList values = rsp.getValues();
    NamedList spellCheck = (NamedList) values.get("spellcheck");
    NamedList collationHolder = (NamedList) spellCheck.get("collations");
    List<String> collations = collationHolder.getAll("collation");
    assertTrue(collations.size() > 0);
    for (String collation : collations) {
        assertTrue(!collation.equals("lowerfilt:(+faith +hope +loaves)"));
    }
}
Also used : LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) SolrCore(org.apache.solr.core.SolrCore) NamedList(org.apache.solr.common.util.NamedList) SearchComponent(org.apache.solr.handler.component.SearchComponent) SimpleOrderedMap(org.apache.solr.common.util.SimpleOrderedMap) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) SolrRequestHandler(org.apache.solr.request.SolrRequestHandler) Test(org.junit.Test)

Example 8 with SearchComponent

use of org.apache.solr.handler.component.SearchComponent in project lucene-solr by apache.

the class SpellCheckCollatorTest method testCollateWithGrouping.

@Test
public void testCollateWithGrouping() throws Exception {
    SolrCore core = h.getCore();
    SearchComponent speller = core.getSearchComponent("spellcheck");
    assertTrue("speller is null and it shouldn't be", speller != null);
    ModifiableSolrParams params = new ModifiableSolrParams();
    params.add(SpellCheckComponent.COMPONENT_NAME, "true");
    params.add(SpellingParams.SPELLCHECK_BUILD, "true");
    params.add(SpellingParams.SPELLCHECK_COUNT, "10");
    params.add(SpellingParams.SPELLCHECK_COLLATE, "true");
    params.add(SpellingParams.SPELLCHECK_MAX_COLLATION_TRIES, "5");
    params.add(SpellingParams.SPELLCHECK_MAX_COLLATIONS, "1");
    params.add(CommonParams.Q, "lowerfilt:(+fauth)");
    params.add(GroupParams.GROUP, "true");
    params.add(GroupParams.GROUP_FIELD, "id");
    //Because a FilterQuery is applied which removes doc id#1 from possible hits, we would
    //not want the collations to return us "lowerfilt:(+faith +hope +loaves)" as this only matches doc id#1.
    SolrRequestHandler handler = core.getRequestHandler("spellCheckCompRH");
    SolrQueryResponse rsp = new SolrQueryResponse();
    rsp.addResponseHeader(new SimpleOrderedMap());
    SolrQueryRequest req = new LocalSolrQueryRequest(core, params);
    handler.handleRequest(req, rsp);
    req.close();
    NamedList values = rsp.getValues();
    NamedList spellCheck = (NamedList) values.get("spellcheck");
    NamedList collationHolder = (NamedList) spellCheck.get("collations");
    List<String> collations = collationHolder.getAll("collation");
    assertTrue(collations.size() == 1);
}
Also used : LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) SolrCore(org.apache.solr.core.SolrCore) NamedList(org.apache.solr.common.util.NamedList) SearchComponent(org.apache.solr.handler.component.SearchComponent) SimpleOrderedMap(org.apache.solr.common.util.SimpleOrderedMap) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) SolrRequestHandler(org.apache.solr.request.SolrRequestHandler) Test(org.junit.Test)

Example 9 with SearchComponent

use of org.apache.solr.handler.component.SearchComponent in project lucene-solr by apache.

the class SpellCheckCollatorTest method testZeroTries.

@Test
public void testZeroTries() throws Exception {
    SolrCore core = h.getCore();
    SearchComponent speller = core.getSearchComponent("spellcheck");
    assertTrue("speller is null and it shouldn't be", speller != null);
    ModifiableSolrParams params = new ModifiableSolrParams();
    params.add(SpellCheckComponent.COMPONENT_NAME, "true");
    params.add(SpellCheckComponent.SPELLCHECK_BUILD, "true");
    params.add(SpellCheckComponent.SPELLCHECK_COUNT, "10");
    params.add(SpellCheckComponent.SPELLCHECK_COLLATE, "true");
    params.add(SpellCheckComponent.SPELLCHECK_MAX_COLLATION_TRIES, "0");
    params.add(SpellCheckComponent.SPELLCHECK_MAX_COLLATIONS, "2");
    params.add(CommonParams.Q, "lowerfilt:(+fauth)");
    SolrRequestHandler handler = core.getRequestHandler("spellCheckCompRH");
    SolrQueryResponse rsp = new SolrQueryResponse();
    rsp.addResponseHeader(new SimpleOrderedMap());
    SolrQueryRequest req = new LocalSolrQueryRequest(core, params);
    handler.handleRequest(req, rsp);
    req.close();
    NamedList values = rsp.getValues();
    NamedList spellCheck = (NamedList) values.get("spellcheck");
    NamedList collationList = (NamedList) spellCheck.get("collations");
    List<?> collations = (List<?>) collationList.getAll("collation");
    assertTrue(collations.size() == 2);
}
Also used : LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) SolrCore(org.apache.solr.core.SolrCore) NamedList(org.apache.solr.common.util.NamedList) SearchComponent(org.apache.solr.handler.component.SearchComponent) NamedList(org.apache.solr.common.util.NamedList) List(java.util.List) SimpleOrderedMap(org.apache.solr.common.util.SimpleOrderedMap) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) SolrRequestHandler(org.apache.solr.request.SolrRequestHandler) Test(org.junit.Test)

Example 10 with SearchComponent

use of org.apache.solr.handler.component.SearchComponent in project lucene-solr by apache.

the class HighlighterTest method payloadFilteringSpanQuery.

@Test
public void payloadFilteringSpanQuery() throws IOException {
    clearIndex();
    String FIELD_NAME = "payloadDelimited";
    assertU(adoc("id", "0", FIELD_NAME, "word|7 word|2"));
    assertU(commit());
    //We search at a lower level than typical Solr tests because there's no QParser for payloads
    //Create query matching this payload
    Query query = new SpanPayloadCheckQuery(new SpanTermQuery(new Term(FIELD_NAME, "word")), //bytes for integer 7
    Collections.singletonList(new BytesRef(new byte[] { 0, 0, 0, 7 })));
    //invoke highlight component... the hard way
    final SearchComponent hlComp = h.getCore().getSearchComponent("highlight");
    SolrQueryRequest req = req("hl", "true", "hl.fl", FIELD_NAME, HighlightParams.USE_PHRASE_HIGHLIGHTER, "true");
    try {
        SolrQueryResponse resp = new SolrQueryResponse();
        ResponseBuilder rb = new ResponseBuilder(req, resp, Collections.singletonList(hlComp));
        rb.setHighlightQuery(query);
        rb.setResults(req.getSearcher().getDocListAndSet(query, (DocSet) null, null, 0, 1));
        //highlight:
        hlComp.prepare(rb);
        hlComp.process(rb);
        //inspect response
        final String[] snippets = (String[]) resp.getValues().findRecursive("highlighting", "0", FIELD_NAME);
        assertEquals("<em>word|7</em> word|2", snippets[0]);
    } finally {
        req.close();
    }
}
Also used : SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) Query(org.apache.lucene.search.Query) SpanTermQuery(org.apache.lucene.search.spans.SpanTermQuery) SpanPayloadCheckQuery(org.apache.lucene.queries.payloads.SpanPayloadCheckQuery) SpanPayloadCheckQuery(org.apache.lucene.queries.payloads.SpanPayloadCheckQuery) SpanTermQuery(org.apache.lucene.search.spans.SpanTermQuery) SearchComponent(org.apache.solr.handler.component.SearchComponent) Term(org.apache.lucene.index.Term) ResponseBuilder(org.apache.solr.handler.component.ResponseBuilder) BytesRef(org.apache.lucene.util.BytesRef) DocSet(org.apache.solr.search.DocSet) Test(org.junit.Test)

Aggregations

SearchComponent (org.apache.solr.handler.component.SearchComponent)12 SolrQueryResponse (org.apache.solr.response.SolrQueryResponse)12 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)11 LocalSolrQueryRequest (org.apache.solr.request.LocalSolrQueryRequest)11 SolrQueryRequest (org.apache.solr.request.SolrQueryRequest)11 NamedList (org.apache.solr.common.util.NamedList)10 Test (org.junit.Test)10 SolrCore (org.apache.solr.core.SolrCore)9 SolrRequestHandler (org.apache.solr.request.SolrRequestHandler)9 SimpleOrderedMap (org.apache.solr.common.util.SimpleOrderedMap)8 List (java.util.List)4 ResponseBuilder (org.apache.solr.handler.component.ResponseBuilder)3 ArrayList (java.util.ArrayList)2 IndexReader (org.apache.lucene.index.IndexReader)2 SolrParams (org.apache.solr.common.params.SolrParams)2 QueryComponent (org.apache.solr.handler.component.QueryComponent)2 EarlyTerminatingCollectorException (org.apache.solr.search.EarlyTerminatingCollectorException)2 HashSet (java.util.HashSet)1 Term (org.apache.lucene.index.Term)1 SpanPayloadCheckQuery (org.apache.lucene.queries.payloads.SpanPayloadCheckQuery)1