<commit_before>[[python-embedded-tutorial-invoiceapp]]
A sample app using traversals and indexes
=========================================

For detailed documentation on the concepts use here, see <<python-embedded-reference-indexes>> and <<python-embedded-reference-traversal>>.

This example shows you how to get started building something like a simple invoice tracking application with Neo4j.

We start out by importing Neo4j, and creating some meta data that we will use to organize our actual data with.

[snippet,python]
----
component=neo4j-python-embedded
source=examples.py
tag=invoiceapp-setup
classifier=test-sources
----

== Domain logic ==

Then we define some domain logic that we want our application to be able to perform. Our application has two domain objects, Customers and Invoices. Let's create methods to add new customers and invoices.
 
[snippet,python]
----
component=neo4j-python-embedded
source=examples.py
tag=invoiceapp-domainlogic-create
classifier=test-sources
----

In the customer case, we create a new node to represent the customer and connect it to the _customers node_. This helps us find customers later on, as well as determine if a given node is a customer.

We also index the name of the customer, to allow for quickly finding customers by name.

In the invoice case, we do the same, except no indexing. We also connect each new invoice to the customer it was sent to, using a relationship of type +SENT_TO+.

Next, we want to be able to retrieve customers and invoices that we have added. Because we are indexing customer names, finding them is quite simple.

[snippet,python]
----
component=neo4j-python-embedded
source=examples.py
tag=invoiceapp-domainlogic-get-by-idx
classifier=test-sources
----

Lets say we also like to do something like finding all invoices for a given customer that are above some given amount. This could be done by writing a traversal, like this:

[snippet,python]
----
component=neo4j-python-embedded
source=examples.py
tag=invoiceapp-domainlogic-get-by-traversal
classifier=test-sources
----

== Creating data and getting it back ==

Putting it all together, we can create customers and invoices, and use the search methods we wrote to find them.

[snippet,python]
----
component=neo4j-python-embedded
source=examples.py
tag=invoiceapp-create-and-search
classifier=test-sources
----

<commit_msg>Fix formatting.<commit_after>[[python-embedded-tutorial-invoiceapp]]
A sample app using traversals and indexes
=========================================

For detailed documentation on the concepts used here, see <<python-embedded-reference-indexes>> and <<python-embedded-reference-traversal>>.

This example shows you how to get started building something like a simple invoice tracking application with Neo4j.

We start out by importing Neo4j, and creating some meta data that we will use to organize our actual data with.

[snippet,python]
----
component=neo4j-python-embedded
source=examples.py
tag=invoiceapp-setup
classifier=test-sources
----

== Domain logic ==

Then we define some domain logic that we want our application to be able to perform. Our application has two domain objects, Customers and Invoices. Let's create methods to add new customers and invoices.
 
[snippet,python]
----
component=neo4j-python-embedded
source=examples.py
tag=invoiceapp-domainlogic-create
classifier=test-sources
----

In the customer case, we create a new node to represent the customer and connect it to the _customers node_. This helps us find customers later on, as well as determine if a given node is a customer.

We also index the name of the customer, to allow for quickly finding customers by name.

In the invoice case, we do the same, except no indexing. We also connect each new invoice to the customer it was sent to, using a relationship of type +SENT_TO+.

Next, we want to be able to retrieve customers and invoices that we have added. Because we are indexing customer names, finding them is quite simple.

[snippet,python]
----
component=neo4j-python-embedded
source=examples.py
tag=invoiceapp-domainlogic-get-by-idx
classifier=test-sources
----

Lets say we also like to do something like finding all invoices for a given customer that are above some given amount. This could be done by writing a traversal, like this:

[snippet,python]
----
component=neo4j-python-embedded
source=examples.py
tag=invoiceapp-domainlogic-get-by-traversal
classifier=test-sources
----

== Creating data and getting it back ==

Putting it all together, we can create customers and invoices, and use the search methods we wrote to find them.

[snippet,python]
----
component=neo4j-python-embedded
source=examples.py
tag=invoiceapp-create-and-search
classifier=test-sources
----


{'fraction_non_alphanumeric': 0.09094745726946613, 'fraction_numerical': 0.0029542097488921715, 'mean_word_length': 4.622775800711744, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '1785827', 'n_tokens_mistral': 1327, 'n_tokens_neox': 1244, 'n_words': 577}