コード例 #1
0
 /**
  * @return the query used to fetch the documents from the Solr index
  * @throws SolrIndexerException if we fail to obtain a query for the configured root entity
  */
 private SolrQuery getQuery() throws SolrIndexerException {
   if (query == null) {
     query = new SolrQuery(solrReferenceResolver.getQuery(rootReference));
     query.setFields(
         FieldUtils.WIKI,
         FieldUtils.SPACES,
         FieldUtils.NAME,
         FieldUtils.DOCUMENT_LOCALE,
         FieldUtils.VERSION);
     query.addFilterQuery(FieldUtils.TYPE + ':' + EntityType.DOCUMENT.name());
     // We sort by ID, which is normally the serialized document reference, in order to ensure this
     // iterator has
     // the same order as the database iterator.
     query.addSort(FieldUtils.ID, ORDER.asc);
     // Paginate using a cursor because it performs better than basic pagination (using absolute
     // offset,
     // especially when the offset is big) and because the impact of index modifications is much
     // smaller (and we
     // plan to update the index to match the database during the synchronization process).
     // See https://cwiki.apache.org/confluence/display/solr/Pagination+of+Results
     query.set(CursorMarkParams.CURSOR_MARK_PARAM, CursorMarkParams.CURSOR_MARK_START);
     query.setRows(LIMIT);
   }
   return query;
 }
コード例 #2
0
 /**
  * @return the query used to fetch the documents from the Solr index
  * @throws SolrIndexerException if we fail to obtain a query for the configured root entity
  */
 private SolrQuery getQuery() throws SolrIndexerException {
   if (query == null) {
     query = new SolrQuery(solrReferenceResolver.getQuery(rootReference));
     query.setFields(
         FieldUtils.WIKI,
         FieldUtils.SPACE,
         FieldUtils.NAME,
         FieldUtils.DOCUMENT_LOCALE,
         FieldUtils.VERSION);
     query.addFilterQuery(FieldUtils.TYPE + ':' + EntityType.DOCUMENT.name());
     // We must add the unique key field (ID in our case) to the list of sort fields (as a tie
     // breaker) in order
     // to use the cursor-based pagination.
     query
         .addSort(FieldUtils.WIKI, ORDER.asc)
         .addSort(FieldUtils.SPACE_EXACT, ORDER.asc)
         .addSort(FieldUtils.NAME_EXACT, ORDER.asc)
         .addSort(FieldUtils.DOCUMENT_LOCALE, ORDER.asc)
         .addSort(FieldUtils.ID, ORDER.asc);
     // Speed up the query by disabling the faceting and the highlighting.
     query.set(FacetParams.FACET, false);
     query.set(HighlightParams.HIGHLIGHT, false);
     // Paginate using a cursor because it performs better than basic pagination (using absolute
     // offset,
     // especially when the offset is big) and because the impact of index modifications is much
     // smaller (and we
     // plan to update the index to match the database during the synchronization process).
     // See https://cwiki.apache.org/confluence/display/solr/Pagination+of+Results
     query.set(CursorMarkParams.CURSOR_MARK_PARAM, CursorMarkParams.CURSOR_MARK_START);
     query.setRows(LIMIT);
   }
   return query;
 }
  @Test
  public void getSimpleDocument() throws Exception {
    // Mock

    // No objects (and no comments).
    when(mockDocument.getComments()).thenReturn(new Vector<BaseObject>());
    when(mockDocument.getXObjects()).thenReturn(new HashMap<DocumentReference, List<BaseObject>>());

    // Call

    DocumentSolrMetadataExtractor extractor =
        (DocumentSolrMetadataExtractor) mocker.getComponentUnderTest();
    SolrInputDocument solrDocument = extractor.getSolrDocument(documentReference);

    // Assert and verify

    Assert.assertEquals(
        String.format("%s_%s", documentReferenceString, language),
        solrDocument.getFieldValue(Fields.ID));

    Assert.assertEquals(
        documentReference.getWikiReference().getName(), solrDocument.getFieldValue(Fields.WIKI));
    Assert.assertEquals(
        documentReference.getLastSpaceReference().getName(),
        solrDocument.getFieldValue(Fields.SPACE));
    Assert.assertEquals(documentReference.getName(), solrDocument.getFieldValue(Fields.NAME));

    Assert.assertEquals(language, solrDocument.getFieldValue(Fields.LANGUAGE));
    Assert.assertEquals(hidden, solrDocument.getFieldValue(Fields.HIDDEN));
    Assert.assertEquals(EntityType.DOCUMENT.name(), solrDocument.getFieldValue(Fields.TYPE));

    Assert.assertEquals(documentReferenceLocalString, solrDocument.getFieldValue(Fields.FULLNAME));

    Assert.assertEquals(
        title,
        solrDocument.getFieldValue(
            String.format(Fields.MULTILIGNUAL_FORMAT, Fields.TITLE, language)));
    Assert.assertEquals(
        renderedContent,
        solrDocument.getFieldValue(
            String.format(Fields.MULTILIGNUAL_FORMAT, Fields.DOCUMENT_CONTENT, language)));

    Assert.assertEquals(version, solrDocument.getFieldValue(Fields.VERSION));

    Assert.assertEquals(authorString, solrDocument.getFieldValue(Fields.AUTHOR));
    Assert.assertEquals(authorDisplay, solrDocument.getFieldValue(Fields.AUTHOR_DISPLAY));
    Assert.assertEquals(creatorString, solrDocument.getFieldValue(Fields.CREATOR));
    Assert.assertEquals(creatorDisplay, solrDocument.getFieldValue(Fields.CREATOR_DISPLAY));

    Assert.assertEquals(creationDate, solrDocument.getFieldValue(Fields.CREATIONDATE));
    Assert.assertEquals(date, solrDocument.get(Fields.DATE).getValue());
  }