Skip to content

Instantly share code, notes, and snippets.

@peterneubauer
Last active December 23, 2015 08:38
Show Gist options
  • Save peterneubauer/6608600 to your computer and use it in GitHub Desktop.
Save peterneubauer/6608600 to your computer and use it in GitHub Desktop.

A case of nested subcategories

In many multilingual systems, there are nested hierarchis of categories, connected to different products that need to be searched by customers with different language preferences. Here is a possible approach, inspired by the Wordnet Project.

The setup

CREATE (getr{name:'C1'})
CREATE (alc{name:'C2'})
CREATE ({caption:'beverages', lang:'EN'})<-[:CAPTION]-(getr)
CREATE (getr)-[:CAPTION]->({caption:'Getraenke', lang:'DE'})
CREATE ({caption:'alcoholic stuff', lang:'EN'})<-[:CAPTION]-(alc)
CREATE (alc)-[:CAPTION]->(alc_de{caption:'Alkoholika', lang:'DE'})
CREATE (getr)<-[:IS_A]-(alc)
CREATE ({name:"Wein"})-[:TAGGED]->(alc_de)

Find English things that are beverages

Now, let’s find the German captions of products that are attached to the category or one of its subcategories of the one that has an English caption beverages.

MATCH
  (bev_caption)<-[:CAPTION]-bev<-[:IS_A*0..]-(sub_cat)-[:CAPTION]->(caption),
  bev-[:CAPTION]->(cap2),(caption)<-[:TAGGED]-(product)
WHERE
  bev_caption.caption = 'beverages' AND
  caption.lang='DE' AND cap2.lang='DE'
RETURN bev_caption.caption AS search_term,cap2.caption AS search_term_DE,caption.caption AS found_cat, product.name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment