gt: 			if (filterQueryString.trim().length() > 0) {
context: package at.knowcenter.recommender.solrpowered.engine.strategy.social.cf.network;
  
  import java.text.DecimalFormat;
  import java.util.ArrayList;
  import java.util.Collection;
  import java.util.Collections;
  import java.util.Comparator;
  import java.util.HashMap;
  import java.util.HashSet;
  import java.util.List;
  import java.util.Map;
  import java.util.Set;
  import java.util.TreeMap;
  
  import org.apache.solr.client.solrj.SolrServer;
  import org.apache.solr.client.solrj.SolrServerException;
  import org.apache.solr.client.solrj.response.FacetField;
  import org.apache.solr.client.solrj.response.FacetField.Count;
  import org.apache.solr.client.solrj.response.QueryResponse;
  import org.apache.solr.common.SolrDocumentList;
  import org.apache.solr.common.params.ModifiableSolrParams;
  
  import at.knowcenter.recommender.solrpowered.engine.filtering.ContentFilter;
  import at.knowcenter.recommender.solrpowered.engine.strategy.RecommendStrategy;
  import at.knowcenter.recommender.solrpowered.engine.strategy.StrategyType;
  import at.knowcenter.recommender.solrpowered.engine.strategy.marketplace.cf.ReviewBasedRec;
  import at.knowcenter.recommender.solrpowered.engine.utils.CFQueryBuilder;
  import at.knowcenter.recommender.solrpowered.engine.utils.RecommendationQueryUtils;
  import at.knowcenter.recommender.solrpowered.evaluation.UserSimilarityTracker;
  import at.knowcenter.recommender.solrpowered.model.CustomerAction;
  import at.knowcenter.recommender.solrpowered.model.Resource;
  import at.knowcenter.recommender.solrpowered.model.SocialAction;
  import at.knowcenter.recommender.solrpowered.services.SolrServiceContainer;
  import at.knowcenter.recommender.solrpowered.services.impl.actions.RecommendQuery;
  import at.knowcenter.recommender.solrpowered.services.impl.actions.RecommendResponse;
  import at.knowcenter.recommender.solrpowered.services.impl.item.ItemQuery;
  
  /**
   * Collaborative Filtering Recommender strategy
   * @author elacic
   *
   */
  public class CommonNeighborBasedRec implements RecommendStrategy {
  
  	public static int MAX_USER_OCCURENCE_COUNT = CFQueryBuilder.MAX_USER_OCCURENCE_COUNT;
  	private List<String> alreadyBoughtProducts;
  	private ContentFilter contentFilter;
  
  	@Override
  	public RecommendResponse recommend(RecommendQuery query, Integer maxReuslts){
  		ModifiableSolrParams solrParams = new ModifiableSolrParams();
  		QueryResponse response = null;
  		RecommendResponse searchResponse = new RecommendResponse();
  		
  		long step0ElapsedTime = 0;
  		long step1ElapsedTime;
  		List<String> recommendations = new ArrayList<String>();
  
  		try {
  			// STEP 0 - get products from a user
  			if (query.getUser() != null ) {
  				if (query.getProductIds() == null || query.getProductIds().size() == 0) {
  					if (alreadyBoughtProducts != null) {
  						query.setProductIds(alreadyBoughtProducts);
  					} else {
  					}
  				}
  			}
  			
  			solrParams = getInteractions(query.getUser());
  
  			response = SolrServiceContainer.getInstance().getSocialActionService().getSolrServer().query(solrParams);
  			step1ElapsedTime = response.getElapsedTime();
  			
  			
  			List<SocialAction> socialUsers = response.getBeans(SocialAction.class);
  			
  			if (socialUsers.size() == 0) {
  				searchResponse.setNumFound(0);
  				searchResponse.setResultItems(recommendations);
  				searchResponse.setElapsedTime(-1);
  				return searchResponse;
  			}
  			
  			SocialAction currentUserInteractions = socialUsers.get(0);
  			if (currentUserInteractions.getUserId().equals(query.getUser())){
  				socialUsers.remove(0);
  			} else {
  				currentUserInteractions = null;
  			}
  			
  			Set<String> currentUserNeighbors = new HashSet<String>();
  			
  			if (currentUserInteractions != null) {
  				List<String> usersThatLikedMe = currentUserInteractions.getUsersThatLikedMe();
  				List<String> usersThatCommentedOnMyPost = currentUserInteractions.getUsersThatCommentedOnMyPost();
  				List<String> usersThatPostedASnapshopToMe = currentUserInteractions.getUsersThatPostedASnapshopToMe();
  				List<String> usersThatPostedOnMyWall = currentUserInteractions.getUsersThatPostedOnMyWall();
  				
  				if (usersThatLikedMe != null)
  					currentUserNeighbors.addAll(usersThatLikedMe);
  				
  				if (usersThatCommentedOnMyPost != null)
  					currentUserNeighbors.addAll(usersThatCommentedOnMyPost);
  				
  				if (usersThatPostedASnapshopToMe != null)
  					currentUserNeighbors.addAll(usersThatPostedASnapshopToMe);
  				
  				if (usersThatPostedOnMyWall != null)
  					currentUserNeighbors.addAll(usersThatPostedOnMyWall);
  			}
  			
  			for (SocialAction socialUser : socialUsers) {
  				currentUserNeighbors.add(socialUser.getUserId());
  			}
  			
  
  			solrParams = getComparingParams(currentUserNeighbors);
  			solrParams.set("fq", "-id:" + query.getUser());
  
  
  			response = SolrServiceContainer.getInstance().getSocialActionService().getSolrServer().query(solrParams);
  			step1ElapsedTime = response.getElapsedTime();
  			
  			
  			List<SocialAction> neighborActions = response.getBeans(SocialAction.class);
  
  			Map<String, Set<String>> otherUsersNeighbors = new HashMap<String, Set<String>>();
  			
  			for (SocialAction socialUser : neighborActions) {
  				List<String> usersThatCommentedOnMyPost = socialUser.getUsersThatCommentedOnMyPost();
  				List<String> usersThatLikedMe = socialUser.getUsersThatLikedMe();
  				List<String> usersThatPostedASnapshopToMe = socialUser.getUsersThatPostedASnapshopToMe();
  				List<String> usersThatPostedOnMyWall = socialUser.getUsersThatPostedOnMyWall();
  
  				String user = socialUser.getUserId();
  				
  				Set<String> neighbors = otherUsersNeighbors.get(user);
  				
  				if (neighbors == null) {
  					neighbors = new HashSet<String>();
  				}
  				
  				if (usersThatCommentedOnMyPost != null) {
  					neighbors.addAll(usersThatCommentedOnMyPost);
  					fillFurtherNeighbors(otherUsersNeighbors, usersThatCommentedOnMyPost, user);
  				}
  
  				if (usersThatLikedMe != null) {
  					neighbors.addAll(usersThatLikedMe);
  					fillFurtherNeighbors(otherUsersNeighbors, usersThatLikedMe, user);
  				}
  
  				if (usersThatPostedASnapshopToMe != null) {
  					neighbors.addAll(usersThatPostedASnapshopToMe);
  					fillFurtherNeighbors(otherUsersNeighbors, usersThatPostedASnapshopToMe, user);
  				}
  
  				if (usersThatPostedOnMyWall != null) {
  					neighbors.addAll(usersThatPostedOnMyWall);
  					fillFurtherNeighbors(otherUsersNeighbors, usersThatPostedOnMyWall, user);
  				}
  
  				otherUsersNeighbors.put(user, neighbors);
  			}
  			
  			final Map<String, Integer> commonNeighborMap = new HashMap<String, Integer>();
  			for (String user : otherUsersNeighbors.keySet()) {
  				Set<String> neighbors = new HashSet<String>(otherUsersNeighbors.get(user));
  				neighbors.retainAll(currentUserNeighbors);
  				
  				commonNeighborMap.put(user, neighbors.size());
  			}
  
  			Comparator<String> interactionCountComparator = new Comparator<String>() {
  
  				
  				@Override
  				public int compare(String a, String b) {
  					if (commonNeighborMap.get(a) > commonNeighborMap.get(b)) {
  			            return -1;
  			        } else if (commonNeighborMap.get(a).equals(commonNeighborMap.get(b))){
  			        	return 0;
  			        } else {
  			            return 1;
  			        }
  				}
  				
  			};
  			
  			final String user = query.getUser();
  			Thread t = new Thread() {
  				@Override public void run() {
  					UserSimilarityTracker.getInstance().writeToFileInt("soc_network_cn", user, commonNeighborMap);
  				}
  			};
  			t.start();
  			
  	        TreeMap<String,Integer> sorted_map = new TreeMap<String,Integer>(interactionCountComparator);
  	        sorted_map.putAll(commonNeighborMap);
  	        solrParams = getSTEP2Params(query, maxReuslts, sorted_map);
  			// TODO Facet for confidence value
  			response = SolrServiceContainer.getInstance().getResourceService().getSolrServer().query(solrParams);
  			// fill response object
  			List<Resource> beans = response.getBeans(Resource.class);
  			searchResponse.setResultItems(RecommendationQueryUtils.extractRecommendationIds(beans));
  			searchResponse.setElapsedTime(step0ElapsedTime + step1ElapsedTime + response.getElapsedTime());
  
  			SolrDocumentList docResults = response.getResults();
  			searchResponse.setNumFound(docResults.getNumFound());
  		} catch (Exception e) {
  			System.out.println(solrParams);
  			e.printStackTrace();
  			searchResponse.setNumFound(0);
  			searchResponse.setResultItems(recommendations);
  			searchResponse.setElapsedTime(-1);
  		}
  		
  		return searchResponse;
  	}
  
  
  	private void fillFurtherNeighbors(Map<String, Set<String>> usersNeighbors, List<String> users, String neighbor) {
  		for (String user : users) {
  			Set<String> neighbors = usersNeighbors.get(user);
  			if (neighbors == null) {
  				neighbors = new HashSet<String>();
  			}
  			neighbors.add(neighbor);
  			usersNeighbors.put(user, neighbors);
  		}
  	}
  
  
  	private ModifiableSolrParams getSTEP2Params(
  			RecommendQuery query, Integer maxReuslts, Map<String, Integer> userInteractionMap) {
  		ModifiableSolrParams solrParams = new ModifiableSolrParams();
  		
  		String queryString = createQueryToFindProdLikedBySimilarSocialUsers(userInteractionMap, contentFilter, MAX_USER_OCCURENCE_COUNT);
  		
  		String filterQueryString = 
  				RecommendationQueryUtils.buildFilterForContentBasedFiltering(contentFilter);
  		
  		if (alreadyBoughtProducts != null && alreadyBoughtProducts.size() > 0) {
  