Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The below code will add a synonym to a rootword: (You'll probably want to check if your 'word' and 'synonym' is already in the db so you could just create a relationship)</p> <pre><code>public static void AddNodeToDb(IGraphClient graphClient, string index, RootWord word, RootWord synonym) { if (!graphClient.CheckIndexExists(index, IndexFor.Node)) { var configuration = new IndexConfiguration { Provider = IndexProvider.lucene, Type = IndexType.fulltext }; graphClient.CreateIndex(index, configuration, IndexFor.Node); } var wordReference = graphClient.Create(word, null, GetIndexEntries(word, index)); var synonymReference = graphClient.Create(synonym, null, GetIndexEntries(synonym, index)); graphClient.CreateRelationship(wordReference, new IsSynonym(synonymReference)); Console.WriteLine("Word: {0}, Synonym: {1}", wordReference.Id, synonymReference.Id); } </code></pre> <p>The 'GetIndexEntries' method gets the entries you'll want to put in the index for your object (RootWord), as you only have term, that's easy:</p> <pre><code>private static IEnumerable&lt;IndexEntry&gt; GetIndexEntries(RootWord rootWord, string indexName) { var indexKeyValues = new List&lt;KeyValuePair&lt;string, object&gt;&gt; { new KeyValuePair&lt;string, object&gt;("term", rootWord.Term) }; return new[] { new IndexEntry { Name = indexName, KeyValues = indexKeyValues.Where(v =&gt; v.Value != null) } }; } </code></pre> <p>So, say you've entered 'Ace', 'Great' You can query (using Cypher) as:</p> <pre><code>START n=node(0) MATCH n-[:IS_SYNONYM]-&gt;res RETURN res </code></pre> <p>(assuming node 0 is your root word you want!) which will return the 'Great' node. At the same time, because we also created a fulltext index, you can search for the rootword using the following code:</p> <pre><code>public static void QueryTerms(IGraphClient gc, string query) { var result = gc.QueryIndex&lt;RootWord&gt;("synonyms", IndexFor.Node, "term:" + query).ToList(); if (result.Any()) foreach (var node in result) Console.WriteLine("node: {0} -&gt; {1}", node.Reference.Id, node.Data.Term); else Console.WriteLine("No results..."); } </code></pre> <p>Once you have those nodes, you can traverse the 'IS_SYNONYM' relationships to get to the actual synonyms.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload