Package org.apache.lucene.search.function

Examples of org.apache.lucene.search.function.CustomScoreQuery


    //create a term query to search against all documents
    Query tq = new TermQuery(new Term("metafile", "doc"));

    FieldScoreQuery fsQuery = new FieldScoreQuery("geo_distance", Type.FLOAT);

    CustomScoreQuery customScore = new CustomScoreQuery(dq.getQuery(tq),fsQuery){

      @Override
      protected CustomScoreProvider getCustomScoreProvider(IndexReader reader) {
        return new CustomScoreProvider(reader) {
          @Override // TODO: broken, as reader is not used!
          public float customScore(int doc, float subQueryScore, float valSrcScore){
            System.out.println(doc);
            if (dq.distanceFilter.getDistance(doc) == null)
              return 0;

            double distance = dq.distanceFilter.getDistance(doc);
            // boost score shouldn't exceed 1
            if (distance < 1.0d)
              distance = 1.0d;
            //boost by distance is invertly proportional to
            // to distance from center point to location
            float score = (float) ((miles - distance) / miles );
            return score * subQueryScore;
          }
        };
      }
     
    };
    // Create a distance sort
    // As the radius filter has performed the distance calculations
    // already, pass in the filter to reuse the results.
    //
    DistanceFieldComparatorSource dsort = new DistanceFieldComparatorSource(dq.distanceFilter);
    Sort sort = new Sort(new SortField("foo", dsort,false));

    // Perform the search, using the term query, the serial chain filter, and the
    // distance sort
    TopDocs hits = searcher.search(customScore.createWeight(searcher),null, 1000, sort);
    int results = hits.totalHits;
    ScoreDoc[] scoreDocs = hits.scoreDocs;
   
    // Get a list of distances
    Map<Integer,Double> distances = dq.distanceFilter.getDistances();
View Full Code Here


    //create a term query to search against all documents
    Query tq = new TermQuery(new Term("metafile", "doc"));

    FieldScoreQuery fsQuery = new FieldScoreQuery("geo_distance", Type.FLOAT);

    CustomScoreQuery customScore = new CustomScoreQuery(dq.getQuery(tq),fsQuery){

      @Override
      protected CustomScoreProvider getCustomScoreProvider(IndexReader reader) {
        return new CustomScoreProvider(reader) {
          @Override // TODO: broken, as reader is not used!
          public float customScore(int doc, float subQueryScore, float valSrcScore){
            System.out.println(doc);
            if (dq.distanceFilter.getDistance(doc) == null)
              return 0;

            double distance = dq.distanceFilter.getDistance(doc);
            // boost score shouldn't exceed 1
            if (distance < 1.0d)
              distance = 1.0d;
            //boost by distance is invertly proportional to
            // to distance from center point to location
            float score = (float) ((miles - distance) / miles );
            return score * subQueryScore;
          }
        };
      }
     
    };
    // Create a distance sort
    // As the radius filter has performed the distance calculations
    // already, pass in the filter to reuse the results.
    //
    DistanceFieldComparatorSource dsort = new DistanceFieldComparatorSource(dq.distanceFilter);
    Sort sort = new Sort(new SortField("foo", dsort,false));

    // Perform the search, using the term query, the serial chain filter, and the
    // distance sort
    TopDocs hits = searcher.search(customScore.createWeight(searcher),null, 1000, sort);
    int results = hits.totalHits;
    ScoreDoc[] scoreDocs = hits.scoreDocs;

    // Get a list of distances
    Map<Integer,Double> distances = dq.distanceFilter.getDistances();
View Full Code Here

      //create a term query to search against all documents
      Query tq = new TermQuery(new Term("metafile", "doc"));
   
      FieldScoreQuery fsQuery = new FieldScoreQuery("geo_distance", Type.FLOAT);
   
      CustomScoreQuery customScore = new CustomScoreQuery(dq.getQuery(tq),fsQuery){
        @Override
        protected CustomScoreProvider getCustomScoreProvider(IndexReader reader) {
          return new CustomScoreProvider(reader) {
            @Override // TODO: broken, as reader is not used!
            public float customScore(int doc, float subQueryScore, float valSrcScore){
              //System.out.println(doc);
              if (dq.distanceFilter.getDistance(doc) == null)
                return 0;
         
              double distance = dq.distanceFilter.getDistance(doc);
              // boost score shouldn't exceed 1
              if (distance < 1.0d)
                distance = 1.0d;
              //boost by distance is invertly proportional to
              // to distance from center point to location
              float score = (float) ( (miles - distance) / miles );
              return score * subQueryScore;
            }
          };
        }
      };
      // Create a distance sort
      // As the radius filter has performed the distance calculations
      // already, pass in the filter to reuse the results.
      //
      DistanceFieldComparatorSource dsort = new DistanceFieldComparatorSource(dq.distanceFilter);
      Sort sort = new Sort(new SortField("foo", dsort,false));
   
      // Perform the search, using the term query, the serial chain filter, and the
      // distance sort
      TopDocs hits = searcher.search(customScore.createWeight(searcher),null, 1000, sort);
      int results = hits.totalHits;
      ScoreDoc[] scoreDocs = hits.scoreDocs;
   
      // Get a list of distances
      Map<Integer,Double> distances = dq.distanceFilter.getDistances();
View Full Code Here

      System.out.println(dq);
      //create a term query to search against all documents
      Query tq = new TermQuery(new Term("metafile", "doc"));
     
      FieldScoreQuery fsQuery = new FieldScoreQuery("geo_distance", Type.FLOAT);
      CustomScoreQuery customScore = new CustomScoreQuery(tq,fsQuery){
        @Override
        protected CustomScoreProvider getCustomScoreProvider(IndexReader reader) {
          return new CustomScoreProvider(reader) {
              @Override // TODO: broken, as reader is not used!
              public float customScore(int doc, float subQueryScore, float valSrcScore){
              //System.out.println(doc);
              if (dq.distanceFilter.getDistance(doc) == null)
                return 0;
           
              double distance = dq.distanceFilter.getDistance(doc);
              // boost score shouldn't exceed 1
              if (distance < 1.0d)
                distance = 1.0d;
              //boost by distance is invertly proportional to
              // to distance from center point to location
              float score = (float) ( (miles - distance) / miles );
              return score * subQueryScore;
            }
          };
        }
      };
      // Create a distance sort
      // As the radius filter has performed the distance calculations
      // already, pass in the filter to reuse the results.
      //
      DistanceFieldComparatorSource dsort = new DistanceFieldComparatorSource(dq.distanceFilter);
      Sort sort = new Sort(new SortField("foo", dsort));
     
      // Perform the search, using the term query, the serial chain filter, and the
      // distance sort
      TopDocs hits = searcher.search(customScore.createWeight(searcher),dq.getFilter(), 1000); //,sort);
      int results = hits.totalHits;
      ScoreDoc[] scoreDocs = hits.scoreDocs;
     
      // Get a list of distances
      Map<Integer,Double> distances = dq.distanceFilter.getDistances();
View Full Code Here

    //create a term query to search against all documents
    Query tq = new TermQuery(new Term("metafile", "doc"));

    FieldScoreQuery fsQuery = new FieldScoreQuery("geo_distance", Type.FLOAT);

    CustomScoreQuery customScore = new CustomScoreQuery(dq.getQuery(tq),fsQuery){

      @Override
      protected CustomScoreProvider getCustomScoreProvider(IndexReader reader) {
        return new CustomScoreProvider(reader) {
          @Override // TODO: broken, as reader is not used!
          public float customScore(int doc, float subQueryScore, float valSrcScore){
            if (VERBOSE) System.out.println(doc);
            if (dq.distanceFilter.getDistance(doc) == null)
              return 0;

            double distance = dq.distanceFilter.getDistance(doc);
            // boost score shouldn't exceed 1
            if (distance < 1.0d)
              distance = 1.0d;
            //boost by distance is invertly proportional to
            // to distance from center point to location
            float score = (float) ((miles - distance) / miles );
            return score * subQueryScore;
          }
        };
      }
     
    };
    // Create a distance sort
    // As the radius filter has performed the distance calculations
    // already, pass in the filter to reuse the results.
    //
    DistanceFieldComparatorSource dsort = new DistanceFieldComparatorSource(dq.distanceFilter);
    Sort sort = new Sort(new SortField("foo", dsort,false));

    // Perform the search, using the term query, the serial chain filter, and the
    // distance sort
    TopDocs hits = searcher.search(customScore.createWeight(searcher),null, 1000, sort);
    int results = hits.totalHits;
    ScoreDoc[] scoreDocs = hits.scoreDocs;
   
    // Get a list of distances
    Map<Integer,Double> distances = dq.distanceFilter.getDistances();
View Full Code Here

    //create a term query to search against all documents
    Query tq = new TermQuery(new Term("metafile", "doc"));

    FieldScoreQuery fsQuery = new FieldScoreQuery("geo_distance", Type.FLOAT);

    CustomScoreQuery customScore = new CustomScoreQuery(dq.getQuery(tq),fsQuery){

      @Override
      protected CustomScoreProvider getCustomScoreProvider(IndexReader reader) {
        return new CustomScoreProvider(reader) {
          @Override // TODO: broken, as reader is not used!
          public float customScore(int doc, float subQueryScore, float valSrcScore){
            if (VERBOSE) System.out.println(doc);
            if (dq.distanceFilter.getDistance(doc) == null)
              return 0;

            double distance = dq.distanceFilter.getDistance(doc);
            // boost score shouldn't exceed 1
            if (distance < 1.0d)
              distance = 1.0d;
            //boost by distance is invertly proportional to
            // to distance from center point to location
            float score = (float) ((miles - distance) / miles );
            return score * subQueryScore;
          }
        };
      }
     
    };
    // Create a distance sort
    // As the radius filter has performed the distance calculations
    // already, pass in the filter to reuse the results.
    //
    DistanceFieldComparatorSource dsort = new DistanceFieldComparatorSource(dq.distanceFilter);
    Sort sort = new Sort(new SortField("foo", dsort,false));

    // Perform the search, using the term query, the serial chain filter, and the
    // distance sort
    TopDocs hits = searcher.search(customScore.createWeight(searcher),null, 1000, sort);
    int results = hits.totalHits;
    ScoreDoc[] scoreDocs = hits.scoreDocs;

    // Get a list of distances
    Map<Integer,Double> distances = dq.distanceFilter.getDistances();
View Full Code Here

      //create a term query to search against all documents
      Query tq = new TermQuery(new Term("metafile", "doc"));
   
      FieldScoreQuery fsQuery = new FieldScoreQuery("geo_distance", Type.FLOAT);
   
      CustomScoreQuery customScore = new CustomScoreQuery(dq.getQuery(tq),fsQuery){
        @Override
        protected CustomScoreProvider getCustomScoreProvider(IndexReader reader) {
          return new CustomScoreProvider(reader) {
            @Override // TODO: broken, as reader is not used!
            public float customScore(int doc, float subQueryScore, float valSrcScore){
              if (VERBOSE) System.out.println(doc);
              if (dq.distanceFilter.getDistance(doc) == null)
                return 0;
         
              double distance = dq.distanceFilter.getDistance(doc);
              // boost score shouldn't exceed 1
              if (distance < 1.0d)
                distance = 1.0d;
              //boost by distance is invertly proportional to
              // to distance from center point to location
              float score = (float) ( (miles - distance) / miles );
              return score * subQueryScore;
            }
          };
        }
      };
      // Create a distance sort
      // As the radius filter has performed the distance calculations
      // already, pass in the filter to reuse the results.
      //
      DistanceFieldComparatorSource dsort = new DistanceFieldComparatorSource(dq.distanceFilter);
      Sort sort = new Sort(new SortField("foo", dsort,false));
   
      // Perform the search, using the term query, the serial chain filter, and the
      // distance sort
      TopDocs hits = searcher.search(customScore.createWeight(searcher),null, 1000, sort);
      int results = hits.totalHits;
      ScoreDoc[] scoreDocs = hits.scoreDocs;
   
      // Get a list of distances
      Map<Integer,Double> distances = dq.distanceFilter.getDistances();
View Full Code Here

      if (VERBOSE) System.out.println(dq);
      //create a term query to search against all documents
      Query tq = new TermQuery(new Term("metafile", "doc"));
     
      FieldScoreQuery fsQuery = new FieldScoreQuery("geo_distance", Type.FLOAT);
      CustomScoreQuery customScore = new CustomScoreQuery(tq,fsQuery){
        @Override
        protected CustomScoreProvider getCustomScoreProvider(IndexReader reader) {
          return new CustomScoreProvider(reader) {
              @Override // TODO: broken, as reader is not used!
              public float customScore(int doc, float subQueryScore, float valSrcScore){
              if (VERBOSE) System.out.println(doc);
              if (dq.distanceFilter.getDistance(doc) == null)
                return 0;
           
              double distance = dq.distanceFilter.getDistance(doc);
              // boost score shouldn't exceed 1
              if (distance < 1.0d)
                distance = 1.0d;
              //boost by distance is invertly proportional to
              // to distance from center point to location
              float score = (float) ( (miles - distance) / miles );
              return score * subQueryScore;
            }
          };
        }
      };
      // Create a distance sort
      // As the radius filter has performed the distance calculations
      // already, pass in the filter to reuse the results.
      //
      //DistanceFieldComparatorSource dsort = new DistanceFieldComparatorSource(dq.distanceFilter);
      //Sort sort = new Sort(new SortField("foo", dsort));
     
      // Perform the search, using the term query, the serial chain filter, and the
      // distance sort
      TopDocs hits = searcher.search(customScore.createWeight(searcher),dq.getFilter(), 1000); //,sort);
      int results = hits.totalHits;
      ScoreDoc[] scoreDocs = hits.scoreDocs;
     
      // Get a list of distances
      Map<Integer,Double> distances = dq.distanceFilter.getDistances();
View Full Code Here

      //create a term query to search against all documents
      Query tq = new TermQuery(new Term("metafile", "doc"));
   
      FieldScoreQuery fsQuery = new FieldScoreQuery("geo_distance", Type.FLOAT);
   
      CustomScoreQuery customScore = new CustomScoreQuery(dq.getQuery(tq),fsQuery){
     
          @Override
            public float customScore(int doc, float subQueryScore, float valSrcScore){
            //System.out.println(doc);
            if (dq.distanceFilter.getDistance(doc) == null)
View Full Code Here

      System.out.println(dq);
      //create a term query to search against all documents
      Query tq = new TermQuery(new Term("metafile", "doc"));
     
      FieldScoreQuery fsQuery = new FieldScoreQuery("geo_distance", Type.FLOAT);
      CustomScoreQuery customScore = new CustomScoreQuery(tq,fsQuery){
       
          @Override
            public float customScore(int doc, float subQueryScore, float valSrcScore){
            //System.out.println(doc);
            if (dq.distanceFilter.getDistance(doc) == null)
View Full Code Here

TOP

Related Classes of org.apache.lucene.search.function.CustomScoreQuery

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.