org.neo4j.graphdb.index.IndexHits Java Examples
The following examples show how to use
org.neo4j.graphdb.index.IndexHits.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Traversals.java From EvilCoder with MIT License | 6 votes |
public static List<Node> getCallsTo(String source) { List<Node> retval = new LinkedList<Node>(); // JANNIK String my = source; my = my.replace("*", "\\*"); my = my.replace("(", "\\("); my = my.replace(")", "\\)"); my = my.replace("-", "\\-"); my = my.replace(" ", "\\ "); String query = String.format("%s:Callee AND %s:%s", NodeKeys.TYPE, NodeKeys.CODE, my); IndexHits<Node> hits = Neo4JDBInterface.queryIndex(query); for (Node n : hits) { List<Node> parents = getParentsConnectedBy(n, "IS_AST_PARENT"); retval.add(parents.get(0)); } return retval; }
Example #2
Source File: Traversals.java From EvilCoder with MIT License | 6 votes |
public static List<Node> getCallsToForFunction(String source, long functionId) { List<Node> retval = new LinkedList<Node>(); // JANNIK String my = source; my = my.replace("*", "\\*"); my = my.replace("(", "\\("); my = my.replace(")", "\\)"); my = my.replace("-", "\\-"); my = my.replace(" ", "\\ "); String query = String.format("%s:Callee AND %s:%s AND %s:%s", NodeKeys.TYPE, NodeKeys.FUNCTION_ID, functionId, NodeKeys.CODE, my); IndexHits<Node> hits = Neo4JDBInterface.queryIndex(query); for (Node n : hits) { List<Node> parents = getParentsConnectedBy(n, "IS_AST_PARENT"); retval.add(parents.get(0)); } return retval; }
Example #3
Source File: Neo4j.java From SPADE with GNU General Public License v3.0 | 6 votes |
public Graph getEdges(int childVertexId, int parentVertexId) { Graph resultGraph = new Graph(); try( Transaction tx = graphDb.beginTx() ) { IndexHits<Relationship> queryHits = edgeIndex.query("type:*", graphDb.getNodeById(childVertexId), graphDb.getNodeById(parentVertexId)); for (Relationship currentRelationship : queryHits) { resultGraph.putVertex(convertNodeToVertex(currentRelationship.getStartNode())); resultGraph.putVertex(convertNodeToVertex(currentRelationship.getEndNode())); resultGraph.putEdge(convertRelationshipToEdge(currentRelationship)); } queryHits.close(); tx.success(); } return resultGraph; }
Example #4
Source File: VocabularyNeo4jImpl.java From SciGraph with Apache License 2.0 | 6 votes |
List<Concept> limitHits(IndexHits<Node> hits, Query query) { try (Transaction tx = graph.beginTx()) { Iterable<Concept> concepts = Iterables.transform(hits, transformer); if (!query.isIncludeDeprecated()) { concepts = filter(concepts, new Predicate<Concept>() { @Override public boolean apply(Concept concept) { return !concept.isDeprecated(); } }); } Iterable<Concept> limitedHits = limit(concepts, query.getLimit()); List<Concept> ret = newArrayList(limitedHits); tx.success(); return ret; } }
Example #5
Source File: ReverseDependencyMojo.java From maven-dependency-mapper with GNU Lesser General Public License v3.0 | 5 votes |
private void listDependants(){ final RestIndex<RestNode> index = restAPI.getIndex("artifact"); final IndexHits<RestNode> nodes = index.query(GROUP_ID_AND_ARTIFACT_ID, ArtifactHelper.getGroupIdAndArtifactId(project.getArtifact())); for (RestNode node : nodes) { listNodeDependants(node); } }
Example #6
Source File: GraphBatchImplIT.java From SciGraph with Apache License 2.0 | 5 votes |
@Test public void testMultiplePropertyNameIndex() { graph.addNodeProperty(foo, "prop1", "foo"); graph.addNodeProperty(foo, "prop2", "bar"); getGraphDB(); IndexHits<Node> hits = nodeIndex.query("prop1:foo"); assertThat(hits.size(), is(1)); hits = nodeIndex.query("prop2:bar"); assertThat(hits.size(), is(1)); }
Example #7
Source File: GraphBatchImplIT.java From SciGraph with Apache License 2.0 | 5 votes |
@Test public void testMultiplePropertyValueIndex() { graph.addNodeProperty(foo, "prop1", "foo"); graph.addNodeProperty(foo, "prop1", "bar"); getGraphDB(); IndexHits<Node> hits = nodeIndex.query("prop1:foo"); assertThat(hits.size(), is(1)); hits = nodeIndex.query("prop1:bar"); assertThat(hits.size(), is(1)); }
Example #8
Source File: GraphBatchImplIT.java From SciGraph with Apache License 2.0 | 5 votes |
@Test public void testReplacePropertyIndex() { graph.setNodeProperty(foo, "prop1", "foo"); graph.setNodeProperty(foo, "prop1", "bar"); getGraphDB(); IndexHits<Node> hits = nodeIndex.query("prop1:foo"); assertThat(hits.size(), is(0)); hits = nodeIndex.query("prop1:bar"); assertThat(hits.size(), is(1)); }
Example #9
Source File: GraphBatchImplIT.java From SciGraph with Apache License 2.0 | 5 votes |
@Test public void testExactPropertyIndex() { graph.addNodeProperty(foo, "prop1", "foo"); getGraphDB(); IndexHits<Node> hits = nodeIndex.query("prop1" + LuceneUtils.EXACT_SUFFIX + ":foo"); assertThat(hits.getSingle().getId(), is(foo)); }
Example #10
Source File: GraphBatchImplIT.java From SciGraph with Apache License 2.0 | 5 votes |
@Test public void testPropertyIndex() { graph.addNodeProperty(foo, "prop1", "foo"); getGraphDB(); IndexHits<Node> hits = nodeIndex.query("prop1:foo"); assertThat(hits.getSingle().getId(), is(foo)); }
Example #11
Source File: GraphBatchImplIT.java From SciGraph with Apache License 2.0 | 5 votes |
@Test public void testMultiplePropertySetting() { graph.addNodeProperty(foo, "prop1", "bar"); graph.addNodeProperty(foo, "prop1", "baz"); getGraphDB(); IndexHits<Node> hits = nodeIndex.query("prop1:bar"); assertThat((String[])hits.getSingle().getProperty("prop1"), is(arrayContaining("bar", "baz"))); }
Example #12
Source File: GraphBatchImplIT.java From SciGraph with Apache License 2.0 | 5 votes |
@Test public void testPropertySetting() { graph.addNodeProperty(foo, "prop1", "foo"); getGraphDB(); IndexHits<Node> hits = nodeIndex.query("prop1:foo"); assertThat((String)hits.getSingle().getProperty("prop1"), is("foo")); }
Example #13
Source File: GraphBatchImplIT.java From SciGraph with Apache License 2.0 | 5 votes |
@Test public void testNodeCreation() { GraphDatabaseService graphDb = getGraphDB(); assertThat(size(graphDb.getAllNodes()), is(1)); //IndexHits<Node> hits = nodeIndex.query(CommonProperties.IRI + ":http\\://example.org/foo"); IndexHits<Node> hits = nodeIndex.query(CommonProperties.IRI + ":http\\:\\/\\/example.org\\/foo"); assertThat(hits.getSingle().getId(), is(foo)); }
Example #14
Source File: FulltextIndex.java From ongdb-lab-apoc with Apache License 2.0 | 5 votes |
/** * @param * @return * @Description: TODO(全文检索节点结果输出) */ private Stream<ChineseHit> toWeightedNodeResult(IndexHits<Node> hits) { List<ChineseHit> results = new ArrayList<>(); while (hits.hasNext()) { Node node = hits.next(); results.add(new ChineseHit(node, hits.currentScore())); } return results.stream(); }
Example #15
Source File: VocabularyNeo4jImpl.java From SciGraph with Apache License 2.0 | 5 votes |
@Override public List<Concept> searchConcepts(Query query) { QueryParser parser = getQueryParser(); // BooleanQuery finalQuery = new BooleanQuery(); Builder finalQueryBuilder = new BooleanQuery.Builder(); try { if (query.isIncludeSynonyms() || query.isIncludeAbbreviations() || query.isIncludeAcronyms()) { // BooleanQuery subQuery = new BooleanQuery(); Builder subQueryBuilder = new BooleanQuery.Builder(); subQueryBuilder.add(LuceneUtils.getBoostedQuery(parser, query.getInput(), 10.0f), Occur.SHOULD); String escapedQuery = QueryParser.escape(query.getInput()); if (query.isIncludeSynonyms()) { subQueryBuilder.add(parser.parse(Concept.SYNONYM + ":" + escapedQuery), Occur.SHOULD); } if (query.isIncludeAbbreviations()) { subQueryBuilder.add(parser.parse(Concept.ABREVIATION + ":" + escapedQuery), Occur.SHOULD); } if (query.isIncludeAcronyms()) { subQueryBuilder.add(parser.parse(Concept.ACRONYM + ":" + escapedQuery), Occur.SHOULD); } finalQueryBuilder.add(subQueryBuilder.build(), Occur.MUST); } else { finalQueryBuilder.add(parser.parse(query.getInput()), Occur.MUST); } } catch (ParseException e) { logger.log(Level.WARNING, "Failed to parse query", e); } addCommonConstraints(finalQueryBuilder, query); IndexHits<Node> hits = null; BooleanQuery finalQuery = finalQueryBuilder.build(); try (Transaction tx = graph.beginTx()) { hits = graph.index().getNodeAutoIndexer().getAutoIndex().query(finalQuery); tx.success(); return limitHits(hits, query); } }
Example #16
Source File: Neo4jIndexHandler.java From timbuctoo with GNU General Public License v3.0 | 5 votes |
private GraphTraversal<Vertex, Vertex> traversalFromIndex(Collection collection, QuickSearch quickSearch) { Index<Node> index = getQuickSearchIndex(collection); try { IndexHits<Node> hits = index.query(QUICK_SEARCH_PROP_NAME, createQuery(quickSearch)); List<Long> ids = StreamIterator.stream(hits.iterator()).map(h -> h.getId()).collect(toList()); return ids.isEmpty() ? EmptyGraphTraversal.instance() : traversal().V(ids); } catch (Exception e) { LOG.error("Unexpected exception during search", e); return EmptyGraphTraversal.instance(); } }
Example #17
Source File: Neo4j.java From SPADE with GNU General Public License v3.0 | 5 votes |
public Graph getVertices(String expression) { try ( Transaction tx = graphDb.beginTx() ) { Graph resultGraph = new Graph(); IndexHits<Node> queryHits = vertexIndex.query(expression); for (Node foundNode : queryHits) { resultGraph.putVertex(convertNodeToVertex(foundNode)); } queryHits.close(); tx.success(); return resultGraph; } }
Example #18
Source File: Traversals.java From EvilCoder with MIT License | 5 votes |
public static IndexHits<Node> getStatementsForFunction(Node funcNode) { String query = String.format("%s:True AND %s:%d", NodeKeys.IS_CFG_NODE, NodeKeys.FUNCTION_ID, funcNode.getId()); return Neo4JDBInterface.queryIndex(query); }
Example #19
Source File: Neo4jIndexHandler.java From timbuctoo with GNU General Public License v3.0 | 5 votes |
@Override public Optional<Edge> findEdgeById(UUID edgeId) { RelationshipIndex edgeIdIndex = getEdgeIdIndex(); IndexHits<Relationship> hits = edgeIdIndex.query(TIM_ID, edgeId.toString()); return hits.hasNext() ? traversal().E(hits.next().getId()).tryNext() : Optional.empty(); }
Example #20
Source File: VocabularyNeo4jImpl.java From SciGraph with Apache License 2.0 | 4 votes |
@Override public List<Concept> getConceptsFromTerm(Query query) { QueryParser parser = getQueryParser(); // String exactQuery = String.format("\"\\^ %s $\"", query.getInput()); String exactQuery = String.format("\"\\^ %s $\"", query.getInput()); Builder finalQueryBuilder = new BooleanQuery.Builder(); try { if (query.isIncludeSynonyms() || query.isIncludeAbbreviations() || query.isIncludeAcronyms()) { Builder subQueryBuilder = new BooleanQuery.Builder(); // subQuery.add(LuceneUtils.getBoostedQuery(parser, exactQuery, 10.0f), Occur.SHOULD); subQueryBuilder.add(LuceneUtils.getBoostedQuery(parser, exactQuery, 10.0f), Occur.SHOULD); if (query.isIncludeSynonyms()) { // subQuery.add(parser.parse(Concept.SYNONYM + ":" + exactQuery), Occur.SHOULD); subQueryBuilder.add(parser.parse(Concept.SYNONYM + ":" + exactQuery), Occur.SHOULD); } if (query.isIncludeAbbreviations()) { // subQuery.add(parser.parse(Concept.ABREVIATION + ":" + exactQuery), Occur.SHOULD); subQueryBuilder.add(parser.parse(Concept.ABREVIATION + ":" + exactQuery), Occur.SHOULD); } if (query.isIncludeAcronyms()) { // subQuery.add(parser.parse(Concept.ACRONYM + ":" + exactQuery), Occur.SHOULD); subQueryBuilder.add(parser.parse(Concept.ACRONYM + ":" + exactQuery), Occur.SHOULD); } // finalQuery.add(subQuery, Occur.MUST); finalQueryBuilder.add(subQueryBuilder.build(), Occur.MUST); } else { // finalQuery.add(parser.parse(exactQuery), Occur.MUST); finalQueryBuilder.add(parser.parse(exactQuery), Occur.MUST); } } catch (ParseException e) { logger.log(Level.WARNING, "Failed to parse query", e); } addCommonConstraints(finalQueryBuilder, query); BooleanQuery finalQuery = finalQueryBuilder.build(); logger.finest(finalQuery.toString()); try (Transaction tx = graph.beginTx()) { IndexHits<Node> hits = graph.index().getNodeAutoIndexer().getAutoIndex().query(finalQuery); tx.success(); return limitHits(hits, query); } }
Example #21
Source File: Neo4jIndexHandler.java From timbuctoo with GNU General Public License v3.0 | 4 votes |
@Override public Optional<Vertex> findById(UUID timId) { IndexHits<Node> hits = getIdIndex().query(TIM_ID, timId.toString()); return hits.hasNext() ? traversal().V(hits.next().getId()).tryNext() : Optional.empty(); }
Example #22
Source File: VocabularyNeo4jImpl.java From SciGraph with Apache License 2.0 | 4 votes |
@Override public List<Concept> getConceptsFromPrefix(Query query) { QueryParser parser = getQueryParser(); // BooleanQuery finalQuery = new BooleanQuery(); Builder finalQueryBuilder = new BooleanQuery.Builder(); try { // BooleanQuery subQuery = new BooleanQuery(); Builder subQueryBuilder = new BooleanQuery.Builder(); subQueryBuilder.add(parser.parse(formatQuery("%s%s:%s*", NodeProperties.LABEL, LuceneUtils.EXACT_SUFFIX, query.getInput())), Occur.SHOULD); Optional<String> fullUri = curieUtil.getIri(query.getInput()); if (fullUri.isPresent()) { subQueryBuilder.add( parser.parse(formatQuery("%s:%s*", NodeProperties.IRI, (fullUri.get()))), Occur.SHOULD); } if (query.isIncludeSynonyms()) { subQueryBuilder.add( parser.parse(formatQuery("%s%s:%s*", Concept.SYNONYM, LuceneUtils.EXACT_SUFFIX, query.getInput())), Occur.SHOULD); } if (query.isIncludeAbbreviations()) { subQueryBuilder.add(parser.parse(formatQuery("%s%s:%s*", Concept.ABREVIATION, LuceneUtils.EXACT_SUFFIX, query.getInput())), Occur.SHOULD); } if (query.isIncludeAcronyms()) { subQueryBuilder.add( parser.parse(formatQuery("%s%s:%s*", Concept.ACRONYM, LuceneUtils.EXACT_SUFFIX, query.getInput())), Occur.SHOULD); } finalQueryBuilder.add(subQueryBuilder.build(), Occur.MUST); } catch (ParseException e) { logger.log(Level.WARNING, "Failed to parse query", e); } addCommonConstraints(finalQueryBuilder, query); BooleanQuery finalQuery = finalQueryBuilder.build(); IndexHits<Node> hits = null; try (Transaction tx = graph.beginTx()) { hits = graph.index().getNodeAutoIndexer().getAutoIndex().query(finalQuery); tx.success(); return limitHits(hits, query); } }
Example #23
Source File: Neo4j.java From SPADE with GNU General Public License v3.0 | 4 votes |
public Graph getEdges(String childExpression, String parentExpression, String edgeExpression) { Graph resultGraph = new Graph(); Set<AbstractVertex> childSet = null; Set<AbstractVertex> parentSet = null; if (childExpression != null) { if (childExpression.trim().equalsIgnoreCase("null")) { childExpression = null; } else { childSet = getVertices(childExpression).vertexSet(); } } if (parentExpression != null) { if (parentExpression.trim().equalsIgnoreCase("null")) { parentExpression = null; } else { parentSet = getVertices(parentExpression).vertexSet(); } } try( Transaction tx = graphDb.beginTx() ) { IndexHits<Relationship> queryHits = edgeIndex.query(edgeExpression); for (Relationship foundRelationship : queryHits) { AbstractVertex childVertex = convertNodeToVertex(foundRelationship.getStartNode()); AbstractVertex parentVertex = convertNodeToVertex(foundRelationship.getEndNode()); AbstractEdge tempEdge = convertRelationshipToEdge(foundRelationship); if ((childExpression != null) && (parentExpression != null)) { if (childSet.contains(tempEdge.getChildVertex()) && parentSet.contains(tempEdge.getParentVertex())) { resultGraph.putVertex(childVertex); resultGraph.putVertex(parentVertex); resultGraph.putEdge(tempEdge); } } else if ((childExpression != null) && (parentExpression == null)) { if (childSet.contains(tempEdge.getChildVertex())) { resultGraph.putVertex(childVertex); resultGraph.putVertex(parentVertex); resultGraph.putEdge(tempEdge); } } else if ((childExpression == null) && (parentExpression != null)) { if (parentSet.contains(tempEdge.getParentVertex())) { resultGraph.putVertex(childVertex); resultGraph.putVertex(parentVertex); resultGraph.putEdge(tempEdge); } } else if ((childExpression == null) && (parentExpression == null)) { resultGraph.putVertex(childVertex); resultGraph.putVertex(parentVertex); resultGraph.putEdge(tempEdge); } } queryHits.close(); tx.success(); } return resultGraph; }
Example #24
Source File: Traversals.java From EvilCoder with MIT License | 4 votes |
public static IndexHits<Node> getFunctionsByName(String functionName) { return Neo4JDBInterface.queryIndex(NodeKeys.NAME + ":" + functionName); }
Example #25
Source File: Neo4JDBInterface.java From EvilCoder with MIT License | 4 votes |
public static IndexHits<Node> queryIndex(String query) { return nodeIndex.query(query); }