11.05.2016 Views

Apache Solr Reference Guide Covering Apache Solr 6.0

21SiXmO

21SiXmO

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

We can also use the traversalFilter to limit the graph traversal to only nodes with maximum value of 15 in<br />

the foo field. In this case that means D, E, and F are excluded – F has a value of foo=11, but it is unreachable<br />

because the traversal skipped D:<br />

http://localhost:8983/solr/my_graph/query?fl=id&q={!graph+from=in_edge+to=out_edge+t<br />

raversalFilter='foo:[*+TO+15]'}id:A<br />

...<br />

"response":{"numFound":3,"start":0,"docs":[<br />

{ "id":"A" },<br />

{ "id":"B" },<br />

{ "id":"C" } ]<br />

}<br />

The examples shown so far have all used a query for a single document ("id:A") as the root node for the graph<br />

traversal, but any query can be used to identify multiple documents to use as root nodes. The next example<br />

demonstrates using the maxDepth param to find all nodes that are at most one edge away from an root node<br />

with a value in the foo field less then or equal to 10:<br />

http://localhost:8983/solr/my_graph/query?fl=id&q={!graph+from=in_edge+to=out_edge+m<br />

axDepth=1}foo:[*+TO+10]<br />

...<br />

"response":{"numFound":6,"start":0,"docs":[<br />

{ "id":"A" },<br />

{ "id":"B" },<br />

{ "id":"C" },<br />

{ "id":"D" },<br />

{ "id":"G" },<br />

{ "id":"H" } ]<br />

}<br />

Simplified Models<br />

The Document & Field modelling used in the above examples enumerated all of the outgoing and income edges<br />

for each node explicitly, to help demonstrate exactly how the "from" and "to" params work, and to give you an<br />

idea of what is possible. With multiple sets of fields like these for identifying incoming and outgoing edges, it's<br />

possible to model many independent Directed Graphs that contain some or all of the documents in your<br />

collection.<br />

But in many cases it can also be possible to drastically simplify the model used.<br />

For Example: The same graph shown in the diagram above can be modelled by <strong>Solr</strong> Documents that represent<br />

each node and know only the ids of the nodes they link to, with out knowing anything about the incoming links:<br />

curl -H 'Content-Type: application/json'<br />

'http://localhost:8983/solr/alt_graph/update?commit=true' --data-binary '[<br />

{"id":"A","foo": 7, "out_edge":["B","C"] },<br />

{"id":"B","foo": 12, "out_edge":["E","D"] },<br />

{"id":"C","foo": 10, "out_edge":["A","D"] },<br />

{"id":"D","foo": 20, "out_edge":["A","F"] },<br />

{"id":"E","foo": 17, "out_edge":[] },<br />

{"id":"F","foo": 11, "out_edge":[] },<br />

{"id":"G","foo": 7, "out_edge":["H"] },<br />

{"id":"H","foo": 10, "out_edge":[] }<br />

]'<br />

<strong>Apache</strong> <strong>Solr</strong> <strong>Reference</strong> <strong>Guide</strong> <strong>6.0</strong><br />

286

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!