52 | ////
53 |
54 | === Setup: Creating Friends, Restaurants in Cities and their Cusines
55 |
56 | //setup
57 | [source,cypher]
58 | ----
59 | CREATE (philip:Person {name:"Philip"})-[:IS_FRIEND_OF]->(emil:Person {name:"Emil"}),
60 | (philip)-[:IS_FRIEND_OF]->(michael:Person {name:"Michael"}),
61 | (philip)-[:IS_FRIEND_OF]->(andreas:Person {name:"Andreas"})
62 | CREATE (sushi:Cuisine {name:"Sushi"}), (nyc:City {name:"New York"}),
63 | (iSushi:Restaurant {name:"iSushi"})-[:SERVES]->(sushi),(iSushi)-[:LOCATED_IN]->(nyc),
64 | (michael)-[:LIKES]->(iSushi),
65 | (andreas)-[:LIKES]->(iSushi),
66 | (zam:Restaurant {name:"Zushi Zam"})-[:SERVES]->(sushi),(zam)-[:LOCATED_IN]->(nyc),
67 | (andreas)-[:LIKES]->(zam)
68 | ----
69 |
70 | //graph
71 |
72 | === Philips Friends
73 |
74 | [source,cypher]
75 | ----
76 | MATCH (philip:Person {name:"Philip"})-[:IS_FRIEND_OF]-(person)
77 | RETURn person.name
78 | ----
79 |
80 | //table
81 |
82 | === Restaurants in NYC and their cusines
83 |
84 | [source,cypher]
85 | ----
86 | MATCH (nyc:City {name:"New York"})<-[:LOCATED_IN]-(restaurant)-[:SERVES]->(cusine)
87 | RETURN nyc, restaurant, cusine
88 | ----
89 |
90 | //table
91 |
92 | //graph_result
93 |
94 | === Graph Search Recommendation
95 |
96 | image::https://guides.neo4j.com/sushi_restaurants_nyc.png[height=300,float=right]
97 |
98 | We want to answer the following question
99 |
100 | ""
101 | Find Sushi Restaurants in New York that my friends like.
102 | ""
103 |
104 | To satisfy this question, we have to know who's asking: _Philip_ and he's asking for 4 connected facts
105 |
106 | * _People_ that are friends of _Philip_
107 | * _Restaurants_ located in _New York_
108 | * _Restaurants_ that server _Sushi_
109 | * _Restaurants_ that his _Friends_ like
110 |
111 | [source,cypher]
112 | ----
113 | MATCH (philip:Person {name:"Philip"}),
114 | (philip)-[:IS_FRIEND_OF]-(friend),
115 | (restaurant:Restaurant)-[:LOCATED_IN]->(:City {name:"New York"}),
116 | (restaurant)-[:SERVES]->(:Cuisine {name:"Sushi"}),
117 | (friend)-[:LIKES]->(restaurant)
118 | RETURN restaurant.name, collect(friend.name) AS likers, count(*) AS occurence
119 | ORDER BY occurence DESC
120 | ----
121 |
122 | //table
--------------------------------------------------------------------------------
/adoc/template-table.adoc:
--------------------------------------------------------------------------------
1 | [cols="7", opts="headers"]
2 | |===
3 |
4 | | Label
5 | | Property
6 | | Value
7 | | Relationship
8 | | Label
9 | | Property
10 | | Value
11 |
12 | | pass:a[]
13 | | pass:a[]
14 | | pass:a[]
15 |
16 | | pass:a[]
17 |
18 | | pass:a[]
19 | | pass:a[]
20 | | pass:a[]
21 |
22 | |===
23 |
--------------------------------------------------------------------------------
/docs/adoc-guides.adoc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/neo4j-contrib/neo4j-guides/7887c8ef95010f138c9f86577626d27e7ec197cb/docs/adoc-guides.adoc
--------------------------------------------------------------------------------
/docs/html-guides.adoc:
--------------------------------------------------------------------------------
1 | = Creating remote browser guides in HTML
2 | == Setting up a remote server
3 | The remote server serving these guides must be open to handle requests from all origins. This is done by setting it's `Access-Control-Allow-Origin` header to allow `*`. Read more here: http://enable-cors.org/server.html
4 |
5 | == Configure Neo4j
6 | Enterprise edition of Neo4j can have configurated whitelist of allowed hostnames to fetch guides from. Community edition have a static whitelist.
7 | The whitelist is in _neo4j-server.properties_. Set to `*` to allow from all hosts.
8 |
9 | == Create a guide
10 | Howto create a guide.
11 |
12 | === Basic HTML structure
13 | A browser guide is a partial HTML document that sould be encapsulated in `` tags.
14 |
15 | A guide usually have multiple slides/pages by using a carousel:
16 |
17 | [source,html]
18 | ----
19 |
20 | Slide 1
21 | Slide 2
22 |
23 | ----
24 |
25 | The Bootstrap CSS classes can be used, see http://getbootstrap.com/css/ for info on what's available.
26 |
27 | A slide is usually split into two columns with title and lead to the left and content to the right.
28 | To get this structure, use this code:
29 |
30 | [source,html]
31 | ----
32 |
33 |
Title
34 |
Informative text
35 |
36 |
37 | content...
38 |
39 | ----
40 |
41 | All HTML is allowed so make sure the guides structure is valid and complete so other parts of the browser don't break.
42 | All `
3 |
4 |
5 |
6 |
REMOTE Cypher
7 |
Neo4j's graph query language
8 |
9 |
10 |
Neo4j's Cypher language is purpose built for working with graph data.
11 |
12 |
uses patterns to describe graph data
13 |
familiar SQL-like clauses
14 |
declarative, describing what to find, not how to find it
15 |
declarative, describing what to find, not how to find it 2
16 |
declarative, describing what to find, not how to find it 2
17 |
18 |
19 |
20 |
21 |
22 |
CREATE
23 |
Create a node
24 |
25 |
26 |
Let's use Cypher to generate a small social graph.
For instance, a pattern can be used to find Emil's friends:
84 |
85 |
MATCH (ee:Person)-[:KNOWS]-(friends)
86 | WHERE ee.name = "Emil" RETURN ee, friends
87 |
88 |
89 |
MATCHclause to describe the pattern from known Nodes to found Nodes
90 |
(ee)starts the pattern with a Person (qualified by WHERE)
91 |
-[:KNOWS]-matches "KNOWS" relationships (in either direction)
92 |
(friends)will be bound to Emil's friends
93 |
94 |
95 |
96 |
97 |
98 |
Recommend
99 |
Using patterns
100 |
101 |
102 |
103 | Pattern matching can be used to make recommendations. Johan is learning to surf, so he may want to find
104 | a new friend who already does:
105 |
106 |
107 |
MATCH (js:Person)-[:KNOWS]-()-[:KNOWS]-(surfer)
108 | WHERE js.name = "Johan" AND surfer.hobby = "surfing"
109 | RETURN DISTINCT surfer
110 |
111 |
112 |
()empty parenthesis to ignore these nodes
113 |
DISTINCTbecause more than one path will match the pattern
114 |
surferwill contain Allison, a friend of a friend who surfs
115 |
116 |
117 |
118 |
119 |
120 |
Next steps
121 |
122 | Start your application using Cypher to create and query graph data. Use the REST API
123 | to monitor the database. In special cases, consider a plugin.
124 |
Start by typing :play intro into the command-line and pressing Enter.
59 | Please follow the guide to learn about our user interface.
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
Feedback & Questions
70 |
71 |
72 |
73 |
If you have feedback or questions on how to use the Neo4j Browser, there is a small messaging system in the configuration (cog) drawer.
74 | You can provide your name and send us a message.
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
Useful Commands and Keyboard Shortcuts
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
Shortcut
95 |
Purpose
96 |
97 |
98 |
99 |
100 |
:help
101 |
Help System
102 |
103 |
104 |
:help commands
105 |
Useful Commands
106 |
107 |
108 |
:clear
109 |
Clear Frames
110 |
111 |
112 |
:style [reset]
113 |
Styling Popup & Reset
114 |
115 |
116 |
:help keys
117 |
Keyboard Help
118 |
119 |
120 |
Ctrl+Enter or Cmd+Enter
121 |
Execute Statement
122 |
123 |
124 |
Ctrl+Up or Cmd+Up
125 |
Previous Statement
126 |
127 |
128 |
Shift+Enter
129 |
Enter Multiline Mode
130 |
131 |
132 |
/
133 |
Move Focus to Editor
134 |
135 |
136 |
ESC
137 |
Toggle Editor to Full Screen
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 |
148 |
149 |
Built in Guides
150 |
151 |
152 |
153 |
If you want to learn more first, click on any of the helpful links shown after startup: these are quick guides that introduce the different concepts.
154 | You find more helpful links in the left sidebar in the "Information" tab, with the (i).
155 |
156 |
157 |
158 |
159 |
Intro - a guided tour of Neo4j browser :play intro
160 |
161 |
162 |
Concepts - GraphDB 101 :play concepts
163 |
164 |
165 |
Cypher - query language :play cypher
166 |
167 |
168 |
The Movie Graph - a mini graph model with use-cases :play movie graph
169 |
170 |
171 |
The Northwind Database - the classic demo database with import instructions & use-case queries :play northwind graph
172 |
173 |
174 |
Custom Guides - starting with Neo4j 2.3 you can use :play <url> to play a custom guide, e.g. :play http://guides.neo4j.com/intro/create.html from the fundamentals training.
175 |
176 |
177 |
178 |
179 |
Import our sample movie graph by entering :play movie graph.
180 |
181 |
182 |
On the second slide click the large Cypher CREATE ... statement, then hit the Run button.
183 |
184 |
185 |
After a few seconds the data is imported, and you’ll see a subset of the movie data rendered as a graph.
186 |
187 |
188 |
189 |
190 |
191 |
192 |
193 |
194 |
195 |
Styling Neo4j Browser Visualization
196 |
197 |
198 |
199 |
You can pan the visual view around and drag nodes to rearrange them.
200 |
201 |
202 |
The nodes already have a sensible captions, it auto-selects a property from the property list to be rendered as caption.
203 |
204 |
205 |
If you click on any node or relationship you see the properties of that element below the visualization, larger property sets might be folded in, there is a little triangle on the right to fold them out.
206 |
207 |
208 |
E.g. you click on one of the Movies then you can see it’s properties below the graph.
209 | Same for actors or the ACTED_IN relationships.
210 |
211 |
212 |
If you click on any label or relationship above the graph visualization, you can then chose its styling in the area below the graph.
213 |
214 |
215 |
Colors, sizes and captions are selectable from there.
216 |
217 |
218 |
For instance click on the (Movies) label above the graph and change the color, size and captions of nodes labeled with Movie.
219 |
220 |
221 |
222 |
223 |
224 |
225 |
226 |
227 |
228 |
229 |
230 |
231 |
232 |
233 |
234 |
235 |
236 |
237 |
238 |
Running Queries
239 |
240 |
241 |
242 |
When you continue with the guide, you will see more queries.
243 | You can get them into the editor by clicking on them.
244 | To execute, hit the triangular play button.
245 |
246 |
247 |
Query results are rendered either as visual graph or tabular result.
248 | You can switch between those with the icons on the left side of the result frame.
249 |
250 |
251 |
Remove all accumulated output frames with :clear, the cross removes a single frame and aborts a (long-)running statement.
252 |
253 |
254 |
You can click the query above the graph visualisation to pull it back into the editor.
255 |
256 |
257 |
Use the keyboard shortcuts listed above to work efficiently with the editor area.
258 |
259 |
260 |
Navigate input history with Ctrl+Up and Ctrl+Down, access all of it via :history. The history will be persisted across browser restarts.
261 |
262 |
263 |
You can switch between tabular, visual mode, query plan and x-ray mode for results with the icons on the left of each panel,
264 |
265 |
266 |
267 |
268 |
269 |
Note
270 |
271 |
272 | Don’t worry if you don’t see any output, you might just be in visual mode but returned tabular/scalar data, just switch the mode to tabular
273 |
274 |
275 |
276 |
277 |
278 |
Query time is reported in the tabular view, don’t rely on that exact timing though it includes the latency and (de-)serialization costs, not just the actual query execution time.
279 |
280 |
281 |
You can download the results as CSV from the tabular output panel (top right download icon), and as JSON (download icon above the panel).
282 | The graph visualization can be exported as PNG and SVG.
283 |
284 |
285 |
286 |
287 |
288 |
289 |
290 |
291 |
292 |
Meta Graph
293 |
294 |
295 |
296 |
In the left side drawer on the three bubbles section (that resemble the Neo4j logo) you find the currently used node-labels and relationship types.
297 | Clicking on any of those runs a quick query to show you a sample of the graph using those.
298 |
299 |
300 |
301 |
302 |
303 |
304 |
305 |
306 |
307 |
Queries and Favorites
308 |
309 |
310 |
311 |
If you start with an empty frame, display some nodes and relationships, use the Favorites (Star) drawer on the left, click on the Get Some Data entry, and run the query.
312 | This executes the statement MATCH (n) RETURN n limit 100 which fetches some nodes.
313 |
314 |
315 |
The browser helpfully also fetches and displays relationships between those nodes, even if they were not part of your query result.
316 | You can disable the latter behavior with the "Auto-Complete" switch in the bottom left corner.
317 | Then only relationships returned by the actual query will be shown.
318 |
319 |
320 |
You can save your own queries as favorites by "starring" them.
321 | Use a comment // comment above your query for a title.
322 | Use folders to organize the favorites you can rearrange them by dragging and delete if they are no longer useful.
323 |
324 |
325 |
326 |
327 |
328 |
Note
329 |
330 |
331 | Favorites are stored in your local browser storage, so they are only available per Browser and URL.
332 |
333 |
334 |
335 |
336 |
337 |
338 |
339 |
340 |
For more advanced styling you can bring up the style-viewer with :style, download the graph-style-sheet (GRASS), edit it offline and drag it back onto the drag-area of the viewer.
341 |
342 |
343 |
344 |
345 |
346 |
Note
347 |
348 |
349 | You can reset to the default styles with :style reset.
350 | Alternatively by clicking the "fire extinguisher" icon in the popup from :style.
351 |
352 |
353 |
354 |
355 |
356 |
Within the GRASS file you can change colors, fonts, sizes, outlines and titles per node-label and relationship-type.
357 | It is also possible to combine multiple properties into a caption with caption: '{name}, born in {born}';
358 |
359 |
360 |
361 |
362 |
363 |
364 |
365 |
366 |
367 |
368 |
369 |
370 |
371 |
372 |
Configuration
373 |
374 |
375 |
376 |
377 |
378 |
since Neo4j 2.3 there is a config drawer on the left (with the cog), no need for the :config command anymore
379 |
380 |
381 |
you can retrieve the current configuration with :config
382 |
383 |
384 |
the individual settings are configured with:
385 |
386 |
387 |
388 |
:config maxNeighbours:100 - maxiumum number of neighbours for a node
389 |
390 |
391 |
:config maxRows:100 - maximum number of rows for the tabular result
392 |
393 |
394 |
395 |
396 |
397 |
398 |
399 |
400 |
401 |
402 |
403 |
404 |
405 |
406 |
Executing REST requests
407 |
408 |
409 |
410 |
You can also execute REST requests with the Neo4j Browser, the command-syntax is
411 | :COMMAND /a/path {"some":"data"}.
412 | The available commands are :GET, :POST, :PUT and :DELETE.
413 |
414 |
415 |
A simple query would inspect the available endpoints of the database :GET /db/data/, the results are listed as formatted JSON.
416 | Then you can for instance retrieve all labels in the database with :GET /db/data/labels.
417 |
418 |
419 |
To execute a Cypher statement you post to the transaction Cypher endpoint like this:
<%
9 | if item.blocks? %>
10 | <%= item.content %><%
11 | end %>
12 |
<%
13 | end %>
14 |
15 |
16 |
--------------------------------------------------------------------------------
/templates/block_open.html.erb:
--------------------------------------------------------------------------------
1 | <%#encoding:UTF-8%><%
2 | if @style == 'abstract'
3 | if @parent == @document && @document.doctype == 'book'
4 | puts 'asciidoctor: WARNING: abstract block cannot be used in a document without a title when doctype is book. Excluding block content.'
5 | else
6 | %>
<%
14 | end
15 | elsif @style == 'partintro' && (@level != 0 || @parent.context != :section || @document.doctype != 'book')
16 | puts 'asciidoctor: ERROR: partintro block can only be used when doctype is book and it\'s a child of a book part. Excluding block content.'
17 | else
18 | %>