You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by Jamie Johnson <je...@gmail.com> on 2012/03/03 04:19:37 UTC

Custom Component which removes documents from response

On a previous version of a solr snapshot we had a custom component
which did the following


		boolean fsv =
req.getParams().getBool(ResponseBuilder.FIELD_SORT_VALUES,false);
	    if(fsv){
	    	NamedList sortVals = (NamedList) rsp.getValues().get("sort_values");
	    	if(sortVals != null){
	    		Sort sort = searcher.weightSort(rb.getSortSpec().getSort());
	    		SortField[] sortFields = sort==null ? new
SortField[]{SortField.FIELD_SCORE} : sort.getSort();
			
	    		for (SortField sortField: sortFields) {
	    			String fieldname = sortField.getField();
	    			if(sortVals.get(fieldname) == null)
	    				continue;
	    			ArrayList<Object> list = (ArrayList<Object>) sortVals.get(fieldname);
	    			list.removeAll(filteredDocs);
	    			
	    		}
	    	}
	    }

where filteredDocs is an ArrayList of integers containing the
documents to remove from sort vals.  On the current solr on trunk
sortVals is now an Object[].  I had tried to update by I had thought
that doing the following would provide the same result, but alas it
does not.  Am I missing something that should be happening here?


		boolean fsv =
req.getParams().getBool(ResponseBuilder.FIELD_SORT_VALUES,false);
	    if(fsv){
	    	NamedList sortVals = (NamedList) rsp.getValues().get("sort_values");
	    	if(sortVals != null){
	    		Sort sort = searcher.weightSort(rb.getSortSpec().getSort());
	    		SortField[] sortFields = sort==null ? new
SortField[]{SortField.FIELD_SCORE} : sort.getSort();
			
	    		for (SortField sortField: sortFields) {
	    			String fieldname = sortField.getField();
	    			if(sortVals.get(fieldname) == null)
	    				continue;
	    			Object[] sortValue = (Object[])sortVals.get(fieldname);
	    			List<Object> sortValueList = new ArrayList<Object>(sortValue.length);
	    			sortValueList.removeAll(filteredDocs);
	    			
	    			sortVals.remove(fieldname);
	    			sortVals.add(fieldname, sortValueList.toArray());
	    			
	    		}
	    	}
	    }

Re: Custom Component which removes documents from response

Posted by Jamie Johnson <je...@gmail.com>.
I suppose it would help if I populated the list I try to remove things
from....I believe it's working once I did that.  Now that this is out
there, is there a better way to do something like this?

On Fri, Mar 2, 2012 at 10:19 PM, Jamie Johnson <je...@gmail.com> wrote:
> On a previous version of a solr snapshot we had a custom component
> which did the following
>
>
>                boolean fsv =
> req.getParams().getBool(ResponseBuilder.FIELD_SORT_VALUES,false);
>            if(fsv){
>                NamedList sortVals = (NamedList) rsp.getValues().get("sort_values");
>                if(sortVals != null){
>                        Sort sort = searcher.weightSort(rb.getSortSpec().getSort());
>                        SortField[] sortFields = sort==null ? new
> SortField[]{SortField.FIELD_SCORE} : sort.getSort();
>
>                        for (SortField sortField: sortFields) {
>                                String fieldname = sortField.getField();
>                                if(sortVals.get(fieldname) == null)
>                                        continue;
>                                ArrayList<Object> list = (ArrayList<Object>) sortVals.get(fieldname);
>                                list.removeAll(filteredDocs);
>
>                        }
>                }
>            }
>
> where filteredDocs is an ArrayList of integers containing the
> documents to remove from sort vals.  On the current solr on trunk
> sortVals is now an Object[].  I had tried to update by I had thought
> that doing the following would provide the same result, but alas it
> does not.  Am I missing something that should be happening here?
>
>
>                boolean fsv =
> req.getParams().getBool(ResponseBuilder.FIELD_SORT_VALUES,false);
>            if(fsv){
>                NamedList sortVals = (NamedList) rsp.getValues().get("sort_values");
>                if(sortVals != null){
>                        Sort sort = searcher.weightSort(rb.getSortSpec().getSort());
>                        SortField[] sortFields = sort==null ? new
> SortField[]{SortField.FIELD_SCORE} : sort.getSort();
>
>                        for (SortField sortField: sortFields) {
>                                String fieldname = sortField.getField();
>                                if(sortVals.get(fieldname) == null)
>                                        continue;
>                                Object[] sortValue = (Object[])sortVals.get(fieldname);
>                                List<Object> sortValueList = new ArrayList<Object>(sortValue.length);
>                                sortValueList.removeAll(filteredDocs);
>
>                                sortVals.remove(fieldname);
>                                sortVals.add(fieldname, sortValueList.toArray());
>
>                        }
>                }
>            }