<commit_before>// Copyright 2013 <NAME> <<EMAIL>>
// 
// This code is available under the MIT license.
// See the LICENSE file for details.
package services;

import java.nio.file.Path;
import java.util.Arrays;
import java.util.Collection;
import java.util.Date;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;

import notifiers.Email;

import org.apache.commons.lang.RandomStringUtils;

import controllers.ParentController;

import access.AccessType;

import play.modules.search.Query;
import play.modules.search.Query.SearchException;
import play.modules.search.Search;
import play.mvc.Util;

import models.Activation;
import models.DatabaseImage;
import models.Directory;
import models.ImageAttribute;
import models.ImageSetMembership;
import models.Paper;
import models.Permission;
import models.PermissionedModel;
import models.Project;
import models.User;

public class SearchService {
	public static Set<DatabaseImage> performLuceneSearch(String value, Project project) throws Exception {
		try {
			Set<DatabaseImage> results = new HashSet<DatabaseImage>();
			
			if (value.trim().length() == 0) return results;
			
			String lucene = String.format("project:%d AND value:%s*",project.id.longValue(),value);
			Query query = Search.search(lucene, ImageAttribute.class);
			List<ImageAttribute> found = query.all().fetch();
			

			List<DatabaseImage> imageResults = DatabaseImage.find("byPathLike","%"+value+"%").fetch(); 

			for (DatabaseImage image : imageResults) {
				results.add(image);
			}
			
			for (ImageAttribute attr : found) {
				results.add(attr.image);
			}
			
			return results;
		} catch (SearchException se) {
			//Search.getCurrentStore().rebuild(ImageAttribute.class.getName());
			throw se;
		}
	}
	
	public static Set<DatabaseImage> performDatabaseSearch(String value, Project project) throws Exception {
		Set<DatabaseImage> results = new HashSet<DatabaseImage>();
		
		if (value.trim().length() == 0) return results;
		
		List<ImageAttribute> found = ImageAttribute.find("byProjectAndValueLike",project,"%"+value+"%").fetch();
		List<DatabaseImage> imageResults = DatabaseImage.find("byPathLike","%"+value+"%").fetch(); 

		for (DatabaseImage image : imageResults) {
			results.add(image);
		}
		<commit_msg>fixing database search so that it doesnt depend on the project<commit_after>// Copyright 2013 <NAME> <<EMAIL>>
// 
// This code is available under the MIT license.
// See the LICENSE file for details.
package services;

import java.nio.file.Path;
import java.util.Arrays;
import java.util.Collection;
import java.util.Date;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;

import notifiers.Email;

import org.apache.commons.lang.RandomStringUtils;

import controllers.ParentController;

import access.AccessType;

import play.modules.search.Query;
import play.modules.search.Query.SearchException;
import play.modules.search.Search;
import play.mvc.Util;

import models.Activation;
import models.DatabaseImage;
import models.Directory;
import models.ImageAttribute;
import models.ImageSetMembership;
import models.Paper;
import models.Permission;
import models.PermissionedModel;
import models.Project;
import models.User;

public class SearchService {
	public static Set<DatabaseImage> performLuceneSearch(String value, Project project) throws Exception {
		try {
			Set<DatabaseImage> results = new HashSet<DatabaseImage>();
			
			if (value.trim().length() == 0) return results;
			
			String lucene = String.format("project:%d AND value:%s*",project.id.longValue(),value);
			Query query = Search.search(lucene, ImageAttribute.class);
			List<ImageAttribute> found = query.all().fetch();
			

			List<DatabaseImage> imageResults = DatabaseImage.find("byPathLike","%"+value+"%").fetch(); 

			for (DatabaseImage image : imageResults) {
				results.add(image);
			}
			
			for (ImageAttribute attr : found) {
				results.add(attr.image);
			}
			
			return results;
		} catch (SearchException se) {
			//Search.getCurrentStore().rebuild(ImageAttribute.class.getName());
			throw se;
		}
	}
	
	public static Set<DatabaseImage> performDatabaseSearch(String value, Project project) throws Exception {
		Set<DatabaseImage> results = new HashSet<DatabaseImage>();
		
		if (value.trim().length() == 0) return results;
		
		List<ImageAttribute> found = ImageAttribute.find("byValueLike","%"+value+"%").fetch();
		//List<ImageAttribute> found = ImageAttribute.find("byProjectAndValueLike",project,"%"+value+"%").fetch();
		List<DatabaseImage> imageResults = DatabaseImage.find("byPathLike","%"+value+"%").fetch(); 

		for (DatabaseImage image : imageResults) {
			results.add(image);
		}
		
{'fraction_non_alphanumeric': 0.1282755705832629, 'fraction_numerical': 0.00253592561284869, 'mean_word_length': 4.9835651074589125, 'pattern_counts': {'":': 0, '<': 30, '<?xml version=': 0, '>': 30, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1661628', 'n_tokens_mistral': 1503, 'n_tokens_neox': 1345, 'n_words': 327}