@Test public void testPrepareExecInvalidInput() { SortedSet<String> projectNames = new TreeSet<>(); SearchHelper searchHelper; env.setProjectsEnabled(true); Project project = new Project("c", "/c"); env.getProjects().put("c", project); project = new Project("java", "/java"); project.setIndexed(true); env.getProjects().put("java", project); projectNames.add("c"); projectNames.add("java"); searchHelper = this.getSearchHelper("foobar") .prepareExec(projectNames); Assert.assertNotNull(searchHelper.errorMsg); Assert.assertTrue(searchHelper.errorMsg.contains("not indexed")); Assert.assertFalse(searchHelper.errorMsg.contains("java")); projectNames.add("totally_nonexistent_project"); searchHelper = this.getSearchHelper("foobar") .prepareExec(projectNames); Assert.assertNotNull(searchHelper.errorMsg); Assert.assertTrue(searchHelper.errorMsg.contains("invalid projects")); }
public SearchHelper prepareExec(SortedSet<String> projects) { if (redirect != null || errorMsg != null) { return this; } settingsHelper = null; try { indexDir = new File(dataRoot, IndexDatabase.INDEX_DIR); query = builder.build(); if (projects == null) { errorMsg = "No project selected!"; return this; } this.projects = projects; if (projects.isEmpty()) { FSDirectory dir = FSDirectory.open(indexDir.toPath()); reader = DirectoryReader.open(dir); searcher = new IndexSearcher(reader); closeOnDestroy = true; } else { closeOnDestroy = false; Set<String> invalidProjects = projects.stream(). filter(proj -> (Project.getByName(proj) == null)). collect(Collectors.toSet()); if (invalidProjects.size() > 0) { errorMsg = "Project list contains invalid projects: " + String.join(", ", invalidProjects); return this; } Set<Project> notIndexedProjects = projects.stream(). map(x -> Project.getByName(x)). filter(proj -> !proj.isIndexed()). collect(Collectors.toSet()); if (notIndexedProjects.size() > 0) { errorMsg = "Some of the projects to be searched are not indexed yet: " + String.join(", ", notIndexedProjects.stream(). map(proj -> proj.getName()). collect(Collectors.toSet())); return this; } reader = RuntimeEnvironment.getInstance().getMultiReader( projects, searcherList); if (reader != null) { searcher = new IndexSearcher(reader); } else { errorMsg = "Failed to initialize search. Check the index."; return this; } } switch (order) { case LASTMODIFIED: sort = new Sort(new SortField(QueryBuilder.DATE, SortField.Type.STRING, true)); break; case BY_PATH: sort = new Sort(new SortField(QueryBuilder.FULLPATH, SortField.Type.STRING)); break; default: sort = Sort.RELEVANCE; break; } checker = new DirectSpellChecker(); } catch (ParseException e) { errorMsg = PARSE_ERROR_MSG + e.getMessage(); } catch (FileNotFoundException e) { errorMsg = "Index database(s) not found."; } catch (IOException e) { errorMsg = e.getMessage(); } return this; }
SearchHelper { public SearchHelper prepareExec(SortedSet<String> projects) { if (redirect != null || errorMsg != null) { return this; } settingsHelper = null; try { indexDir = new File(dataRoot, IndexDatabase.INDEX_DIR); query = builder.build(); if (projects == null) { errorMsg = "No project selected!"; return this; } this.projects = projects; if (projects.isEmpty()) { FSDirectory dir = FSDirectory.open(indexDir.toPath()); reader = DirectoryReader.open(dir); searcher = new IndexSearcher(reader); closeOnDestroy = true; } else { closeOnDestroy = false; Set<String> invalidProjects = projects.stream(). filter(proj -> (Project.getByName(proj) == null)). collect(Collectors.toSet()); if (invalidProjects.size() > 0) { errorMsg = "Project list contains invalid projects: " + String.join(", ", invalidProjects); return this; } Set<Project> notIndexedProjects = projects.stream(). map(x -> Project.getByName(x)). filter(proj -> !proj.isIndexed()). collect(Collectors.toSet()); if (notIndexedProjects.size() > 0) { errorMsg = "Some of the projects to be searched are not indexed yet: " + String.join(", ", notIndexedProjects.stream(). map(proj -> proj.getName()). collect(Collectors.toSet())); return this; } reader = RuntimeEnvironment.getInstance().getMultiReader( projects, searcherList); if (reader != null) { searcher = new IndexSearcher(reader); } else { errorMsg = "Failed to initialize search. Check the index."; return this; } } switch (order) { case LASTMODIFIED: sort = new Sort(new SortField(QueryBuilder.DATE, SortField.Type.STRING, true)); break; case BY_PATH: sort = new Sort(new SortField(QueryBuilder.FULLPATH, SortField.Type.STRING)); break; default: sort = Sort.RELEVANCE; break; } checker = new DirectSpellChecker(); } catch (ParseException e) { errorMsg = PARSE_ERROR_MSG + e.getMessage(); } catch (FileNotFoundException e) { errorMsg = "Index database(s) not found."; } catch (IOException e) { errorMsg = e.getMessage(); } return this; } }
SearchHelper { public SearchHelper prepareExec(SortedSet<String> projects) { if (redirect != null || errorMsg != null) { return this; } settingsHelper = null; try { indexDir = new File(dataRoot, IndexDatabase.INDEX_DIR); query = builder.build(); if (projects == null) { errorMsg = "No project selected!"; return this; } this.projects = projects; if (projects.isEmpty()) { FSDirectory dir = FSDirectory.open(indexDir.toPath()); reader = DirectoryReader.open(dir); searcher = new IndexSearcher(reader); closeOnDestroy = true; } else { closeOnDestroy = false; Set<String> invalidProjects = projects.stream(). filter(proj -> (Project.getByName(proj) == null)). collect(Collectors.toSet()); if (invalidProjects.size() > 0) { errorMsg = "Project list contains invalid projects: " + String.join(", ", invalidProjects); return this; } Set<Project> notIndexedProjects = projects.stream(). map(x -> Project.getByName(x)). filter(proj -> !proj.isIndexed()). collect(Collectors.toSet()); if (notIndexedProjects.size() > 0) { errorMsg = "Some of the projects to be searched are not indexed yet: " + String.join(", ", notIndexedProjects.stream(). map(proj -> proj.getName()). collect(Collectors.toSet())); return this; } reader = RuntimeEnvironment.getInstance().getMultiReader( projects, searcherList); if (reader != null) { searcher = new IndexSearcher(reader); } else { errorMsg = "Failed to initialize search. Check the index."; return this; } } switch (order) { case LASTMODIFIED: sort = new Sort(new SortField(QueryBuilder.DATE, SortField.Type.STRING, true)); break; case BY_PATH: sort = new Sort(new SortField(QueryBuilder.FULLPATH, SortField.Type.STRING)); break; default: sort = Sort.RELEVANCE; break; } checker = new DirectSpellChecker(); } catch (ParseException e) { errorMsg = PARSE_ERROR_MSG + e.getMessage(); } catch (FileNotFoundException e) { errorMsg = "Index database(s) not found."; } catch (IOException e) { errorMsg = e.getMessage(); } return this; }  }
SearchHelper { public SearchHelper prepareExec(SortedSet<String> projects) { if (redirect != null || errorMsg != null) { return this; } settingsHelper = null; try { indexDir = new File(dataRoot, IndexDatabase.INDEX_DIR); query = builder.build(); if (projects == null) { errorMsg = "No project selected!"; return this; } this.projects = projects; if (projects.isEmpty()) { FSDirectory dir = FSDirectory.open(indexDir.toPath()); reader = DirectoryReader.open(dir); searcher = new IndexSearcher(reader); closeOnDestroy = true; } else { closeOnDestroy = false; Set<String> invalidProjects = projects.stream(). filter(proj -> (Project.getByName(proj) == null)). collect(Collectors.toSet()); if (invalidProjects.size() > 0) { errorMsg = "Project list contains invalid projects: " + String.join(", ", invalidProjects); return this; } Set<Project> notIndexedProjects = projects.stream(). map(x -> Project.getByName(x)). filter(proj -> !proj.isIndexed()). collect(Collectors.toSet()); if (notIndexedProjects.size() > 0) { errorMsg = "Some of the projects to be searched are not indexed yet: " + String.join(", ", notIndexedProjects.stream(). map(proj -> proj.getName()). collect(Collectors.toSet())); return this; } reader = RuntimeEnvironment.getInstance().getMultiReader( projects, searcherList); if (reader != null) { searcher = new IndexSearcher(reader); } else { errorMsg = "Failed to initialize search. Check the index."; return this; } } switch (order) { case LASTMODIFIED: sort = new Sort(new SortField(QueryBuilder.DATE, SortField.Type.STRING, true)); break; case BY_PATH: sort = new Sort(new SortField(QueryBuilder.FULLPATH, SortField.Type.STRING)); break; default: sort = Sort.RELEVANCE; break; } checker = new DirectSpellChecker(); } catch (ParseException e) { errorMsg = PARSE_ERROR_MSG + e.getMessage(); } catch (FileNotFoundException e) { errorMsg = "Index database(s) not found."; } catch (IOException e) { errorMsg = e.getMessage(); } return this; }  static Set<Map.Entry<String, String>> getFileTypeDescriptions(); SearchHelper prepareExec(SortedSet<String> projects); SearchHelper prepareExec(Project project); SearchHelper executeQuery(); List<Suggestion> getSuggestions(); SearchHelper prepareSummary(); void destroy(); int searchSingle(File file); int getTabSize(Project proj); String getPrimeRelativePath(String project, String relativePath); }
SearchHelper { public SearchHelper prepareExec(SortedSet<String> projects) { if (redirect != null || errorMsg != null) { return this; } settingsHelper = null; try { indexDir = new File(dataRoot, IndexDatabase.INDEX_DIR); query = builder.build(); if (projects == null) { errorMsg = "No project selected!"; return this; } this.projects = projects; if (projects.isEmpty()) { FSDirectory dir = FSDirectory.open(indexDir.toPath()); reader = DirectoryReader.open(dir); searcher = new IndexSearcher(reader); closeOnDestroy = true; } else { closeOnDestroy = false; Set<String> invalidProjects = projects.stream(). filter(proj -> (Project.getByName(proj) == null)). collect(Collectors.toSet()); if (invalidProjects.size() > 0) { errorMsg = "Project list contains invalid projects: " + String.join(", ", invalidProjects); return this; } Set<Project> notIndexedProjects = projects.stream(). map(x -> Project.getByName(x)). filter(proj -> !proj.isIndexed()). collect(Collectors.toSet()); if (notIndexedProjects.size() > 0) { errorMsg = "Some of the projects to be searched are not indexed yet: " + String.join(", ", notIndexedProjects.stream(). map(proj -> proj.getName()). collect(Collectors.toSet())); return this; } reader = RuntimeEnvironment.getInstance().getMultiReader( projects, searcherList); if (reader != null) { searcher = new IndexSearcher(reader); } else { errorMsg = "Failed to initialize search. Check the index."; return this; } } switch (order) { case LASTMODIFIED: sort = new Sort(new SortField(QueryBuilder.DATE, SortField.Type.STRING, true)); break; case BY_PATH: sort = new Sort(new SortField(QueryBuilder.FULLPATH, SortField.Type.STRING)); break; default: sort = Sort.RELEVANCE; break; } checker = new DirectSpellChecker(); } catch (ParseException e) { errorMsg = PARSE_ERROR_MSG + e.getMessage(); } catch (FileNotFoundException e) { errorMsg = "Index database(s) not found."; } catch (IOException e) { errorMsg = e.getMessage(); } return this; }  static Set<Map.Entry<String, String>> getFileTypeDescriptions(); SearchHelper prepareExec(SortedSet<String> projects); SearchHelper prepareExec(Project project); SearchHelper executeQuery(); List<Suggestion> getSuggestions(); SearchHelper prepareSummary(); void destroy(); int searchSingle(File file); int getTabSize(Project proj); String getPrimeRelativePath(String project, String relativePath); static final String REQUEST_ATTR; public int SPELLCHECK_SUGGEST_WORD_COUNT; public File dataRoot; public String contextPath; public File sourceRoot; public EftarFileReader desc; public int start; public int maxItems; public QueryBuilder builder; public SortOrder order; public boolean parallel; public boolean isCrossRefSearch; public boolean isGuiSearch; public String redirect; public boolean noRedirect; public String errorMsg; public IndexSearcher searcher; public ScoreDoc[] hits; public long totalHits; public Query query; public SortedSet<String> projects; public Context sourceContext; public Summarizer summarizer; public HistoryContext historyContext; static final String PARSE_ERROR_MSG; }