[Neo4j] Limiting index query results - pagination

Mattias Persson mattias at neotechnology.com
Fri Aug 27 09:27:15 CEST 2010


You can do that out of the box. If the result size is more than a certain
threshold (100, I think) it gathers the results lazily instead of in the
getNodes method itself. So if you do a query which has lots of hits you can
keep that IndexHits instance with you to do pagination and such with. So
there's really no need to specify max number of hits to return, instead just
iterate over as many as you like and close the IndexHits instance when
you're done. It should still perform very well. If it doesn't please come
back with feedback about it.


/ Mattias

2010/8/27 Honnur Vorvoi <vhonnur at yahoo.com>

>
> Thanks Mattias, that was very helpful.
>
> I have another related question:
> Is there a way we can limit the number of search results from the index
> query?
> Basically am looking to implement pagination incase the search results
> return say thousands of records. Are there any better solutions to achieve
> the same?
>
> Would be interested to know your thoughts.
>
> Honnur
>
> --- On Wed, 8/25/10, user-request at lists.neo4j.org <
> user-request at lists.neo4j.org> wrote:
>
> Date: Wed, 25 Aug 2010 10:28:10 +0200
> From: Mattias Persson <mattias at neotechnology.com>
> Subject: Re: [Neo4j] Index search with more than one key
> To: Neo4j user discussions <user at lists.neo4j.org>
> Message-ID:
>     <AANLkTinN0fisDAAXBiYD2-KCreBmYt9GLQYSm_dgXj-q at mail.gmail.com>
> Content-Type: text/plain; charset=UTF-8
>
> There's a prototype implementation of a new index which solves this (and
> some other issues as well, f.ex. indexing for relationships). The code is
> at
> https://svn.neo4j.org/laboratory/components/lucene-index/ and it's built
> and
> deployed over at http://m2.neo4j.org/org/neo4j/neo4j-lucene-index/
>
> The new index isn't compatible with the old one so you'll have to index
> your
> data with the new index framework to be able to use it.
>
>     IndexProvider provider = new LuceneIndexProvider( graphDb );
>     Index<Node> myIndex = provider.nodeIndex( "users" );
>
>     myIndex.add( myNode, "type", "value1" );
>     myIndex.add( myNode, "key1", "value2" );
>
>     // Ask lucene queries directly here
>     for ( Node searchHit : myIndex.query( "type:value1 AND key1:value2" ) )
>     {
>         System.out.println( "Found " + searchHit );
>     }
>
> 2010/8/25 Honnur Vorvoi <vhonnur at yahoo.com>
>
> > Hello,
> >
> > Is there a way we can search nodes based on more than one property key?
> > For ex:
> > Node1:
> > type=value1,
> > key1=value2
> >
> > node2:
> > type=value1,
> > key1=value21
> >
> > node3:
> > type=value2
> > key1=value2
> >
> > node4:
> > type=value1
> > key1=value21
> > key2=value4
> >
> > Let's say type & key1 properties are indexed
> > Any suggestions on how we can get all nodes with type=value1 AND
> > key1=value21 in one call.
> >
> >
> > TIA
> > _______________________________________________
> > Neo4j mailing list
> > User at lists.neo4j.org
> > https://lists.neo4j.org/mailman/listinfo/user
> >
> _______________________________________________
> Neo4j mailing list
> User at lists.neo4j.org
> https://lists.neo4j.org/mailman/listinfo/user
>



-- 
Mattias Persson, [mattias at neotechnology.com]
Hacker, Neo Technology
www.neotechnology.com


More information about the User mailing list