Hi Kamal
Thanks for taking the time to look at this and thanks for the link, really
interesting read. Am now rethinking the whole process now and going back to
the start of this Might keep this idea on a back thread, but for now, it
might not be necessary.
Dave
On Friday, 23 June 2017 06:26:35 UTC+1, Kamal Murthy wrote:
>
> Hi Dave,
> Here is my analysis:
>
> #1: //MATCH WHISKY WITH DISTILLERY, COUNTRY, REGION, KEYWORDS AND
> FLAVOUR_PROFILE
>
> MATCH (whisky:Whisky {id: {whiskyId}})
> OPTIONAL MATCH
> (whisky)<-[:PRODUCES]-(distillery:Distillery)-[:FLAVOUR]-(flavour:Flavour)
> OPTIONAL MATCH (whisky)-[:HAS_KEYWORD]->(keyword:Keyword)
> OPTIONAL MATCH (whisky)-[:FROM]-(region:Region)-[:IN]-(country:Country)
>
> Here you use WITH clause to chain together selected results.
>
> WITH whisky, distillery, flavour, keyword, region, country
>
>
> #2: //MATCH MATCH USER TASTING
>
> Here the relation [:TASTED] has a property, 'recommend' and am assuming
> you are storing the whiskies ids. if this is correct:
>
> OPTIONAL MATCH (me2:User {id:
> {userId}})-[s1:SIMILAR]-(:User)-[t1:TASTED]->(whisky)
> WHERE t1.recommend <> {whiskyId} // here itself we can filter out
> UNWIND (CASE WHEN t1.recommend IS NULL then [0] else t1.recommend end) AS
> tastingIds
>
> WITH whisky, distillery, flavour, keyword, region, country, tastingIds
>
> This will bring out all the recommended whisky ids.
>
> #2 // MATCH RECOMMENDED WHISKIES BASED ON FLAVOUR
> OPTIONAL MATCH
> (me2)-[s2:SIMILAR]-(:User)-[t2:TASTED]-(:Whisky)-[:PRODUCES]-(:Distillery)-[:FLAVOUR]-(flavour)
> UNWIND (CASE WHEN t2.recommend IS NULL then [0] else t2.recommend end) AS
> flavourUserIds
>
> I think flavourUserIds will be sme as tastingIds as t1.recommend =
> t2.recommend
>
> If you are trying to get the flavours corresponding to the recommended
> whisky ids, then I would do this:
>
> //MATCH RECOMMENDED FLAVOURS
> MATCH
> (whisky2:Whisky)-[:PRODUCES]-(:Distillery)-[:FLAVOUR]-(flavour2:Flavour)
> WHERE whisky2.id = tastingIds.id
>
> WITH whisky, distillery, flavour, keyword, region, country, tastingIds,
> flavour2
>
> (flavour corresponds to {whiskyId} and flavour2 corresponds to tastingIds)
>
> // RETURN RESULTS
> RETURN DISTINCT whisky, flavour as flavourProfile, distillery.name AS
> distillery, region.name AS region, country.name AS country,
>
> // RETURN RECOMMENDED WHISKIES IF USER IS LOGGED IN AND SIMILAR USERS HAVE
> TASTED THE WHISKY
> CASE WHEN tastingIds.id IS NULL THEN null else COLLECT(DISTINCT
> {name:tastingIds.name, id:ttastingIds.id, img:tastingIds.whisky_img}) END
> AS tastingRecommended,
>
> ----This I am not clear...........
> // RETURN RECOMMENDED WHISKIES IF USER IS LOGGED IN AND SIMILAR USERS HAVE
> TASTED WHISKY WITHIN FLAVOUR PROFILE MATCH
> CASE WHEN flavourRecommended.id IS NULL THEN null else COLLECT(DISTINCT
> {name:flavourRecommended.name, id:flavourRecommended.id,
> img:flavourRecommended.whisky_img}) END AS flavourRecommended
>
>
> I created a small graph and call apoc.meta.graph() gives:
>
>
> <https://lh3.googleusercontent.com/-ovr6Lcrb_cw/WUylvoVhG6I/AAAAAAAACPQ/yFXeRImmbU4ep_FOjgLEL2teBEd0kAp6ACLcBGAs/s1600/Screen%2BShot%2B06-22-17%2Bat%2B05.12%2BPM.PNG>
> MATCH
> (w:Whisky{name:'Aberlour'})-[p:PRODUCED_IN]-(r:Location)-[t:LOCATED_IN]-(c:Region)
> WITH w, r, c
> MATCH (w1:Whisky)-[:HAS_FLAVOURS]->(f:Flavour)
> WHERE w1.name = w.name
> WITH w, r, c, f
> MATCH (n1:User)-[:TASTED]->(q)
> WITH n1, w, r, c, f
> MATCH
> (s)-[:USER]->(n:User)-[:RECOMMEND]->(q:Whisky)-[:HAS_FLAVOURS]->(f2:Flavour)
> WHERE n.id = n1.id
> WITH w, r, c, f, q, f2
> RETURN w.name as SelWhisky, f.name as SelFlavour, r.name AS Location,
> c.name AS Region, COLLECT(distinct q.name) as RecWhisky, COLLECT(distinct
> f2.name) as RecFlavour;
>
> Result:
>
>
> <https://lh3.googleusercontent.com/-jkVrkxTZfKw/WUyl3Am7bOI/AAAAAAAACPU/uQAw7-dpZfgBBfcbMQorT37WgMDBrplTwCLcBGAs/s1600/Screen%2BShot%2B06-22-17%2Bat%2B10.17%2BPM.PNG>
> You can check my GraphGist titled: Multidimensional Approach To
> Recommender Systems
>
> url: https://neo4j.com/graphgist/800a57b2-bbd1-40d3-9dee-a00c4ef624e6
>
> Hope this will help you.
> Thanks,
> -Kamal
>
>
>
> On Wednesday, June 21, 2017 at 10:20:26 AM UTC-7, Dave Clissold wrote:
>>
>> Am experiencing really strange behavior with the return of records. When
>> I run this rather long query it splits the response into 2 records and
>> places null into one of the columns to begin, but then returns the data in
>> the 2nd record. I cannot see what could be causing this so
>>
>> // MATCH WHISKY WITH DISTILLERY, COUNTRY, REGION, KEYWORDS AND
>> FLAVOUR_PROFILE
>> MATCH (whisky:Whisky {id: {whiskyId}}) WITH whisky
>> OPTIONAL MATCH (whisky)<-[:PRODUCES]-(distillery:Distillery)-[:FLAVOUR]-(
>> flavour:Flavour)
>> OPTIONAL MATCH (whisky)-[:HAS_KEYWORD]->(keyword:Keyword)
>> OPTIONAL MATCH (whisky)-[:FROM]-(region:Region)-[:IN]-(country:Country)
>> // MATCH SHOPS THAT SELL THE WHISKY AND IF THEY SHOP TO USERS COUNTRY
>> OPTIONAL MATCH (whisky)<-[shopInfoA:SELLS]-(shopA:Retailer)
>> OPTIONAL MATCH (whisky)<-[shopInfoB:SELLS]-(shopB:Retailer)-[
>> shopShippingB:SHIPSTO]-(:Country)-[:FROM]-(me:User {id: {userId}})
>> OPTIONAL MATCH (whisky)<-[shopInfoA:SELLS]-(shopA:Retailer)
>> // MATCH USER TASTING
>> OPTIONAL MATCH (whisky)<-[myTasting:TASTED]-(me)
>> // MATCH RECOMMENDED WHISKIES BASED ON WHISKY ID
>> OPTIONAL MATCH (me2:User {id: {userId}})-[s1:SIMILAR]-(:User)-[t1:TASTED
>> ]->(whisky)
>> UNWIND (CASE WHEN t1.recommend IS NULL then [0] else t1.recommend end)
>> AS tastingIds
>> // MATCH RECOMMENDED WHISKIES FROM ABOVE QUERY AND RETURN WHISKIES
>> OPTIONAL MATCH (tastingRecommended:Whisky) WHERE tastingRecommended.id =
>> tastingIds AND tastingRecommended.id <> {whiskyId}
>> // MATCH RECOMMENDED WHISKIES BASED ON FLAVOUR
>> OPTIONAL MATCH (me2)-[s2:SIMILAR]-(:User)-[t2:TASTED]-(:Whisky)-[:
>> PRODUCES]-(:Distillery)-[:FLAVOUR]-(flavour)
>> UNWIND (CASE WHEN t2.recommend IS NULL then [0] else t2.recommend end)
>> AS flavourUserIds
>> // MATCH RECOMMENDED WHISKIES FROM ABOVE QUERY AND RETURN WHISKIES
>> OPTIONAL MATCH (flavourRecommended:Whisky) WHERE flavourRecommended.id =
>> flavourUserIds AND flavourRecommended.id <> {whiskyId}
>> // JOIN QUERIES WITH RETURNS
>> WITH whisky, flavour, tastingRecommended, flavourRecommended, distillery,
>> keyword, region, country, shopA, shopInfoA, me, shopShippingB, shopB,
>> shopInfoB, myTasting,
>> // RETURN RESULTS
>> RETURN DISTINCT whisky, flavour as flavourProfile, distillery.name AS
>> distillery, region.name AS region, country.name AS country,
>> // RETURN RECOMMENDED WHISKIES IF USER IS LOGGED IN AND SIMILAR USERS
>> HAVE TASTED THE WHISKY
>> CASE WHEN tastingRecommended.id IS NULL THEN null else COLLECT(DISTINCT {
>> name:tastingRecommended.name, id:tastingRecommended.id, img:
>> tastingRecommended.whisky_img}) END AS tastingRecommended,
>> // RETURN RECOMMENDED WHISKIES IF USER IS LOGGED IN AND SIMILAR USERS
>> HAVE TASTED WHISKY WITHIN FLAVOUR PROFILE MATCH
>> CASE WHEN flavourRecommended.id IS NULL THEN null else COLLECT(DISTINCT {
>> name:flavourRecommended.name, id:flavourRecommended.id, img:
>> flavourRecommended.whisky_img}) END AS flavourRecommended,
>>
>>
>> Here is the return as text so you can see what is going on. in the
>> interest of sanity, I have shortened the entries down,
>>
>>
>> ╒══════════════════════════════╤══════════════════════════════╤════════════╤══════════╤══════════╤══════════════════════════════╤══════════════════════════════╤
>> │"whisky" │"flavourProfile"
>> │"distillery"│"region" │"country" │"tastingRecommended"
>> │"flavourRecommended |
>>
>> ╞══════════════════════════════╪══════════════════════════════╪════════════╪══════════╪══════════╪══════════════════════════════╪══════════════════════════════╪
>> │{"floral":1,"testData":"1","pr│{"profile":"A","description":"│"Macallan"
>> │"Speyside"│"Scotland"│[{"name":"Knockando 21 Year Ol│null
>> │
>> │oduct_url":"34.99","distillery│Sherried, malty and spicy, wit│
>> │ │ │d 1994 Master Reserve Single M│
>> │
>> │":"The Macallan","smoky":1,"wh│h nutty and smoky hints","id":│
>> │ │ │alt Whisky","id":"370","streng│
>> │
>> │...... │...... │
>> │ │ │...... │
>> │
>>
>> ├──────────────────────────────┼──────────────────────────────┼────────────┼──────────┼──────────┼──────────────────────────────┼──────────────────────────────┼
>> │{"floral":1,"testData":"1","pr│{"profile":"A","description":"│"Macallan"
>> │"Speyside"│"Scotland"│[{"name":"Glen Moray 12 Year O│[{"name":"Laphroaig
>> Select Sin│
>> │oduct_url":"34.99","distillery│Sherried, malty and spicy, wit│
>> │ │ │ld Single Malt Whisky","id":"3│gle Malt
>> Whisky","id":"217","s│
>> │":"The Macallan","smoky":1,"wh│h nutty and smoky hints","id":│
>> │ │ │10","strength":6,"img":"http:/│trength":6,"img":"
>> http://cdn1.│ <http://cdn1.xn--bwh>
>> │...... │...... │
>> │ │ │...... │
>> │
>>
>> └──────────────────────────────┴──────────────────────────────┴────────────┴──────────┴──────────┴──────────────────────────────┴──────────────────────────────┴
>> Started streaming 2 records after 5548 ms and completed after 5550 ms.
>>
>>
>> Is this a bug I need to report on Github or has the community come across
>> this before and have a solution?
>>
>
--
You received this message because you are subscribed to the Google Groups
"Neo4j" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.