Skip to content

Commit

Permalink
Merge pull request #7345 from MishaDemianenko/3.0-legacy-index-sort
Browse files Browse the repository at this point in the history
Legacy index tests with sorting by string and numeric property.
  • Loading branch information
systay committed Jun 13, 2016
2 parents 370a56b + 95f62c0 commit f9ff135
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 289 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
import org.apache.lucene.search.BooleanQuery;
import org.apache.lucene.search.NumericRangeQuery;
import org.apache.lucene.search.Sort;
import org.apache.lucene.search.SortField;
import org.apache.lucene.search.SortedNumericSortField;
import org.apache.lucene.search.SortedSetSortField;
import org.apache.lucene.search.TermQuery;
import org.apache.lucene.search.similarities.DefaultSimilarity;
import org.hamcrest.CoreMatchers;
Expand Down Expand Up @@ -115,6 +118,73 @@ private <T extends PropertyContainer> void makeSureAdditionsCanBeRead(
index.delete();
}

@Test
public void queryIndexWithSortByNumeric() throws Exception
{
Index<Node> index = nodeIndex( stringMap() );
String numericProperty = "NODE_ID";

try ( Transaction transaction = graphDb.beginTx() )
{
for ( int i = 0; i < 15; i++ )
{
Node node = graphDb.createNode();
node.setProperty( numericProperty, i );
index.add( node, numericProperty, new ValueContext( i ).indexNumeric() );
}
transaction.success();
}

try ( Transaction transaction = graphDb.beginTx() )
{
QueryContext queryContext = new QueryContext( numericProperty + ":**" );
queryContext.sort( new Sort( new SortedNumericSortField( numericProperty, SortField.Type.INT, false ) ) );
IndexHits<Node> nodes = index.query( queryContext );

int expectedIndexId = 0;
for ( Node node : nodes )
{
assertEquals("Nodes should be sorted by numeric property", expectedIndexId++, node.getProperty( numericProperty ));
}
transaction.success();
}
}

@Test
public void queryIndexWithSortByString() throws Exception
{
Index<Node> index = nodeIndex( stringMap() );
String stringProperty = "NODE_NAME";

String[] names = new String[]{"Fry", "Leela", "Bender", "Amy", "Hubert", "Calculon"};
try ( Transaction transaction = graphDb.beginTx() )
{
for ( String name : names )
{
Node node = graphDb.createNode();
node.setProperty( stringProperty, name );
index.add( node, stringProperty, name );
}
transaction.success();
}

try ( Transaction transaction = graphDb.beginTx() )
{
QueryContext queryContext = new QueryContext( stringProperty + ":**" );
queryContext.sort( new Sort( new SortedSetSortField( stringProperty, true ) ) );
IndexHits<Node> nodes = index.query( queryContext );

int nameIndex = 0;
String[] sortedNames = new String[]{"Leela", "Hubert", "Fry", "Calculon", "Bender", "Amy"};
for ( Node node : nodes )
{
assertEquals("Nodes should be sorted by string property", sortedNames[nameIndex++],
node.getProperty( stringProperty ));
}
transaction.success();
}
}

@Test
public void makeSureYouGetLatestTxModificationsInQueryByDefault()
{
Expand Down

0 comments on commit f9ff135

Please sign in to comment.