Running a case-insensitive cypher query












32















Is it possible to run a case-insensitive cypher query on neo4j?



Try that: http://console.neo4j.org/



When I type into this:



start n=node(*) 
match n-->m
where (m.name="Neo")
return m


it returns one row. But when I type into this:



start n=node(*) 
match n-->m
where (m.name="neo")
return m


it does not return anything; because the name is saved as "Neo". Is there a simple way to run case-insensitive queries?










share|improve this question



























    32















    Is it possible to run a case-insensitive cypher query on neo4j?



    Try that: http://console.neo4j.org/



    When I type into this:



    start n=node(*) 
    match n-->m
    where (m.name="Neo")
    return m


    it returns one row. But when I type into this:



    start n=node(*) 
    match n-->m
    where (m.name="neo")
    return m


    it does not return anything; because the name is saved as "Neo". Is there a simple way to run case-insensitive queries?










    share|improve this question

























      32












      32








      32


      5






      Is it possible to run a case-insensitive cypher query on neo4j?



      Try that: http://console.neo4j.org/



      When I type into this:



      start n=node(*) 
      match n-->m
      where (m.name="Neo")
      return m


      it returns one row. But when I type into this:



      start n=node(*) 
      match n-->m
      where (m.name="neo")
      return m


      it does not return anything; because the name is saved as "Neo". Is there a simple way to run case-insensitive queries?










      share|improve this question














      Is it possible to run a case-insensitive cypher query on neo4j?



      Try that: http://console.neo4j.org/



      When I type into this:



      start n=node(*) 
      match n-->m
      where (m.name="Neo")
      return m


      it returns one row. But when I type into this:



      start n=node(*) 
      match n-->m
      where (m.name="neo")
      return m


      it does not return anything; because the name is saved as "Neo". Is there a simple way to run case-insensitive queries?







      neo4j case-insensitive cypher






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 18 '12 at 10:23









      gzggzg

      62541634




      62541634
























          3 Answers
          3






          active

          oldest

          votes


















          41














          Yes, by using case insensitive regular expressions:



          WHERE m.name =~ '(?i)neo'


          http://neo4j.com/docs/developer-manual/current/cypher/clauses/where/#where-case-insensitive-regular-expressions






          share|improve this answer





















          • 2





            Link is dead now. It is shifted to http://neo4j.com/docs/developer-manual/current/#query-general. Though your answer contains the solution, it will be better to update the link for someone may end up clicking on it.

            – Gandalf
            Jul 21 '16 at 8:35













          • =~ operator does not use Indexes

            – Abhi
            Apr 12 '17 at 11:23






          • 2





            how can I pass parameter here? '(?i)$param' and '(?!)'+$param doesn't work

            – vladkras
            Nov 21 '17 at 10:22



















          9














          Another way would be:



          WHERE LOWER(m.Name) = LOWER("Neo")


          And if you are using the Neo4j Client (.NET):



          Client.Cypher.Match("(m:Entity)")
          .Where("LOWER(m.Name) = LOWER({name})")
          .WithParam("name", inputName)
          .Return(m => m.As<Entity>())
          .Results
          .FirstOrDefault();





          share|improve this answer


























          • This solution is easier to apply for parameter

            – thangdc94
            Mar 9 '18 at 7:44











          • @rotgers Wouldn't using the LOWER() function affect index lookups defined on the actual string?

            – Partha
            Aug 25 '18 at 1:33



















          1














          If anybody is looking on how to do this with a parameter, I managed to do it like this.



          query = "{}{}{}".format('Match (n) WHERE n.pageName =~ "'"(?i)", name, '" RETURN n')


          and "name" is the variable or your parameter






          share|improve this answer

























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f13439278%2frunning-a-case-insensitive-cypher-query%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            3 Answers
            3






            active

            oldest

            votes








            3 Answers
            3






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            41














            Yes, by using case insensitive regular expressions:



            WHERE m.name =~ '(?i)neo'


            http://neo4j.com/docs/developer-manual/current/cypher/clauses/where/#where-case-insensitive-regular-expressions






            share|improve this answer





















            • 2





              Link is dead now. It is shifted to http://neo4j.com/docs/developer-manual/current/#query-general. Though your answer contains the solution, it will be better to update the link for someone may end up clicking on it.

              – Gandalf
              Jul 21 '16 at 8:35













            • =~ operator does not use Indexes

              – Abhi
              Apr 12 '17 at 11:23






            • 2





              how can I pass parameter here? '(?i)$param' and '(?!)'+$param doesn't work

              – vladkras
              Nov 21 '17 at 10:22
















            41














            Yes, by using case insensitive regular expressions:



            WHERE m.name =~ '(?i)neo'


            http://neo4j.com/docs/developer-manual/current/cypher/clauses/where/#where-case-insensitive-regular-expressions






            share|improve this answer





















            • 2





              Link is dead now. It is shifted to http://neo4j.com/docs/developer-manual/current/#query-general. Though your answer contains the solution, it will be better to update the link for someone may end up clicking on it.

              – Gandalf
              Jul 21 '16 at 8:35













            • =~ operator does not use Indexes

              – Abhi
              Apr 12 '17 at 11:23






            • 2





              how can I pass parameter here? '(?i)$param' and '(?!)'+$param doesn't work

              – vladkras
              Nov 21 '17 at 10:22














            41












            41








            41







            Yes, by using case insensitive regular expressions:



            WHERE m.name =~ '(?i)neo'


            http://neo4j.com/docs/developer-manual/current/cypher/clauses/where/#where-case-insensitive-regular-expressions






            share|improve this answer















            Yes, by using case insensitive regular expressions:



            WHERE m.name =~ '(?i)neo'


            http://neo4j.com/docs/developer-manual/current/cypher/clauses/where/#where-case-insensitive-regular-expressions







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Jan 16 '17 at 13:49









            Frank S. Thomas

            3,85322146




            3,85322146










            answered Nov 18 '12 at 10:54









            Volker PacherVolker Pacher

            1,447158




            1,447158








            • 2





              Link is dead now. It is shifted to http://neo4j.com/docs/developer-manual/current/#query-general. Though your answer contains the solution, it will be better to update the link for someone may end up clicking on it.

              – Gandalf
              Jul 21 '16 at 8:35













            • =~ operator does not use Indexes

              – Abhi
              Apr 12 '17 at 11:23






            • 2





              how can I pass parameter here? '(?i)$param' and '(?!)'+$param doesn't work

              – vladkras
              Nov 21 '17 at 10:22














            • 2





              Link is dead now. It is shifted to http://neo4j.com/docs/developer-manual/current/#query-general. Though your answer contains the solution, it will be better to update the link for someone may end up clicking on it.

              – Gandalf
              Jul 21 '16 at 8:35













            • =~ operator does not use Indexes

              – Abhi
              Apr 12 '17 at 11:23






            • 2





              how can I pass parameter here? '(?i)$param' and '(?!)'+$param doesn't work

              – vladkras
              Nov 21 '17 at 10:22








            2




            2





            Link is dead now. It is shifted to http://neo4j.com/docs/developer-manual/current/#query-general. Though your answer contains the solution, it will be better to update the link for someone may end up clicking on it.

            – Gandalf
            Jul 21 '16 at 8:35







            Link is dead now. It is shifted to http://neo4j.com/docs/developer-manual/current/#query-general. Though your answer contains the solution, it will be better to update the link for someone may end up clicking on it.

            – Gandalf
            Jul 21 '16 at 8:35















            =~ operator does not use Indexes

            – Abhi
            Apr 12 '17 at 11:23





            =~ operator does not use Indexes

            – Abhi
            Apr 12 '17 at 11:23




            2




            2





            how can I pass parameter here? '(?i)$param' and '(?!)'+$param doesn't work

            – vladkras
            Nov 21 '17 at 10:22





            how can I pass parameter here? '(?i)$param' and '(?!)'+$param doesn't work

            – vladkras
            Nov 21 '17 at 10:22













            9














            Another way would be:



            WHERE LOWER(m.Name) = LOWER("Neo")


            And if you are using the Neo4j Client (.NET):



            Client.Cypher.Match("(m:Entity)")
            .Where("LOWER(m.Name) = LOWER({name})")
            .WithParam("name", inputName)
            .Return(m => m.As<Entity>())
            .Results
            .FirstOrDefault();





            share|improve this answer


























            • This solution is easier to apply for parameter

              – thangdc94
              Mar 9 '18 at 7:44











            • @rotgers Wouldn't using the LOWER() function affect index lookups defined on the actual string?

              – Partha
              Aug 25 '18 at 1:33
















            9














            Another way would be:



            WHERE LOWER(m.Name) = LOWER("Neo")


            And if you are using the Neo4j Client (.NET):



            Client.Cypher.Match("(m:Entity)")
            .Where("LOWER(m.Name) = LOWER({name})")
            .WithParam("name", inputName)
            .Return(m => m.As<Entity>())
            .Results
            .FirstOrDefault();





            share|improve this answer


























            • This solution is easier to apply for parameter

              – thangdc94
              Mar 9 '18 at 7:44











            • @rotgers Wouldn't using the LOWER() function affect index lookups defined on the actual string?

              – Partha
              Aug 25 '18 at 1:33














            9












            9








            9







            Another way would be:



            WHERE LOWER(m.Name) = LOWER("Neo")


            And if you are using the Neo4j Client (.NET):



            Client.Cypher.Match("(m:Entity)")
            .Where("LOWER(m.Name) = LOWER({name})")
            .WithParam("name", inputName)
            .Return(m => m.As<Entity>())
            .Results
            .FirstOrDefault();





            share|improve this answer















            Another way would be:



            WHERE LOWER(m.Name) = LOWER("Neo")


            And if you are using the Neo4j Client (.NET):



            Client.Cypher.Match("(m:Entity)")
            .Where("LOWER(m.Name) = LOWER({name})")
            .WithParam("name", inputName)
            .Return(m => m.As<Entity>())
            .Results
            .FirstOrDefault();






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Jan 5 '17 at 16:01

























            answered Jan 5 '17 at 15:46









            rotgersrotgers

            1,1461920




            1,1461920













            • This solution is easier to apply for parameter

              – thangdc94
              Mar 9 '18 at 7:44











            • @rotgers Wouldn't using the LOWER() function affect index lookups defined on the actual string?

              – Partha
              Aug 25 '18 at 1:33



















            • This solution is easier to apply for parameter

              – thangdc94
              Mar 9 '18 at 7:44











            • @rotgers Wouldn't using the LOWER() function affect index lookups defined on the actual string?

              – Partha
              Aug 25 '18 at 1:33

















            This solution is easier to apply for parameter

            – thangdc94
            Mar 9 '18 at 7:44





            This solution is easier to apply for parameter

            – thangdc94
            Mar 9 '18 at 7:44













            @rotgers Wouldn't using the LOWER() function affect index lookups defined on the actual string?

            – Partha
            Aug 25 '18 at 1:33





            @rotgers Wouldn't using the LOWER() function affect index lookups defined on the actual string?

            – Partha
            Aug 25 '18 at 1:33











            1














            If anybody is looking on how to do this with a parameter, I managed to do it like this.



            query = "{}{}{}".format('Match (n) WHERE n.pageName =~ "'"(?i)", name, '" RETURN n')


            and "name" is the variable or your parameter






            share|improve this answer






























              1














              If anybody is looking on how to do this with a parameter, I managed to do it like this.



              query = "{}{}{}".format('Match (n) WHERE n.pageName =~ "'"(?i)", name, '" RETURN n')


              and "name" is the variable or your parameter






              share|improve this answer




























                1












                1








                1







                If anybody is looking on how to do this with a parameter, I managed to do it like this.



                query = "{}{}{}".format('Match (n) WHERE n.pageName =~ "'"(?i)", name, '" RETURN n')


                and "name" is the variable or your parameter






                share|improve this answer















                If anybody is looking on how to do this with a parameter, I managed to do it like this.



                query = "{}{}{}".format('Match (n) WHERE n.pageName =~ "'"(?i)", name, '" RETURN n')


                and "name" is the variable or your parameter







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Nov 21 '18 at 12:54









                Suraj Rao

                23.2k85770




                23.2k85770










                answered Nov 21 '18 at 12:47









                Mursy AlguineedyMursy Alguineedy

                112




                112






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f13439278%2frunning-a-case-insensitive-cypher-query%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    MongoDB - Not Authorized To Execute Command

                    How to fix TextFormField cause rebuild widget in Flutter

                    Npm cannot find a required file even through it is in the searched directory