@Test public void invalidQuery() { try { index.findNodes("invalid:"); fail("IllegalArgumentException expected"); } catch(IllegalArgumentException e) { assertThat(e.getMessage()).startsWith("Parsing of query failed: invalid:"); } }
public Set<Node> findNodes(String queryString) { try (DirectoryReader directoryReader = DirectoryReader.open(directory)) { IndexSearcher indexSearcher = new IndexSearcher(directoryReader); Query query = parseQuery(queryString); ScoreDoc[] hits = indexSearcher.search(query, MAX_RESULTS, Sort.INDEXORDER).scoreDocs; Set<Node> result = new HashSet<>(); for (ScoreDoc hit : hits) { Document hitDoc = indexSearcher.doc(hit.doc); String name = hitDoc.get("name"); result.add(graph.getNode(name)); } return result; } catch (IOException e) { throw new IllegalArgumentException("Finding nodes failed for query: " + queryString, e); } }
DependencyGraphIndex { public Set<Node> findNodes(String queryString) { try (DirectoryReader directoryReader = DirectoryReader.open(directory)) { IndexSearcher indexSearcher = new IndexSearcher(directoryReader); Query query = parseQuery(queryString); ScoreDoc[] hits = indexSearcher.search(query, MAX_RESULTS, Sort.INDEXORDER).scoreDocs; Set<Node> result = new HashSet<>(); for (ScoreDoc hit : hits) { Document hitDoc = indexSearcher.doc(hit.doc); String name = hitDoc.get("name"); result.add(graph.getNode(name)); } return result; } catch (IOException e) { throw new IllegalArgumentException("Finding nodes failed for query: " + queryString, e); } } }
DependencyGraphIndex { public Set<Node> findNodes(String queryString) { try (DirectoryReader directoryReader = DirectoryReader.open(directory)) { IndexSearcher indexSearcher = new IndexSearcher(directoryReader); Query query = parseQuery(queryString); ScoreDoc[] hits = indexSearcher.search(query, MAX_RESULTS, Sort.INDEXORDER).scoreDocs; Set<Node> result = new HashSet<>(); for (ScoreDoc hit : hits) { Document hitDoc = indexSearcher.doc(hit.doc); String name = hitDoc.get("name"); result.add(graph.getNode(name)); } return result; } catch (IOException e) { throw new IllegalArgumentException("Finding nodes failed for query: " + queryString, e); } } DependencyGraphIndex(DependencyGraph graph, String... numericFields); }
DependencyGraphIndex { public Set<Node> findNodes(String queryString) { try (DirectoryReader directoryReader = DirectoryReader.open(directory)) { IndexSearcher indexSearcher = new IndexSearcher(directoryReader); Query query = parseQuery(queryString); ScoreDoc[] hits = indexSearcher.search(query, MAX_RESULTS, Sort.INDEXORDER).scoreDocs; Set<Node> result = new HashSet<>(); for (ScoreDoc hit : hits) { Document hitDoc = indexSearcher.doc(hit.doc); String name = hitDoc.get("name"); result.add(graph.getNode(name)); } return result; } catch (IOException e) { throw new IllegalArgumentException("Finding nodes failed for query: " + queryString, e); } } DependencyGraphIndex(DependencyGraph graph, String... numericFields); Set<Node> findNodes(String queryString); }
DependencyGraphIndex { public Set<Node> findNodes(String queryString) { try (DirectoryReader directoryReader = DirectoryReader.open(directory)) { IndexSearcher indexSearcher = new IndexSearcher(directoryReader); Query query = parseQuery(queryString); ScoreDoc[] hits = indexSearcher.search(query, MAX_RESULTS, Sort.INDEXORDER).scoreDocs; Set<Node> result = new HashSet<>(); for (ScoreDoc hit : hits) { Document hitDoc = indexSearcher.doc(hit.doc); String name = hitDoc.get("name"); result.add(graph.getNode(name)); } return result; } catch (IOException e) { throw new IllegalArgumentException("Finding nodes failed for query: " + queryString, e); } } DependencyGraphIndex(DependencyGraph graph, String... numericFields); Set<Node> findNodes(String queryString);  }