Example usage for org.apache.solr.common SolrDocumentList getNumFound

List of usage examples for org.apache.solr.common SolrDocumentList getNumFound

Introduction

In this page you can find the example usage for org.apache.solr.common SolrDocumentList getNumFound.

Prototype

public long getNumFound() 

Source Link

Usage

From source file:se.simonsoft.cms.indexing.xml.HandlerXmlIntegrationTest.java

License:Apache License

@Test
public void testTinyRidDuplicate() throws Exception {
    FilexmlSourceClasspath repoSource = new FilexmlSourceClasspath(
            "se/simonsoft/cms/indexing/xml/datasets/tiny-ridduplicate");
    CmsRepositoryFilexml repo = new CmsRepositoryFilexml("http://localtesthost/svn/tiny-ridduplicate",
            repoSource);//from  www.j a v a 2 s  . c  om
    FilexmlRepositoryReadonly filexml = new FilexmlRepositoryReadonly(repo);

    indexing.enable(new ReposTestBackendFilexml(filexml));

    SolrServer reposxml = indexing.getCore("reposxml");

    SolrDocumentList x1 = reposxml.query(new SolrQuery("pathname:test1.xml").addSort("pos", ORDER.asc))
            .getResults();
    assertEquals("Should index all elements", 5, x1.getNumFound());
    assertEquals("should get 'repoid' from repositem", "localtesthost/svn/tiny-ridduplicate",
            x1.get(0).getFieldValue("repoid"));

    SolrServer repositem = indexing.getCore("repositem");
    SolrDocumentList flagged = repositem.query(new SolrQuery("pathname:test1.xml AND flag:hasxml"))
            .getResults();
    assertEquals("Documents that got added to reposxml should be flagged 'hasxml' in repositem", 1,
            flagged.getNumFound());
    Collection<Object> flags = flagged.get(0).getFieldValues("flag");
    assertFalse("Flag - not empty string", flagged.get(0).getFieldValues("flag").contains(""));
    assertTrue("Flag 'hasxml'", flagged.get(0).getFieldValues("flag").contains("hasxml"));
    assertTrue("Flag 'hasridduplicate'", flagged.get(0).getFieldValues("flag").contains("hasridduplicate"));
    assertEquals("2 flags", 2, flags.size());

    Collection<Object> duplicates = flagged.get(0).getFieldValues("embd_xml_ridduplicate");
    assertEquals("one duplicate, mentioned once", 1, duplicates.size());
    assertEquals("List the duplicate RIDs in repositem core", "2gyvymn15kv0002", duplicates.iterator().next());

    // Back to asserting on reposxml.
    assertEquals("second element", "section", x1.get(1).getFieldValue("name"));
    assertEquals("third element", "elem", x1.get(2).getFieldValue("name"));
    assertEquals("should extract source",
            "<elem xmlns:cms=\"http://www.simonsoft.se/namespace/cms\" name=\"ch1\" cms:rid=\"2gyvymn15kv0002\">text</elem>",
            x1.get(2).getFieldValue("source"));
}

From source file:se.simonsoft.cms.indexing.xml.HandlerXmlIntegrationTest.java

License:Apache License

@Test
public void testTinyRidDuplicateTsuppress() throws Exception {
    FilexmlSourceClasspath repoSource = new FilexmlSourceClasspath(
            "se/simonsoft/cms/indexing/xml/datasets/tiny-ridduplicate");
    CmsRepositoryFilexml repo = new CmsRepositoryFilexml("http://localtesthost/svn/tiny-ridduplicate",
            repoSource);/*from   ww w  .j a  v  a2 s  .c  om*/
    FilexmlRepositoryReadonly filexml = new FilexmlRepositoryReadonly(repo);

    indexing.enable(new ReposTestBackendFilexml(filexml));

    SolrServer reposxml = indexing.getCore("reposxml");

    SolrDocumentList x1 = reposxml
            .query(new SolrQuery("pathname:test1-tsuppress.xml").addSort("pos", ORDER.asc)).getResults();
    assertEquals("Should index all elements", 5, x1.getNumFound());
    assertEquals("should get 'repoid' from repositem", "localtesthost/svn/tiny-ridduplicate",
            x1.get(0).getFieldValue("repoid"));

    SolrServer repositem = indexing.getCore("repositem");
    SolrDocumentList flagged = repositem.query(new SolrQuery("pathname:test1-tsuppress.xml AND flag:hasxml"))
            .getResults();
    assertEquals("Documents that got added to reposxml should be flagged 'hasxml' in repositem", 1,
            flagged.getNumFound());
    Collection<Object> flags = flagged.get(0).getFieldValues("flag");
    assertFalse("Flag - not empty string", flagged.get(0).getFieldValues("flag").contains(""));
    assertTrue("Flag 'hasxml'", flagged.get(0).getFieldValues("flag").contains("hasxml"));
    assertFalse("Flag 'hasridduplicate'", flagged.get(0).getFieldValues("flag").contains("hasridduplicate"));
    assertEquals("only hasxml flag", 1, flags.size());

    // Back to asserting on reposxml.
    assertEquals("second element", "section", x1.get(1).getFieldValue("name"));
    assertEquals("third element", "elem", x1.get(2).getFieldValue("name"));
    assertEquals("should extract source",
            "<elem xmlns:cms=\"http://www.simonsoft.se/namespace/cms\" name=\"ch1\" cms:rid=\"2gyvymn15kv0002\">text</elem>",
            x1.get(2).getFieldValue("source"));
}

From source file:se.simonsoft.cms.indexing.xml.HandlerXmlIntegrationTest.java

License:Apache License

@Test
public void testNextRevisionDeletesElement() throws Exception {
    FilexmlSourceClasspath repoSource = new FilexmlSourceClasspath(
            "se/simonsoft/cms/indexing/xml/datasets/tiny-inline");
    CmsRepositoryFilexml repo = new CmsRepositoryFilexml("http://localtesthost/svn/tiny-inline", repoSource);
    FilexmlRepositoryReadonly filexml = new FilexmlRepositoryReadonly(repo);

    indexing.enable(new ReposTestBackendFilexml(filexml));

    SolrServer reposxml = indexing.getCore("reposxml");
    SolrDocumentList x1 = reposxml.query(new SolrQuery("*:*")).getResults();
    assertEquals(4, x1.getNumFound());
    assertEquals("should get 'repoid' from repositem", "localtesthost/svn/tiny-inline",
            x1.get(0).getFieldValue("repoid"));

    SolrServer repositem = indexing.getCore("repositem");
    SolrDocumentList flagged = repositem.query(new SolrQuery("flag:hasxml")).getResults();
    assertEquals("Documents that got added to reposxml should be flagged 'hasxml' in repositem", 1,
            flagged.getNumFound());/*from w  w  w .  ja v  a2s  .com*/

    // TODO delete one of the elements and make sure it is not there after indexing next revision, would indicate reliance on id overwrite

}

From source file:se.simonsoft.cms.indexing.xml.HandlerXmlIntegrationTest.java

License:Apache License

@Test
public void testInvalidXml() throws Exception {
    FilexmlSourceClasspath repoSource = new FilexmlSourceClasspath(
            "se/simonsoft/cms/indexing/xml/datasets/tiny-invalid");
    CmsRepositoryFilexml repo = new CmsRepositoryFilexml("http://localtesthost/svn/tiny-invalid", repoSource);
    FilexmlRepositoryReadonly filexml = new FilexmlRepositoryReadonly(repo);

    indexing.enable(new ReposTestBackendFilexml(filexml));

    SolrServer reposxml = indexing.getCore("reposxml");
    SolrDocumentList x1 = reposxml.query(new SolrQuery("*:*")).getResults();
    assertEquals(//w ww. ja  v  a  2  s.c  om
            "Should skip the document because it is not parseable as XML. Thus we can try formats that may be XML, such as html, without breaking indexing.",
            0, x1.getNumFound());

    SolrServer repositem = indexing.getCore("repositem");
    SolrDocumentList flagged = repositem.query(new SolrQuery("flag:hasxmlerror")).getResults();
    assertEquals("Should be flagged as error in repositem", 1, flagged.getNumFound());
}

From source file:se.simonsoft.cms.indexing.xml.HandlerXmlIntegrationTest.java

License:Apache License

@Test
public void testJoin() throws SolrServerException {
    FilexmlSourceClasspath repoSource = new FilexmlSourceClasspath(
            "se/simonsoft/cms/indexing/xml/datasets/tiny-inline");
    CmsRepositoryFilexml repo = new CmsRepositoryFilexml("http://localtesthost/svn/tiny-inline", repoSource);
    FilexmlRepositoryReadonly filexml = new FilexmlRepositoryReadonly(repo);

    SolrServer reposxml = indexing.enable(new ReposTestBackendFilexml(filexml)).getCore("reposxml");

    SolrDocumentList j1 = reposxml.query(new SolrQuery("{!join from=id to=id_p}*:*")).getResults();
    assertEquals("all elements that have a parent, got " + j1, 3, j1.getNumFound());
    for (SolrDocument e : j1) {
        assertNotEquals("root does not have a parent", "doc", e.getFieldValue("name"));
    }// w  w  w  .j ava2s  .  com

    SolrDocumentList j2 = reposxml.query(new SolrQuery("{!join from=id_p to=id}*:*")).getResults();
    assertEquals("all elements that have a child, got " + j2, 2, j2.getNumFound());

    SolrDocumentList j3 = reposxml.query(new SolrQuery("{!join from=id_p to=id}name:inline")).getResults();
    assertEquals("all elements that have a child which is an <inline/>, got " + j3, 1, j3.getNumFound());
    assertEquals("elem", j3.get(0).getFieldValue("name"));
    assertEquals("localtesthost/svn/tiny-inline/test1.xml@0000000002|1.2", j3.get(0).getFieldValue("id"));

    SolrDocumentList j4 = reposxml.query(new SolrQuery("name:elem AND {!join from=id_p to=id}*:*"))
            .getResults();
    assertEquals("all elements that are an elem and have a child, got " + j4, 1, j4.getNumFound());
    assertEquals("localtesthost/svn/tiny-inline/test1.xml@0000000002|1.2", j4.get(0).getFieldValue("id"));

    SolrDocumentList j5 = reposxml.query(new SolrQuery("{!join from=id_p to=id}(name:elem OR name:inline)"))
            .getResults();
    assertEquals("all elements that have a child which is either <elem/> or <inline/>" + j5, 2,
            j5.getNumFound());

    // why doesn't this run? instead use Parameter dereferencing?
    //SolrDocumentList j6 = reposxml.query(new SolrQuery("repo:tiny-inline AND {!join from=id_p to=id}(name:elem OR name:inline)")).getResults();
    //assertEquals("all elements that have a child which is either <elem/> or <inline/>, in the test repo" + j6, 2, j6.getNumFound());

    SolrDocumentList j7 = reposxml
            .query(new SolrQuery("{!join from=id_p to=id}(text:\"elem text\" AND name:elem)")).getResults();
    assertEquals("elements that have a child which matches two criterias" + j7, 1, j7.getNumFound());

    SolrDocumentList j8 = reposxml.query(new SolrQuery("{!join from=id_a to=id}name:inline")).getResults();
    assertEquals("elements with a descendat which is an <inline/>, got " + j8, 2, j8.getNumFound());

    // "Parameter dereferencing", http://wiki.apache.org/solr/LocalParams#parameter_dereferencing, but how to do "qq" in solrj?
    //      // find all figures with a bylinew with value "me"
    //      assertJQ(req("q", "{!join from=id_p to=id v=$qq}",
    //               "qq", "name:byline AND pos:1.2.2", // we don't have text indexed in this test so we use pos instead
    //               //"qf", "name",
    //               "fl", "id",
    //               "debugQuery", "true"),
    //            "/response=={'numFound':1,'start':0,'docs':[{'id':'testdoc1_e3'}]}");

}

From source file:se.simonsoft.cms.indexing.xml.HandlerXmlIntegrationTest.java

License:Apache License

@Test
public void testTinyAttributes() throws Exception {
    FilexmlSourceClasspath repoSource = new FilexmlSourceClasspath(
            "se/simonsoft/cms/indexing/xml/datasets/tiny-attributes");
    CmsRepositoryFilexml repo = new CmsRepositoryFilexml("http://localtesthost/svn/tiny-inline", repoSource);
    FilexmlRepositoryReadonly filexml = new FilexmlRepositoryReadonly(repo);

    indexing.enable(new ReposTestBackendFilexml(filexml));

    SolrServer reposxml = indexing.getCore("reposxml");

    SolrQuery q1 = new SolrQuery("*:*").addSort("pos", SolrQuery.ORDER.asc);
    SolrDocumentList x1 = reposxml.query(q1).getResults();
    assertEquals(4, x1.getNumFound());

    assertEquals("get name of root", "root", x1.get(0).getFieldValue("a_name"));
    assertEquals("get depth of root", 1, x1.get(0).getFieldValue("depth"));
    assertEquals("get pos/treeloc of root", "1", x1.get(0).getFieldValue("pos"));
    assertEquals("get name of e1", "ch1", x1.get(1).getFieldValue("a_name"));

    assertNull("get name of e2", x1.get(2).getFieldValue("a_name"));
    assertEquals("get id of e2", "e2", x1.get(2).getFieldValue("a_id"));

    assertEquals("get ancestor name of e1 - tests that inherited attr is not overridden by local attr", "root",
            x1.get(1).getFieldValue("aa_name"));
    assertEquals("get inherited name of e1 - overridden by local attr", "ch1",
            x1.get(1).getFieldValue("ia_name"));

    assertEquals("get ancestor name of e2", "root", x1.get(2).getFieldValue("aa_name"));
    assertEquals("get inherited name of e2", "root", x1.get(2).getFieldValue("ia_name"));

    assertEquals("get p-sibling name of e2", "ch1", x1.get(2).getFieldValue("sa_name"));

    assertEquals("get element name of inline", "inline", x1.get(3).getFieldValue("name"));
    assertEquals("get inherited name of inline", "root", x1.get(3).getFieldValue("ia_name"));
    assertEquals("get depth of inline", 3, x1.get(3).getFieldValue("depth"));
    assertEquals("get pos/treeloc of inline", "1.2.1", x1.get(3).getFieldValue("pos"));
    assertNull("get p-sibling name of inline", x1.get(3).getFieldValue("sa_name"));

}

From source file:se.simonsoft.cms.indexing.xml.HandlerXmlIntegrationTest.java

License:Apache License

@Test
public void testAttributesReleasetranslationRelease() throws SolrServerException {
    FilexmlSourceClasspath repoSource = new FilexmlSourceClasspath(
            "se/simonsoft/cms/indexing/xml/datasets/releasetranslation");
    CmsRepositoryFilexml repo = new CmsRepositoryFilexml("http://localtesthost/svn/testaut1", repoSource);
    FilexmlRepositoryReadonly filexml = new FilexmlRepositoryReadonly(repo);

    SolrServer reposxml = indexing.enable(new ReposTestBackendFilexml(filexml)).getCore("reposxml");

    SolrDocument elem;//from w ww  .  ja  v a  2s  .com
    // search for the first title
    SolrDocumentList findUsingRid = reposxml
            .query(new SolrQuery("a_cms.rid:2gyvymn15kv0001 AND -prop_abx.TranslationLocale:*")).getResults();
    assertEquals("Should find the first title in the release (though actually a future one)", 1,
            findUsingRid.getNumFound());
    elem = findUsingRid.get(0);
    assertEquals("get the rid attribute", "2gyvymn15kv0001", elem.getFieldValue("a_cms.rid"));
    assertEquals("get the parent project id attribute", "0001",
            elem.getFieldValue("ia_cms.translation-project"));

    findUsingRid = reposxml.query(new SolrQuery("a_cms.rid:2gyvymn15kv0006 AND -prop_abx.TranslationLocale:*"))
            .getResults();
    assertEquals("Should find a para", 1, findUsingRid.getNumFound());
    elem = findUsingRid.get(0);
    assertEquals("verify it is a para", "p", elem.getFieldValue("name"));
    assertEquals("get the rid attribute", "2gyvymn15kv0006", elem.getFieldValue("a_cms.rid"));
    assertEquals("get the ancestor rid attribute (in this case parent rid)", "2gyvymn15kv0004",
            elem.getFieldValue("aa_cms.rid"));
    assertEquals("get the inherited rid attribute (in this case context element rid)", "2gyvymn15kv0006",
            elem.getFieldValue("ia_cms.rid"));
    assertEquals("get the root rid attribute", "2gyvymn15kv0000", elem.getFieldValue("ra_cms.rid"));
    assertEquals("get the preceding sibling rid attribute", "2gyvymn15kv0005",
            elem.getFieldValue("sa_cms.rid"));
    assertNull("get the project id attribute", elem.getFieldValue("a_cms.translation-project"));
    assertEquals("get the parent project id attribute", "0001",
            elem.getFieldValue("ia_cms.translation-project"));

    assertEquals("get the inherited rlogicalid attribute",
            "x-svn:///svn/testaut1^/tms/xml/Secs/First%20chapter.xml?p=4",
            elem.getFieldValue("ia_cms.rlogicalid"));
}

From source file:se.simonsoft.cms.indexing.xml.HandlerXmlIntegrationTest.java

License:Apache License

@Test
public void testAttributesReleasetranslationTranslation() throws SolrServerException {
    FilexmlSourceClasspath repoSource = new FilexmlSourceClasspath(
            "se/simonsoft/cms/indexing/xml/datasets/releasetranslation");
    CmsRepositoryFilexml repo = new CmsRepositoryFilexml("http://localtesthost/svn/testaut1", repoSource);
    FilexmlRepositoryReadonly filexml = new FilexmlRepositoryReadonly(repo);

    SolrServer reposxml = indexing.enable(new ReposTestBackendFilexml(filexml)).getCore("reposxml");

    SolrDocument elem;//from  ww  w  .j  a v  a2s  .  c  om
    // search for the first title
    SolrDocumentList findUsingRid = reposxml
            .query(new SolrQuery("a_cms.rid:2gyvymn15kv0001 AND prop_abx.TranslationLocale:*")).getResults();
    assertEquals("Should find the first title in the release (though actually a future one)", 1,
            findUsingRid.getNumFound());
    elem = findUsingRid.get(0);
    assertEquals("get the rid attribute", "2gyvymn15kv0001", elem.getFieldValue("a_cms.rid"));
    assertEquals("get the parent project id attribute", "0001",
            elem.getFieldValue("ia_cms.translation-project"));

    findUsingRid = reposxml.query(new SolrQuery("a_cms.rid:2gyvymn15kv0006 AND prop_abx.TranslationLocale:*"))
            .getResults();
    assertEquals("Should find a para", 1, findUsingRid.getNumFound());
    elem = findUsingRid.get(0);
    assertEquals("verify it is a para", "p", elem.getFieldValue("name"));
    assertEquals("get the rid attribute", "2gyvymn15kv0006", elem.getFieldValue("a_cms.rid"));
    assertEquals("get the ancestor rid attribute (in this case parent rid)", "2gyvymn15kv0004",
            elem.getFieldValue("aa_cms.rid"));
    assertEquals("get the inherited rid attribute (in this case context element rid)", "2gyvymn15kv0006",
            elem.getFieldValue("ia_cms.rid"));
    assertEquals("get the root rid attribute", "2gyvymn15kv0000", elem.getFieldValue("ra_cms.rid"));
    assertEquals("get the preceding sibling rid attribute", "2gyvymn15kv0005",
            elem.getFieldValue("sa_cms.rid"));
    assertNull("get the project id attribute", elem.getFieldValue("a_cms.translation-project"));
    assertEquals("get the parent project id attribute", "0001",
            elem.getFieldValue("ia_cms.translation-project"));

    assertEquals("get the inherited rlogicalid attribute",
            "x-svn:///svn/testaut1^/tms/xml/Secs/First%20chapter.xml?p=4",
            elem.getFieldValue("ia_cms.rlogicalid"));
    assertEquals("get Release checksum (based on first test result)",
            "c5fed03ed1304cecce75d63aee2ada2b0f2326af", elem.getFieldValue("c_sha1_release_source_reuse"));
}

From source file:se.simonsoft.cms.indexing.xml.HandlerXmlIntegrationTest.java

License:Apache License

@Test
public void testJoinReleasetranslationNoExtraFields() throws SolrServerException {
    FilexmlSourceClasspath repoSource = new FilexmlSourceClasspath(
            "se/simonsoft/cms/indexing/xml/datasets/releasetranslation");
    CmsRepositoryFilexml repo = new CmsRepositoryFilexml("http://localtesthost/svn/testaut1", repoSource);
    FilexmlRepositoryReadonly filexml = new FilexmlRepositoryReadonly(repo);

    SolrServer reposxml = indexing.enable(new ReposTestBackendFilexml(filexml)).getCore("reposxml");

    // search for the first title
    SolrDocumentList findUsingRid = reposxml
            .query(new SolrQuery("a_cms.rid:2gyvymn15kv0001 AND -prop_abx.TranslationLocale:*")).getResults();
    assertEquals("Should find the first title in the release (though actually a future one)", 1,
            findUsingRid.getNumFound());
    String wantedReleaseSha1 = (String) findUsingRid.get(0).getFieldValue("c_sha1_source_reuse");

    SolrDocumentList findAllMatchesWithoutJoin = reposxml
            .query(new SolrQuery("c_sha1_source_reuse:" + wantedReleaseSha1)).getResults();
    assertEquals("Could search for the checksum in all xml", 1, findAllMatchesWithoutJoin.getNumFound());

    SolrQuery q = new SolrQuery("c_sha1_source_reuse:" + wantedReleaseSha1
    // Because we join on the same filed name we must explicitly state that the hit should be a release, or In_Translation items would join with themselves and match
    // Do we have a release specific field that is not copied to translations? For now just exclude translations.
            + " AND -prop_abx.TranslationLocale:*"
            // Haven't found how to combine two criterias on the join into a single join, when there's also criteria on the actual match (see join test above)
            + " AND {!join from=prop_abx.AuthorMaster to=prop_abx.AuthorMaster}prop_abx.TranslationLocale:sv-SE"
            + " AND {!join from=prop_abx.AuthorMaster to=prop_abx.AuthorMaster}reusevalue:1");
    SolrDocumentList findReusevalue = reposxml.query(q).getResults();
    assertEquals(1, findReusevalue.getNumFound());
    // TODO with the current data set it is impossible to assert that we don't get false positives with the above query
    // Would need another release with an Obsolete sv-SE translation and a reusevalue=1 de-DE one, which probably would match falsely
}

From source file:se.simonsoft.cms.indexing.xml.HandlerXmlIntegrationTest.java

License:Apache License

/** 
 * This kind of join is not used, just work in progress.
 * @throws SolrServerException//from   www  . ja v a  2  s.c  o  m
 */
@Test
@Ignore
public void testJoinReleasetranslation() throws SolrServerException {
    FilexmlSourceClasspath repoSource = new FilexmlSourceClasspath(
            "se/simonsoft/cms/indexing/xml/datasets/releasetranslation");
    CmsRepositoryFilexml repo = new CmsRepositoryFilexml("http://localtesthost/svn/testaut1", repoSource);
    FilexmlRepositoryReadonly filexml = new FilexmlRepositoryReadonly(repo);

    SolrServer reposxml = indexing.enable(new ReposTestBackendFilexml(filexml)).getCore("reposxml");

    // search for the first title
    SolrDocumentList findUsingRid = reposxml
            .query(new SolrQuery("a_cms.rid:2gyvymn15kv0001 AND -prop_abx.TranslationLocale:*")).getResults();
    assertEquals("Should find the first title in the release (though actually a future one)", 1,
            findUsingRid.getNumFound());
    String wantedReleaseSha1 = (String) findUsingRid.get(0).getFieldValue("c_sha1_source_reuse");

    SolrQuery q = new SolrQuery("c_sha1_source_reuse:" + wantedReleaseSha1
            + " AND {!join to=pathfull from=reuserelease}reusevaluelocale:1sv-SE");
    SolrDocumentList findReusevalue = reposxml.query(q).getResults();
    assertEquals(1, findReusevalue.getNumFound());
    String ridForSourceAndReusereadyLookup = (String) findReusevalue.get(0).getFieldValue("a_cms.rid");
    assertEquals("2gyvymn15kv0001", ridForSourceAndReusereadyLookup);
}