Example usage for org.apache.solr.handler.component HighlightComponent getHighlighter

List of usage examples for org.apache.solr.handler.component HighlightComponent getHighlighter

Introduction

In this page you can find the example usage for org.apache.solr.handler.component HighlightComponent getHighlighter.

Prototype

protected SolrHighlighter getHighlighter(SolrParams params) 

Source Link

Usage

From source file:org.alfresco.solr.highlight.AlfrescoHighligherDistributedTest.java

License:Open Source License

@Test
public void testHighlight() throws Exception {

    logger.info("######### Starting highlighter test ###########");
    SolrHighlighter highlighter = HighlightComponent.getHighlighter(defaultCore);
    assertTrue("wrong highlighter: " + highlighter.getClass(), highlighter instanceof AlfrescoSolrHighlighter);
    /**// ww w . ja  v a 2  s. com
            AclChangeSet aclChangeSet = getAclChangeSet(1);
            Acl acl = getAcl(aclChangeSet);
            
            AclReaders aclReaders = getAclReaders(aclChangeSet, acl, list("mike"), list("mike"), null);
            
            indexAclChangeSet(aclChangeSet, list(acl), list(aclReaders));
            
            //First create a transaction.
            Transaction foldertxn = getTransaction(0, 1);
            Transaction txn = getTransaction(0, 2);
            
            //Next create two nodes to update for the transaction
            Node folderNode = getNode(foldertxn, acl, Node.SolrApiNodeStatus.UPDATED);
            Node fileNode = getNode(txn, acl, Node.SolrApiNodeStatus.UPDATED);
            Node fileNode2 = getNode(txn, acl, Node.SolrApiNodeStatus.UPDATED);
            
            NodeMetaData folderMetaData = getNodeMetaData(folderNode, foldertxn, acl, "mike", null, false);
            NodeMetaData fileMetaData   = getNodeMetaData(fileNode,  txn, acl, "mike", ancestors(folderMetaData.getNodeRef()), false);
            NodeMetaData fileMetaData2  = getNodeMetaData(fileNode2, txn, acl, "mike", ancestors(folderMetaData.getNodeRef()), false);
            
            fileMetaData.getProperties().put(ContentModel.PROP_NAME, new StringPropertyValue("some very long name"));
            fileMetaData.getProperties().put(ContentModel.PROP_TITLE, new StringPropertyValue("title1"));
            fileMetaData.getProperties().put(ContentModel.PROP_DESCRIPTION, new StringPropertyValue("mydesc"));
            
            fileMetaData2.getProperties().put(ContentModel.PROP_NAME, new StringPropertyValue("some name"));
            fileMetaData2.getProperties().put(ContentModel.PROP_TITLE, new StringPropertyValue("title2"));
            
            String LONG_TEXT = "this is some long text.  It has the word long in many places.  In fact, it has long on some different fragments.  " +
        "Let us see what happens to long in this case.";
            
            List<String> content = Arrays.asList(LONG_TEXT, LONG_TEXT);
            
            //Index the transaction, nodes, and nodeMetaDatas.
            indexTransaction(foldertxn, list(folderNode), list(folderMetaData));
            indexTransaction(txn,
        list(fileNode, fileNode2),
        list(fileMetaData, fileMetaData2),
        content);
            logger.info("######### Waiting for Doc Count ###########");
            waitForDocCount(new TermQuery(new Term(QueryConstants.FIELD_OWNER, "mike")), 3, 80000);
            waitForDocCount(new TermQuery(new Term(ContentModel.PROP_TITLE.toString(), "title1")), 1, 500);
            waitForDocCount(new TermQuery(new Term(ContentModel.PROP_DESCRIPTION.toString(), "mydesc")), 1, 500);
            
            //name, title, description, content
            //up to 3 matches in the content  (needs to be big enough)
            QueryResponse response = query(jetty.getDefaultClient(), false,
        "{\"locales\":[\"en\"], \"authorities\": [\"mike\"], \"tenants\": [ \"\" ]}",
        params( "q", ContentModel.PROP_NAME.toString()+":some very long name",
                "qt", "/afts", "start", "0", "rows", "5",
                HighlightParams.HIGHLIGHT, "true",
                HighlightParams.FIELDS, "",
                HighlightParams.SNIPPETS, String.valueOf(4),
                HighlightParams.FRAGSIZE, String.valueOf(40)));
            
            assertTrue(response.getResults().getNumFound() > 0);
            
     **/
}

From source file:org.alfresco.solr.highlight.TestPostingsSolrHighlighter.java

License:Apache License

@BeforeClass
public static void beforeClass() throws Exception {
    initAlfrescoCore("schema.xml");
    // test our config is sane, just to be sure:

    // postingshighlighter should be used
    SolrHighlighter highlighter = HighlightComponent.getHighlighter(getCore());
    assertTrue("wrong highlighter: " + highlighter.getClass(), highlighter instanceof AlfrescoSolrHighlighter);

    // 'text' and 'text3' should have offsets, 'text2' should not
    IndexSchema schema = getCore().getLatestSchema();
    assertTrue(schema.getField("text").storeOffsetsWithPositions());
    assertTrue(schema.getField("text3").storeOffsetsWithPositions());
    assertFalse(schema.getField("text2").storeOffsetsWithPositions());
}