Package org.neo4j.index.lucene

Examples of org.neo4j.index.lucene.QueryContext


    }
  }
 
  public void getNodesWithHighPageRank(){
    Index<Node> ix = graphDB.index().forNodes("pageRank");
    QueryContext c = new QueryContext(new Object());
   
    IndexHits<Node> hits;
        hits = ix.query("pr", new QueryContext("*").sort("pr").top(200));
        for (Node hit: hits){
          System.out.println(hit.getProperty("pageRankValue"));
        }
  }
View Full Code Here


      for (int i = 0; i < 10; i++) {
        Sort s = new Sort();
        s.setSort(new SortField("pr", SortField.DOUBLE, true));
        long start = System.currentTimeMillis();
        IndexHits<Node> res = test.query(new QueryContext("title:"
            + array[i]).sort(s));
        if (res == null)
          continue;
        for (Node n : res) {
          if (n.hasProperty("name")) {
View Full Code Here

    String queryString = "label:(Tert*)";
   
    System.out.println("Querry index: "+ queryString);
   
    IndexHits<Node> results = index.query(
        new QueryContext(queryString).
          defaultOperator(Operator.AND).
          sort("score", "label").
          top(200)
        );
   
View Full Code Here

    // setup sort field
    Sort s = new Sort();
    s.setSort(new SortField("score", SortField.DOUBLE, true));

    // run query
    IndexHits<Node> queryReults = index.query(new QueryContext(query).
        defaultOperator(Operator.AND).
        sort(s).
        top(20));

    IOHelper.log("Query returned " + queryReults.size() + " results.");
View Full Code Here

    Index<Node> index = ContextHelper.getSearchIndex(servletContext);
   
    String queryString = ContextHelper.prepareQueryString("Heinrich Hartmann");

    IndexHits<Node> res = index.query(new QueryContext(queryString).defaultOperator(Operator.AND).sort(s).top(2));

     
    if (index == null){
      System.out.println("No Index found");
      return null;
View Full Code Here

        }

        allExactMatch &= attr.isExactMatch();
      }

      QueryContext queryContext = new QueryContext(query);
      IndexHits hits            = null;

      if (sortKey != null) {

        Integer sortType = sortKey.getSortType();
        if (sortType != null) {

          queryContext.sort(new Sort(new SortField(sortKey.dbName(), sortType, sortDescending)));

        } else {

          queryContext.sort(new Sort(new SortField(sortKey.dbName(), Locale.getDefault(), sortDescending)));
        }

      }

      if (distanceSearch != null) {

        if (coords != null) {

          Map<String, Object> params = new HashMap<>();

          params.put(LayerNodeIndex.POINT_PARAMETER, coords.toArray());
          params.put(LayerNodeIndex.DISTANCE_IN_KM_PARAMETER, dist);

          LayerNodeIndex spatialIndex = this.getSpatialIndex();
          if (spatialIndex != null) {

            synchronized (spatialIndex) {

              hits = spatialIndex.query(LayerNodeIndex.WITHIN_DISTANCE_QUERY, params);
            }
          }
        }

        // instantiate spatial search results without paging,
        // as the results must be filtered by type anyway
        intermediateResult = new NodeFactory(securityContext).instantiate(hits);

      } else if (allExactMatch) {

        index = getKeywordIndex();

        synchronized (index) {

          try {
            hits = index.query(queryContext);

          } catch (NumberFormatException nfe) {

            logger.log(Level.SEVERE, "Could not sort results", nfe);

            // retry without sorting
            queryContext.sort(null);
            hits = index.query(queryContext);

          }
        }

        // all luecene query, do not filter results
        filterResults = hasEmptySearchFields;
        intermediateResult = factory.instantiate(hits);

      } else {

        // Default: Mixed or fulltext-only search: Use fulltext index
        index = getFulltextIndex();

        synchronized (index) {

          try {
            hits = index.query(queryContext);

          } catch (NumberFormatException nfe) {

            logger.log(Level.SEVERE, "Could not sort results", nfe);

            // retry without sorting
            queryContext.sort(null);
            hits = index.query(queryContext);

          }
        }
View Full Code Here

    public Response routeSearch( @QueryParam( "routeId" ) String routeId )
    {

        if ( routeId == null || routeId.trim().length() == 0 )
            return Response.serverError().entity( "routeId cannot be blank" ).build();
        IndexHits<Node> hits = stopLayer.query( new QueryContext( new Term(
                Stop.ROUTEID, routeId ) ).sort( new Sort( new SortField(
                Stop.STOPNUM, SortField.INT ) ) ) );

        if ( hits.hasNext() )
        {
View Full Code Here

        Query query1 = new TermQuery( new Term( Stop.ROUTEID, (String) nodeList.get( 0 ).getProperty(Stop.ROUTEID ) )) ;
        Query query2 = NumericRangeQuery.newIntRange( Stop.STOPNUM, startNum, endNum, true, true );
        BooleanQuery booleanQuery = new BooleanQuery();
        booleanQuery.add(query1, BooleanClause.Occur.MUST);
        booleanQuery.add(query2, BooleanClause.Occur.MUST);
        QueryContext query = new QueryContext( booleanQuery ).sort( new Sort( new SortField( Stop.STOPNUM, SortField.INT ))) ;
       
        IndexHits<Node> stops = nodeList.get( 0 ).getGraphDatabase().index().forNodes( "stopLayer" ).query( query );
        this.numOfStops = stops.size();
        this.latLon = new ArrayList<Coordinate>();
        for(Node node : stops)
View Full Code Here

        Map<String, String> config = new HashMap<String, String>();
        config.put("provider", "lucene");
        config.put("type", "fulltext");
        final Index<Node> index = getRestGraphDb().index().forNodes("text-index", config);
        index.add(node(), "text", "any text");
        QueryContext ctx = new QueryContext("text:any t*");
        final IndexHits<Node> hits = index.query(ctx);
        Assert.assertEquals("found in index results", true, hits.hasNext());
        Assert.assertEquals("found in index results", node(), hits.next());
    }
View Full Code Here

        }
        // END SNIPPET: queryWithScore
        assertEquals( 2, hits.size() );

        // START SNIPPET: queryWithRelevance
        hits = movies.query( "title", new QueryContext( "The*" ).sortByScore() );
        // END SNIPPET: queryWithRelevance
        float previous = Float.MAX_VALUE;
        // START SNIPPET: queryWithRelevance
        for ( Node movie : hits )
        {
            // hits sorted by relevance (score)
            // END SNIPPET: queryWithRelevance
            assertTrue( hits.currentScore() <= previous );
            previous = hits.currentScore();
            // START SNIPPET: queryWithRelevance
        }
        // END SNIPPET: queryWithRelevance
        assertEquals( 2, hits.size() );

        // START SNIPPET: termQuery
        // a TermQuery will give exact matches
        Node actor = actors.query( new TermQuery( new Term( "name", "Keanu Reeves" ) ) ).getSingle();
        // END SNIPPET: termQuery
        assertEquals( "Keanu Reeves", actor.getProperty( "name" ) );

        Node theMatrix = movies.get( "title", "The Matrix" ).getSingle();
        Node theMatrixReloaded = movies.get( "title", "The Matrix Reloaded" ).getSingle();

        // START SNIPPET: wildcardTermQuery
        hits = movies.query( new WildcardQuery( new Term( "title", "The Matrix*" ) ) );
        for ( Node movie : hits )
        {
            System.out.println( movie.getProperty( "title" ) );
            // END SNIPPET: wildcardTermQuery
            assertTrue( ( (String) movie.getProperty( "title" ) ).startsWith( "The Matrix" ) );
            // START SNIPPET: wildcardTermQuery
        }
        // END SNIPPET: wildcardTermQuery
        assertEquals( 2, hits.size() );

        // START SNIPPET: numericRange
        movies.add( theMatrix, "year-numeric", new ValueContext( 1999L ).indexNumeric() );
        movies.add( theMatrixReloaded, "year-numeric", new ValueContext( 2003L ).indexNumeric() );

        // Query for range
        long startYear = 1997;
        long endYear = 2001;
        hits = movies.query( NumericRangeQuery.newLongRange( "year-numeric", startYear, endYear, true, true ) );
        // END SNIPPET: numericRange
        assertEquals( theMatrix, hits.getSingle() );

        // START SNIPPET: compoundQueries
        hits = movies.query( "title:*Matrix* AND year:1999" );
        // END SNIPPET: compoundQueries

        assertEquals( theMatrix, hits.getSingle() );

        // START SNIPPET: defaultOperator
        QueryContext query = new QueryContext( "title:*Matrix* year:1999" ).defaultOperator( Operator.AND );
        hits = movies.query( query );
        // END SNIPPET: defaultOperator
        // with OR the result would be 2 hits
        assertEquals( 1, hits.size() );

        // START SNIPPET: sortedResult
        hits = movies.query( "title", new QueryContext( "*" ).sort( "title" ) );
        for ( Node hit : hits )
        {
            // all movies with a title in the index, ordered by title
        }
        // END SNIPPET: sortedResult
        assertEquals( 3, hits.size() );
        // START SNIPPET: sortedResult
        // or
        hits = movies.query( new QueryContext( "title:*" ).sort( "year", "title" ) );
        for ( Node hit : hits )
        {
            // all movies with a title in the index, ordered by year, then title
        }
        // END SNIPPET: sortedResult
View Full Code Here

TOP

Related Classes of org.neo4j.index.lucene.QueryContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.