org.neo4j.index.lucene.QueryContext.<init>()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(12.3k)|赞(0)|评价(0)|浏览(54)

本文整理了Java中org.neo4j.index.lucene.QueryContext.<init>方法的一些代码示例,展示了QueryContext.<init>的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。QueryContext.<init>方法的具体详情如下:
包路径:org.neo4j.index.lucene.QueryContext
类名称:QueryContext
方法名:<init>

QueryContext.<init>介绍

暂无

代码示例

代码示例来源:origin: neo4j/neo4j

private QueryContext rangeQuery( Long startTimestampOrNull, Long endTimestampOrNull )
{
  long start = startTimestampOrNull != null ? startTimestampOrNull : -Long.MAX_VALUE;
  long end = endTimestampOrNull != null ? endTimestampOrNull : MAX_VALUE;
  return new QueryContext( newLongRange( FIELD, start, end, true, true ) );
}

代码示例来源:origin: neo4j/neo4j

private QueryContext everythingQuery()
{
  return new QueryContext( newLongRange( FIELD, 0L, MAX_VALUE, true, true ) );
}

代码示例来源:origin: neo4j/neo4j

/**
   * Will create a {@link QueryContext} with a query for numeric ranges, that is
   * values that have been indexed using {@link ValueContext#indexNumeric()}.
   * It will match the type of numbers supplied to the type of values that
   * are indexed in the index, f.ex. long, int, float and double.
   * If both {@code from} and {@code to} is {@code null} then it will default
   * to int.
   *
   * @param key the property key to query.
   * @param from the low end of the range (inclusive)
   * @param to the high end of the range (inclusive)
   * @param includeFrom whether or not {@code from} (the lower bound) is inclusive
   * or not.
   * @param includeTo whether or not {@code to} (the higher bound) is inclusive
   * or not.
   * @return a {@link QueryContext} to do numeric range queries with.
   */
  @Deprecated
  public static QueryContext numericRange( String key, Number from, Number to,
      boolean includeFrom, boolean includeTo )
  {
    return new QueryContext( LuceneUtil.rangeQuery( key, from, to, includeFrom, includeTo ) );
  }
}

代码示例来源:origin: neo4j/neo4j

public ListRepresentation getIndexedRelationshipsByQuery( String indexName,
    String key, String query, String sort )
{
  if ( !graphDb.index().existsForRelationships( indexName ) )
  {
    throw new NotFoundException();
  }
  if ( query == null )
  {
    return toListRelationshipRepresentation();
  }
  Index<Relationship> index = graphDb.index().forRelationships( indexName );
  IndexResultOrder order = getOrdering( sort );
  QueryContext queryCtx = order.updateQueryContext( new QueryContext(
      query ) );
  return toListRelationshipRepresentation( index.query( key, queryCtx ), order );
}

代码示例来源:origin: neo4j/neo4j

public ListRepresentation getIndexedNodesByQuery( String indexName,
    String key, String query, String sort )
{
  if ( !graphDb.index().existsForNodes( indexName ) )
  {
    throw new NotFoundException();
  }
  if ( query == null )
  {
    return toListNodeRepresentation();
  }
  Index<Node> index = graphDb.index().forNodes( indexName );
  IndexResultOrder order = getOrdering( sort );
  QueryContext queryCtx = order.updateQueryContext( new QueryContext( query ) );
  IndexHits<Node> result = index.query( key, queryCtx );
  return toListNodeRepresentation( result, order );
}

代码示例来源:origin: neo4j/neo4j

private void queryAndSortNodesByNumericProperty( Index<Node> index, String numericProperty,
    IntFunction<? extends Number> expectedValueProvider )
{
  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 nodeIndex = 0;
    for ( Node node : nodes )
    {
      assertEquals("Nodes should be sorted by numeric property",
          expectedValueProvider.apply( nodeIndex++), node.getProperty( numericProperty ));
    }
    transaction.success();
  }
}

代码示例来源:origin: neo4j/neo4j

private void queryAndSortNodesByStringProperty( Index<Node> index, String stringProperty,
    IntFunction<String> expectedValueProvider )
{
  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 nodeIndex = 0;
    for ( Node node : nodes )
    {
      assertEquals("Nodes should be sorted by string property", expectedValueProvider.apply( nodeIndex++ ),
          node.getProperty( stringProperty ));
    }
    transaction.success();
  }
}

代码示例来源:origin: neo4j/neo4j

@Test
public void testSortingWithTopHitsInPartCommittedPartLocal()
{
  Index<Node> index = nodeIndex( LuceneIndexImplementation.FULLTEXT_CONFIG );
  Node first = graphDb.createNode();
  Node second = graphDb.createNode();
  Node third = graphDb.createNode();
  Node fourth = graphDb.createNode();
  String key = "key";
  index.add( third, key, "ccc" );
  index.add( second, key, "bbb" );
  restartTx();
  index.add( fourth, key, "ddd" );
  index.add( first, key, "aaa" );
  assertContainsInOrder( index.query( key, new QueryContext( "*" ).sort( key ) ), first, second, third, fourth );
  assertContainsInOrder( index.query( key, new QueryContext( "*" ).sort( key ).top( 2 ) ), first, second );
}

代码示例来源:origin: neo4j/neo4j

@Test
public void shouldNotGetLatestTxModificationsWhenChoosingSpeedQueries()
{
  Index<Node> index = nodeIndex( LuceneIndexImplementation.EXACT_CONFIG );
  Node node = graphDb.createNode();
  index.add( node, "key", "value" );
  QueryContext queryContext = new QueryContext( "value" ).tradeCorrectnessForSpeed();
  assertThat( index.query( "key", queryContext ), emptyIterable() );
  assertThat( index.query( "key", "value" ), Contains.contains( node ) );
}

代码示例来源:origin: neo4j/neo4j

assertContainsInOrder( index.query( new QueryContext( "name:*" ).sort( name, title ) ), adam2, adam, eva, jack );
assertContainsInOrder( index.query( new QueryContext( "name:*" ).sort( name, other ) ), adam, adam2, eva, jack );
assertContainsInOrder( index.query( new QueryContext( "name:*" ).sort( sex, title ) ), eva, jack, adam2, adam );
assertContainsInOrder( index.query( name, new QueryContext( "*" ).sort( sex, title ) ), eva, jack, adam2, adam );
assertContainsInOrder( index.query( new QueryContext( "name:*" ).sort( name, title ).top( 2 ) ), adam2, adam );

代码示例来源:origin: neo4j/neo4j

private void createNode( Index<Node> index, long version )
{
  highest( "version", index.query( new QueryContext( "version:*" ) ) );
  {
    Node node = graphdb.createNode();
    node.setProperty( "version", version );
    index.add( node, "version", version );
  }
  {
    Node node = index.get( "version", version ).getSingle();
    Node current = highest( "version", index.get( "current", "current" ) );
    if ( current != null )
    {
      index.remove( current, "current" );
    }
    index.add( node, "current", "current" );
  }
}

代码示例来源:origin: neo4j/neo4j

@Test
public void makeSureCompositeQueriesCanBeAsked()
{
  Index<Node> index = nodeIndex( LuceneIndexImplementation.EXACT_CONFIG );
  Node neo = graphDb.createNode();
  Node trinity = graphDb.createNode();
  index.add( neo, "username", "neo@matrix" );
  index.add( neo, "sex", "male" );
  index.add( trinity, "username", "trinity@matrix" );
  index.add( trinity, "sex", "female" );
  for ( int i = 0; i < 2; i++ )
  {
    assertThat( index.query( "username:*@matrix AND sex:male" ), Contains.contains( neo ) );
    assertThat( index.query( new QueryContext( "username:*@matrix sex:male" ).defaultOperator( Operator.AND ) ), Contains
        .contains( neo ) );
    assertThat( index.query( "username:*@matrix OR sex:male" ), Contains.contains( neo, trinity ) );
    assertThat( index.query( new QueryContext( "username:*@matrix sex:male" ).defaultOperator( Operator.OR ) ), Contains
        .contains( neo, trinity ) );
    restartTx();
  }
  index.delete();
}

代码示例来源:origin: neo4j/neo4j

@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();
  QueryContext queryContext = new QueryContext( "once upon a time was" ).sort( Sort.RELEVANCE );
  try ( IndexHits<Node> hits = index.query( key, queryContext ) )
  {
    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 );
  }
}

代码示例来源:origin: neo4j/neo4j

@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();
}

代码示例来源:origin: neo4j/neo4j

@Test
public void testTopHits()
{
  Index<Relationship> index = relationshipIndex( LuceneIndexImplementation.FULLTEXT_CONFIG );
  EntityCreator<Relationship> creator = RELATIONSHIP_CREATOR;
  String key = "text";
  Relationship rel1 = creator.create( key, "one two three four five six seven eight nine ten" );
  Relationship rel2 = creator.create( key, "one two three four five six seven eight other things" );
  Relationship rel3 = creator.create( key, "one two three four five six some thing else" );
  Relationship rel4 = creator.create( key, "one two three four five what ever" );
  Relationship rel5 = creator.create( key, "one two three four all that is good and bad" );
  Relationship rel6 = creator.create( key, "one two three hill or something" );
  Relationship rel7 = creator.create( key, "one two other time than this" );
  index.add( rel2, key, rel2.getProperty( key ) );
  index.add( rel1, key, rel1.getProperty( key ) );
  index.add( rel3, key, rel3.getProperty( key ) );
  index.add( rel7, key, rel7.getProperty( key ) );
  index.add( rel5, key, rel5.getProperty( key ) );
  index.add( rel4, key, rel4.getProperty( key ) );
  index.add( rel6, key, rel6.getProperty( key ) );
  String query = "one two three four five six seven";
  for ( int i = 0; i < 2; i++ )
  {
    assertContainsInOrder( index.query( key, new QueryContext( query ).top( 3 ).sort(
        Sort.RELEVANCE ) ), rel1, rel2, rel3 );
    restartTx();
  }
}

代码示例来源:origin: neo4j-contrib/neo4j-apoc-procedures

/**
 * Search in the specified index for nodes matching the the given value.
 * <p>
 * Any indexed property is searched.
 *
 * @param index The name of the index to search in.
 * @param query The query specifying what to search for.
 * @param maxNumberOfresults maximum number of results to be retruned. Defaults to 100. If -1, returns all the results.
 * @return a stream of all matching nodes.
 */
@Procedure(mode = Mode.READ)
@Description("apoc.index.search('name', 'query', [maxNumberOfResults]) YIELD node, weight - search for nodes in the free text index matching the given query")
public Stream<WeightedNodeResult> search(@Name("index") String index, @Name("query") String query,
                     @Name(value="numberOfResults", defaultValue = "100") long maxNumberOfresults) throws Exception {
  if (!db.index().existsForNodes(index)) {
    return Stream.empty();
  }
  QueryContext queryParam = new QueryContext(parseFreeTextQuery(query)).sort(Sort.RELEVANCE);
  if (maxNumberOfresults!=-1) {
    queryParam = queryParam.top((int)maxNumberOfresults);
  }
  return toWeightedNodeResult(db.index().forNodes(index).query(queryParam));    
}

代码示例来源:origin: org.neo4j.app/neo4j-server

public ListRepresentation getIndexedNodesByQuery( String indexName,
    String key, String query, String sort )
{
  if ( !graphDb.index().existsForNodes( indexName ) )
  {
    throw new NotFoundException();
  }
  if ( query == null )
  {
    return toListNodeRepresentation();
  }
  Index<Node> index = graphDb.index().forNodes( indexName );
  IndexResultOrder order = getOrdering( sort );
  QueryContext queryCtx = order.updateQueryContext( new QueryContext( query ) );
  IndexHits<Node> result = index.query( key, queryCtx );
  return toListNodeRepresentation( result, order );
}

代码示例来源:origin: org.neo4j.app/neo4j-server

public ListRepresentation getIndexedRelationshipsByQuery( String indexName,
    String key, String query, String sort )
{
  if ( !graphDb.index().existsForRelationships( indexName ) )
  {
    throw new NotFoundException();
  }
  if ( query == null )
  {
    return toListRelationshipRepresentation();
  }
  Index<Relationship> index = graphDb.index().forRelationships( indexName );
  IndexResultOrder order = getOrdering( sort );
  QueryContext queryCtx = order.updateQueryContext( new QueryContext(
      query ) );
  return toListRelationshipRepresentation( index.query( key, queryCtx ), order );
}

相关文章

微信公众号

最新文章

更多