public void addQueryParams(QueryParams queryParams) {
   // restart strategy
   strategy = null;
   this.queryParams = queryParams;
   alfa = queryParams.getQueryConfiguration().getDoubleProperty("sigmoide.distance.alfa");
   beta = queryParams.getQueryConfiguration().getDoubleProperty("sigmoide.distance.beta");
   alfa2 = queryParams.getQueryConfiguration().getDoubleProperty("sigmoide.distance.alfa.2");
 }
 private void initStrategy() {
   if (strategy == null) {
     String startegyClassName;
     if (queryParams != null) {
       startegyClassName =
           queryParams.getQueryConfiguration().getProperty("scorer.spatial.score.strategy");
     } else {
       startegyClassName = ConfigProperties.getProperty("scorer.spatial.score.strategy");
     }
     try {
       strategy = (ISpatialScoreStrategy) Class.forName(startegyClassName).newInstance();
     } catch (ClassNotFoundException e) {
       logger.error(e, e);
     } catch (IllegalAccessException e) {
       logger.error(e, e);
     } catch (InstantiationException e) {
       logger.error(e, e);
     }
     strategy.init(
         biggerDiagonal,
         queryParams,
         iSpatialDistancesWrapper,
         diagonalIndex,
         internalCircleRadiumIndex);
   }
 }
Exemplo n.º 3
0
  public void testRange() throws IOException, InvalidGeoException {
    LgteIndexSearcherWrapper searcher;

    if (lm) searcher = new LgteIndexSearcherWrapper(Model.LanguageModel, path);
    else searcher = new LgteIndexSearcherWrapper(Model.VectorSpaceModel, path);

    int years = 14;

    // Building query
    QueryParams queryParams = new QueryParams();
    queryParams.setTime("1990-6-8");
    queryParams.setRadiumYears(years);
    // create a term level1query to searchCallback against indexText documents
    // doc is a word to find in text
    Query tq = new TermQuery(new Term("metafile", "doc"));

    LgteQuery lgteQuery = new LgteQuery(tq, queryParams);
    TimeDistanceSortSource dsort = new TimeDistanceSortSource();
    LgteSort sort = new LgteSort(new SortField("foo", dsort));

    LgteHits hits = searcher.search(lgteQuery, sort);
    int results = hits.length();

    // Get a list of distances, you don't need this but we keep it available, our LgteHits gives you
    // Distance Information
    ITimeDistancesWrapper timeDistancesWrapper = dsort.getTimeDistancesWrapper();

    // distances calculated from filter first pass must be less than total
    // docs, from the above test of 6 items, 5 will come from the boundary box
    // filter, but only 5 are actually in the radius of the results.

    // Note Boundary Box filtering, is not accurate enough for most systems.

    System.out.println(
        "Distance Filter filtered: " + timeDistancesWrapper.getTimeDistances().size());
    System.out.println("Results: " + results);
    System.out.println("=============================");
    assertEquals(5, timeDistancesWrapper.getTimeDistances().size());
    assertEquals(5, results);

    int lastYears = 0;
    long lastMili = 0;
    for (int i = 0; i < results; i++) {
      LgteDocumentWrapper d = hits.doc(i);

      String name = d.get("name");

      int distanceYears = hits.timeDistanceYears(i);
      long distanceMili = hits.timeDistanceMiliseconds(i);
      assertTrue(distanceYears <= years);
      assertTrue(distanceYears >= lastYears);
      assertTrue(distanceMili >= lastMili);
      lastYears = distanceYears;
      lastMili = distanceMili;

      System.out.println(
          "Name: " + name + ", Distance (years, mili):" + distanceYears + " |" + distanceMili);

      switch (i) {
        case 0:
          assertTrue(d.get("name").equals("1"));
          break;
        case 1:
          assertTrue(d.get("name").equals("2"));
          break;
        case 2:
          assertTrue(d.get("name").equals("3"));
          break;
        case 3:
          assertTrue(d.get("name").equals("4"));
          break;
        case 4:
          assertTrue(d.get("name").equals("5"));
          break;
      }
    }
    searcher.close();
  }