Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong solr result size when index contains non-vfs documents #333

Closed
kartobi opened this issue Aug 17, 2015 · 1 comment
Closed

Wrong solr result size when index contains non-vfs documents #333

kartobi opened this issue Aug 17, 2015 · 1 comment

Comments

@kartobi
Copy link
Contributor

kartobi commented Aug 17, 2015

To seach over pages of a seperate database, I implemented a special indexer which adds them to the index of vfs resources.

The problem is, that the paging isn't working correctly.

Seems to be a bug in CmSolrIndex (line 840ff):

for (int i = 0; (i < queryResponse.getResults().size()) && (cnt < end); i++) {
    try {
        SolrDocument doc = queryResponse.getResults().get(i);
        CmsSolrDocument searchDoc = new CmsSolrDocument(doc);
        if (needsPermissionCheck(searchDoc)) {
            // only if the document is an OpenCms internal resource perform the permission check
            CmsResource resource = getResource(searchCms, searchDoc);
            if (resource != null) {
                // permission check performed successfully: the user has read permissions!
                if (cnt >= start) {
                    if (m_postProcessor != null) {
                        doc = m_postProcessor.process(
                            searchCms,
                            resource,
                            (SolrInputDocument)searchDoc.getDocument());
                    }
                    resourceDocumentList.add(new CmsSearchResource(resource, searchDoc));
                    if (null != doc) {
                        solrDocumentList.add(doc);
                    }
                    maxScore = maxScore < searchDoc.getScore() ? searchDoc.getScore() : maxScore;
                }
                allDocs.add(new CmsSearchResource(resource, searchDoc));
                cnt++;
            } else {
                visibleHitCount--;
            }
        } else {
            // if permission check is not required for this index,
            // add a pseudo resource together with document to the results
            resourceDocumentList.add(new CmsSearchResource(PSEUDO_RES, searchDoc));
            solrDocumentList.add(doc);
            maxScore = maxScore < searchDoc.getScore() ? searchDoc.getScore() : maxScore;
        }
    } catch (Exception e) {
        // should not happen, but if it does we want to go on with the next result nevertheless
        LOG.warn(Messages.get().getBundle().key(Messages.LOG_SOLR_ERR_RESULT_ITERATION_FAILED_0), e);
    }
}

When needsPermissionCheck(searchDocs) returns false, variable cnt isn't incremented, so finally the size of resourceDocumentList is wrong.

@tHerrmann
Copy link

Fixed in branch_9_5_x will be released in version 9.5.3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants