[opencms-dev] Bug in CmsSearchIndex

Claus Priisholm cpr at codedroids.com
Wed Aug 10 12:10:47 CEST 2005


Since the it is looping over the entire result set anyway in order to 
check the resources with the hasReadPermission() method the penalty has 
been paid already, it just seems to miss reporting the adjusted hit 
count (which is what you want to report on the search result page)

Rainer Vehns wrote:
> Hello all,
> 
>  
> 
> I think there is a bug in the CmsSearchIndex-class, but perhaps the 
> behaviour is desired (due to efficiency):
> 
>  
> 
> We have implemented a site with public and non-public areas using the 
> OpenCms access control mechanisms. We have indexed the whole site 
> (including public and non-public areas) for searching and everything 
> works well, except the search result count.
> 
> If the search term produces search results from the public and the 
> non-public areas, the number of results 
> (org.opencms.search.CmsSearch.getSearchResultCount()) corresponds to the 
> total number of hits, not only the number of hits the user has really 
> read-access to. For example that means, a normal (not authenticated) 
> user sees a total count of 20 hits for the search term, but he only sees 
> 5 documents in the list (which are the only documents he has access to).
> 
>  
> 
> With a patch to the class CmsSearchIndex, this could be fixed, but you 
> have to iterate over all search results each time (efficient?).
> 
>  
> 
> What do you mean?
> 
>  
> 
> I have attached a patch (based on build_6_0_0) and the modified source 
> of CmsSearchIndex.
> 
>  
> 
> Kind regards,
> 
>  
> 
> Rainer
> 
>  
> 
>  
> 
> 
> ------------------------------------------------------------------------
> 
> Index: org/opencms/search/CmsSearchIndex.java
> ===================================================================
> RCS file: /usr/local/cvs/opencms/src/org/opencms/search/CmsSearchIndex.java,v
> retrieving revision 1.54
> diff -u -r1.54 CmsSearchIndex.java
> --- org/opencms/search/CmsSearchIndex.java	27 Jun 2005 23:22:16 -0000	1.54
> +++ org/opencms/search/CmsSearchIndex.java	9 Aug 2005 21:20:41 -0000
> @@ -623,12 +623,14 @@
>                      end = hitCount;
>                  }
>  
> -                for (int i = 0, cnt = 0; i < hitCount && cnt < end; i++) {
> +                // effectiveHitCount is the total hitCount subtracted by the number of hits, to which the user has no read access
> +                int effectiveHitCount = hitCount;
> +                for (int i = 0, cnt = 0; i < hitCount; i++) {
>                      try {
>                          doc = hits.doc(i);
>                          if (hasReadPermission(cms, doc)) {
>                              // user has read permission
> -                            if (cnt >= start) {
> +                            if (cnt >= start && cnt < end) {
>                                  // do not use the resource to obtain the raw content, read it from the lucene document !
>                                  if (m_createExcerpt) {
>                                      excerpt = getExcerpt(
> @@ -640,6 +642,10 @@
>                                  searchResults.add(searchResult);
>                              }
>                              cnt++;
> +                        } else {
> +                        	
> +                        	// the user has no read access to this resource, so this resource should not be counted
> +                        	effectiveHitCount--;
>                          }
>                      } catch (Exception e) {
>                          // should not happen, but if it does we want to go on with the next result nevertheless                        
> @@ -650,7 +656,7 @@
>                  }
>  
>                  // save the total count of search results at the last index of the search result 
> -                searchResults.setHitCount(hitCount);
> +                searchResults.setHitCount(effectiveHitCount);
>              } else {
>                  searchResults.setHitCount(0);
>              }
> 
> 
> ------------------------------------------------------------------------
> 
> 
> 
> _______________________________________________
> This mail is send to you from the opencms-dev mailing list
> To change your list options, or to unsubscribe from the list, please visit
> http://mail.opencms.org/mailman/listinfo/opencms-dev

-- 
Claus Priisholm, CodeDroids ApS
cpr (you know what) codedroids.com - http://www.codedroids.com

Javadocs and other OpenCms stuff: 
http://www.codedroids.com/community/opencms



More information about the opencms-dev mailing list