本文整理汇总了Java中org.neo4j.graphdb.index.Index.query方法的典型用法代码示例。如果您正苦于以下问题:Java Index.query方法的具体用法?Java Index.query怎么用?Java Index.query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.neo4j.graphdb.index.Index
的用法示例。
在下文中一共展示了Index.query方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getMetadataLabel
import org.neo4j.graphdb.index.Index; //导入方法依赖的package包/类
protected Response getMetadataLabel(final String label) {
StreamingOutput stream = new StreamingOutput()
{
@Override
public void write( OutputStream os ) throws IOException, WebApplicationException
{
try ( Transaction tx = database.beginTx() ) {
JsonGenerator jg = objectMapper.getFactory().createGenerator(os, JsonEncoding.UTF8);
IndexManager index = database.index();
Index<Node> metadata = index.forNodes("Metadatum");
jg.writeStartArray();
for ( Node metadatum : metadata.query( "label:"+label ) ) {
executor.writeField(metadatum, jg);
}
jg.writeEndArray();
jg.flush();
tx.success();
}
}
};
return Response.ok().entity( stream ).type( MediaType.APPLICATION_JSON ).build();
}
示例2: updateMetadataLabel
import org.neo4j.graphdb.index.Index; //导入方法依赖的package包/类
protected Response updateMetadataLabel(final String label, final String property, final String value) {
StreamingOutput stream = new StreamingOutput()
{
@Override
public void write( OutputStream os ) throws IOException, WebApplicationException
{
try ( Transaction tx = database.beginTx() ) {
JsonGenerator jg = objectMapper.getFactory().createGenerator(os, JsonEncoding.UTF8);
IndexManager index = database.index();
Index<Node> metadata = index.forNodes("Metadatum");
for ( Node metadatum : metadata.query( "label:"+label ) ) {
if (property.equals("explorable") || property.equals("searchable"))
metadatum.setProperty(property, Boolean.valueOf(value));
else
metadatum.setProperty(property, value);
}
jg.writeString("Updated "+label);
jg.flush();
tx.success();
}
}
};
return Response.ok().entity( stream ).type( MediaType.APPLICATION_JSON ).build();
}
示例3: getMetadataGroupKey
import org.neo4j.graphdb.index.Index; //导入方法依赖的package包/类
protected Response getMetadataGroupKey(final String group, final String key) {
StreamingOutput stream = new StreamingOutput()
{
@Override
public void write( OutputStream os ) throws IOException, WebApplicationException
{
try ( Transaction tx = database.beginTx() ) {
JsonGenerator jg = objectMapper.getFactory().createGenerator(os, JsonEncoding.UTF8);
IndexManager index = database.index();
Index<Node> metadata = index.forNodes("Metadatum");
jg.writeStartArray();
for ( Node metadatum : metadata.query( "group:"+group+" AND key:"+key ) ) {
executor.writeField(metadatum, jg);
}
jg.writeEndArray();
jg.flush();
tx.success();
}
}
};
return Response.ok().entity( stream ).type( MediaType.APPLICATION_JSON ).build();
}
示例4: testScoring
import org.neo4j.graphdb.index.Index; //导入方法依赖的package包/类
@Test
public void testScoring()
{
Index<Node> index = nodeIndex( LuceneIndexImplementation.FULLTEXT_CONFIG );
Node node1 = graphDb.createNode();
Node node2 = graphDb.createNode();
String key = "text";
// Where the heck did I get this sentence from?
index.add( node1, key, "a time where no one was really awake" );
index.add( node2, key, "once upon a time there was" );
restartTx();
IndexHits<Node> hits = index.query( key, new QueryContext( "once upon a time was" ).sort( Sort.RELEVANCE ) );
Node hit1 = hits.next();
float score1 = hits.currentScore();
Node hit2 = hits.next();
float score2 = hits.currentScore();
assertEquals( node2, hit1 );
assertEquals( node1, hit2 );
assertTrue( "Score 1 (" + score1 + ") should have been higher than score 2 (" + score2 + ")", score1 > score2 );
}
示例5: doSomeQueries
import org.neo4j.graphdb.index.Index; //导入方法依赖的package包/类
@Test
public void doSomeQueries()
{
Index<Node> persons = graphDb.index().forNodes( "persons" );
// START SNIPPET: query
for ( Node person : persons.query( "name", "*e*" ) )
{
// It will get Morpheus and Neo
}
Node neo = persons.query( "name:*e* AND title:\"The One\"" ).getSingle();
// END SNIPPET: query
assertNotNull( neo );
}
示例6: indexHitsFromQueryingRemovedDoesNotReturnNegativeCount
import org.neo4j.graphdb.index.Index; //导入方法依赖的package包/类
@Test
public void indexHitsFromQueryingRemovedDoesNotReturnNegativeCount()
{
Index<Node> index = nodeIndex( LuceneIndexImplementation.EXACT_CONFIG );
Node theNode = graphDb.createNode();
index.remove( theNode );
IndexHits<Node> hits = index.query( "someRandomKey", theNode.getId() );
assertTrue( hits.size() >= 0 );
}
示例7: testSortByRelevance
import org.neo4j.graphdb.index.Index; //导入方法依赖的package包/类
@Test
public void testSortByRelevance()
{
Index<Node> index = nodeIndex( LuceneIndexImplementation.EXACT_CONFIG );
Node node1 = graphDb.createNode();
Node node2 = graphDb.createNode();
Node node3 = graphDb.createNode();
index.add( node1, "name", "something" );
index.add( node2, "name", "something" );
index.add( node2, "foo", "yes" );
index.add( node3, "name", "something" );
index.add( node3, "foo", "yes" );
index.add( node3, "bar", "yes" );
restartTx();
IndexHits<Node> hits = index.query(
new QueryContext( "+name:something foo:yes bar:yes" ).sort( Sort.RELEVANCE ) );
assertEquals( node3, hits.next() );
assertEquals( node2, hits.next() );
assertEquals( node1, hits.next() );
assertFalse( hits.hasNext() );
index.delete();
node1.delete();
node2.delete();
node3.delete();
}
示例8: testNumericValueArrays
import org.neo4j.graphdb.index.Index; //导入方法依赖的package包/类
@Test
public void testNumericValueArrays()
{
Index<Node> index = nodeIndex( LuceneIndexImplementation.EXACT_CONFIG );
Node node1 = graphDb.createNode();
index.add( node1, "number", new ValueContext[]{ numeric( 45 ), numeric( 98 ) } );
Node node2 = graphDb.createNode();
index.add( node2, "number", new ValueContext[]{ numeric( 47 ), numeric( 100 ) } );
IndexHits<Node> indexResult1 = index.query( "number", newIntRange( "number", 47, 98, true, true ) );
assertThat( indexResult1, contains( node1, node2 ) );
assertThat( indexResult1.size(), is( 2 ));
IndexHits<Node> indexResult2 = index.query( "number", newIntRange( "number", 44, 46, true, true ) );
assertThat( indexResult2, contains( node1 ) );
assertThat( indexResult2.size(), is( 1 ) );
IndexHits<Node> indexResult3 = index.query( "number", newIntRange( "number", 99, 101, true, true ) );
assertThat( indexResult3, contains( node2 ) );
assertThat( indexResult3.size(), is( 1 ) );
IndexHits<Node> indexResult4 = index.query( "number", newIntRange( "number", 47, 98, false, false ) );
assertThat( indexResult4, isEmpty() );
IndexHits<Node> indexResult5 = index.query( "number", numericRange( "number", null, 98, true, true ) );
assertContains( indexResult5, node1, node2 );
IndexHits<Node> indexResult6 = index.query( "number", numericRange( "number", 47, null, true, true ) );
assertContains( indexResult6, node1, node2 );
}
示例9: shouldThrowIllegalStateForActionsAfterDeletedOnIndex4
import org.neo4j.graphdb.index.Index; //导入方法依赖的package包/类
@Test( expected = IllegalStateException.class )
public void shouldThrowIllegalStateForActionsAfterDeletedOnIndex4()
{
restartTx();
index.delete();
Index<Node> newIndex = graphDb.index().forNodes( INDEX_NAME );
newIndex.query( key, "own" );
}
示例10: testNumericValueArrays
import org.neo4j.graphdb.index.Index; //导入方法依赖的package包/类
@Test
public void testNumericValueArrays()
{
BatchInserterIndexProvider provider = new LuceneBatchInserterIndexProviderNewImpl( inserter );
BatchInserterIndex batchIndex = provider.nodeIndex( "mine", EXACT_CONFIG );
long nodeId1 = inserter.createNode( null );
batchIndex.add( nodeId1, map( "number", new ValueContext[]{ numeric( 45 ), numeric( 98 ) } ) );
long nodeId2 = inserter.createNode( null );
batchIndex.add( nodeId2, map( "number", new ValueContext[]{numeric( 47 ), numeric( 100 )} ) );
batchIndex.flush();
IndexHits<Long> batchIndexResult1 = batchIndex.query( "number", newIntRange( "number", 47, 98, true, true ) );
assertThat( batchIndexResult1, contains(nodeId1, nodeId2));
assertThat( batchIndexResult1.size(), is( 2 ));
IndexHits<Long> batchIndexResult2 = batchIndex.query( "number", newIntRange( "number", 44, 46, true, true ) );
assertThat( batchIndexResult2, contains(nodeId1));
assertThat( batchIndexResult2.size(), is( 1 ) );
IndexHits<Long> batchIndexResult3 = batchIndex.query( "number", newIntRange( "number", 99, 101, true, true ) );
assertThat( batchIndexResult3, contains( nodeId2 ) );
assertThat( batchIndexResult3.size(), is( 1 ) );
IndexHits<Long> batchIndexResult4 = batchIndex.query( "number", newIntRange( "number", 47, 98, false, false ) );
assertThat( batchIndexResult4, isEmpty() );
provider.shutdown();
switchToGraphDatabaseService();
try ( Transaction transaction = db.beginTx() )
{
Node node1 = db.getNodeById( nodeId1 );
Node node2 = db.getNodeById( nodeId2 );
Index<Node> index = db.index().forNodes( "mine" );
IndexHits<Node> indexResult1 = index.query( "number", newIntRange( "number", 47, 98, true, true ) );
assertThat(indexResult1, contains(node1, node2));
assertThat( indexResult1.size(), is( 2 ));
IndexHits<Node> indexResult2 = index.query( "number", newIntRange( "number", 44, 46, true, true ) );
assertThat(indexResult2, contains(node1));
assertThat( indexResult2.size(), is( 1 ) );
IndexHits<Node> indexResult3 = index.query( "number", newIntRange( "number", 99, 101, true, true ) );
assertThat( indexResult3, contains( node2 ) );
assertThat( indexResult3.size(), is( 1 ) );
IndexHits<Node> indexResult4 = index.query( "number", newIntRange( "number", 47, 98, false, false ) );
assertThat( indexResult4, isEmpty() );
transaction.success();
}
}
示例11: testInsertionSpeed
import org.neo4j.graphdb.index.Index; //导入方法依赖的package包/类
private <T extends PropertyContainer> void testInsertionSpeed(
Index<T> index,
EntityCreator<T> creator )
{
long t = currentTimeMillis();
int max = 500000;
for ( int i = 0; i < max; i++ )
{
T entity = creator.create();
if ( i % 5000 == 5 )
{
index.query( new TermQuery( new Term( "name", "The name " + i ) ) );
}
lastOrNull( (Iterable<T>) index.query( new QueryContext( new TermQuery( new Term( "name", "The name " + i ) ) ).tradeCorrectnessForSpeed() ) );
lastOrNull( (Iterable<T>) index.get( "name", "The name " + i ) );
index.add( entity, "name", "The name " + i );
index.add( entity, "title", "Some title " + i );
index.add( entity, "something", i + "Nothing" );
index.add( entity, "else", i + "kdfjkdjf" + i );
if ( i % 30000 == 0 )
{
restartTx();
System.out.println( i );
}
}
finishTx( true );
out.println( "insert:" + ( currentTimeMillis() - t ) );
t = currentTimeMillis();
int count = 2000000;
int resultCount = 0;
for ( int i = 0; i < count; i++ )
{
resultCount += count( (Iterator<T>) index.get( "name", "The name " + i%max ) );
}
out.println( "get(" + resultCount + "):" + (double)( currentTimeMillis() - t ) / (double)count );
t = currentTimeMillis();
resultCount = 0;
for ( int i = 0; i < count; i++ )
{
resultCount += count( (Iterator<T>) index.get( "something", i%max + "Nothing" ) );
}
out.println( "get(" + resultCount + "):" + (double)( currentTimeMillis() - t ) / (double)count );
}
示例12: call
import org.neo4j.graphdb.index.Index; //导入方法依赖的package包/类
@Override
public void call( Index<Node> self )
{
self.query( "foo", "bar" );
}