Re: Neo4j - How to speed up Cypher search query

333 views
Skip to first unread message

Max De Marzi Jr.

unread,
Dec 5, 2012, 3:59:17 PM12/5/12
to ne...@googlegroups.com
START n = node:Destination('name:*') <-- bad

Take a look at the search example here=>

  query = "name:*#{params[:term]}* OR name2:*#{params[:term]}*"

get '/search' do 
  content_type :json
  neo = Neography::Rest.new    

  cypher = "START me=node:node_index({query}) 
            RETURN ID(me), me.name
            ORDER BY me.name
            LIMIT 15"
  query = "permalink:*#{params[:term]}* OR name:*#{params[:term]}*"
  neo.execute_query(cypher, 
                    {:query => query })["data"].
                      map{|x| 
                           { label: x[1], 
                             value: x[0] }
                         }.to_json   
end


On Wednesday, December 5, 2012 11:31:48 AM UTC-6, Kobulniczky Csongor wrote:

I'm working on a site that uses Neo4j through a php library. The thing that bothers me is that my suggestions show up quite slowly ( 1-3 seconds ). They should appear almoast instantaneously. I am using Jquery ui Autocomplete for showing results, and the following cypher query:

$query = "START n = node:Destination('name:*')
          WHERE ( n.name =~ '(?i).*"
.$input.".*' OR n.name2 =~ '(?i).*".$input.".*' ) AND has( n.published )
          RETURN n
          LIMIT 6"
;

Does anyone have any optimization ideas, or can someone tell me what am i doing wrong?

Michael Hunger

unread,
Dec 5, 2012, 11:51:04 PM12/5/12
to ne...@googlegroups.com
In general you're doing a full index scan and filter afterwards, not a graph query but just a big index lookup.

Max' approach does two things different:
- it moves your filter into the index query itself
- it creates a parameter for the index-query so that cypher can utilize its query cache and doesn't have to re-parse the query time and again


--
 
 

Kobulniczky Csongor

unread,
Dec 6, 2012, 1:02:18 AM12/6/12
to ne...@googlegroups.com
It looks great but i never worked with Ruby. I am working with PHP. Also is this case insensitive search?
I did try index lookup with lucene query ( it seems to be much faster ), but i didn`t find any way to do incasesensitive search.

Kobulniczky Csongor

unread,
Dec 6, 2012, 1:06:38 AM12/6/12
to ne...@googlegroups.com
Yes, you are right.
I did try to move filter into index query, but i couldn`t do case insensitive search that way.
Tried to use fuzzy search but that didn`t give good results.
Is there any way to do incasesensitive search in index query? Something like 'name:*term*'

Michael Hunger

unread,
Dec 6, 2012, 2:13:22 AM12/6/12
to ne...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages