Package org.apache.lucene.search.similarities

Examples of org.apache.lucene.search.similarities.DefaultSimilarity


    if (VERBOSE) {
      System.out.println("TEST: searcher=" + searcher);
    }
    // even though this uses a boost-only rewrite, this test relies upon queryNorm being the default implementation,
    // otherwise scores are different!
    searcher.setSimilarity(new DefaultSimilarity());
   
    writer.close();
    String line;
    while ((line = reader.readLine()) != null) {
      String params[] = line.split(",");
View Full Code Here


    /**
     * Ensures output is either 1 (for all inputs > 0), or 0.
     */
    @Test
    public void testTF() {
        DefaultSimilarity sim = new BinarySimilarity();
        assertEquals("big positive number", 1, (int)Math.round(sim.tf(999)));
        assertEquals("slightly more than 1", 1, (int)Math.round(sim.tf(2)));
        assertEquals("just 1", 1, (int)Math.round(sim.tf(1)));
        assertEquals("slightly less than 1", 0, (int)Math.round(sim.tf(0)));
        assertEquals("big negative number", 0, (int)Math.round(sim.tf(-999)));
    }
View Full Code Here

    Object ckSimSweet = find(srchOpts, "ckSimSweet");
    Object ckSimOther = find(srchOpts, "ckSimOther");
    Object simClass = find(srchOpts, "simClass");
    Object ckSimCust = find(srchOpts, "ckSimCust");
    if (getBoolean(ckSimDef, "selected")) {
      return new DefaultSimilarity();
    } else if (getBoolean(ckSimSweet, "selected")) {
      return new SweetSpotSimilarity();
    } else if (getBoolean(ckSimOther, "selected")) {
      try {
        Class clazz = Class.forName(getString(simClass, "text"));
        if (Similarity.class.isAssignableFrom(clazz)) {
          Similarity sim = (Similarity)clazz.newInstance();
          return sim;
        } else {
          throw new Exception("Not a subclass of Similarity: " + clazz.getName());
        }
      } catch (Exception e) {
        e.printStackTrace();
        showStatus("ERROR: invalid Similarity, using default");
        setBoolean(ckSimDef, "selected", true);
        setBoolean(ckSimOther, "selected", false);
        return new DefaultSimilarity();
      }
    } else if (getBoolean(ckSimCust, "selected")) {
      return similarity;
    } else {
      return new DefaultSimilarity();
    }
  }
View Full Code Here

                                                          final Codec codec)
  throws IOException {
    return newRandomIndexWriter(dir, analyzer, codec,
      newIndexWriterConfig(TEST_VERSION_CURRENT, analyzer)
    .setCodec(codec).setMergePolicy(newLogMergePolicy())
    .setSimilarity(new DefaultSimilarity()));
  }
View Full Code Here

      reader = writer.getReader();
      writer.close();
      searcher = newSearcher(reader);
     
      // set a similarity that does not normalize our boost away
      searcher.setSimilarity(new DefaultSimilarity() {
        @Override
        public float queryNorm(float sumOfSquaredWeights) {
          return 1.0f;
        }
      });
View Full Code Here

    iw.forceMerge(1);
    iw.close();
    r = DirectoryReader.open(dir);
    reader = getOnlySegmentReader(r);
    searcher = new IndexSearcher(reader);
    searcher.setSimilarity(new DefaultSimilarity() {
      @Override
      public float queryNorm(float sumOfSquaredWeights) {
        return 1; // we disable queryNorm, both for debugging and ease of impl
      }
    });
View Full Code Here

    add("This is a test", "object", writer);
    add("a note", "note", writer);
   
    IndexReader reader = writer.getReader();
    IndexSearcher searcher = newSearcher(reader);
    searcher.setSimilarity(new DefaultSimilarity() {
      @Override
      public Explanation idfExplain(CollectionStatistics collectionStats, TermStatistics termStats[]) {
        return new Explanation(10f, "just a test");
      }
    });
View Full Code Here

    restoreProperties.put("user.timezone", System.getProperty("user.timezone"));
    savedTimeZone = TimeZone.getDefault();
    TimeZone randomTimeZone = randomTimeZone(random());
    timeZone = testTimeZone.equals("random") ? randomTimeZone : TimeZone.getTimeZone(testTimeZone);
    TimeZone.setDefault(timeZone);
    similarity = random().nextBoolean() ? new DefaultSimilarity() : new RandomSimilarityProvider(random());

    // Check codec restrictions once at class level.
    try {
      checkCodecRestrictions(codec);
    } catch (AssumptionViolatedException e) {
View Full Code Here

    IndexReader r = w.getReader();
    IndexSearcher s = newSearcher(r);
    // this test relies upon coord being the default implementation,
    // otherwise scores are different!
    s.setSimilarity(new DefaultSimilarity());

    BooleanQuery q = new BooleanQuery();
    q.add(new TermQuery(new Term("field", "a")), BooleanClause.Occur.SHOULD);

    // LUCENE-2617: make sure that a term not in the index still contributes to the score via coord factor
View Full Code Here

  public void testSlopScoring() throws IOException {
    Directory directory = newDirectory();
    RandomIndexWriter writer = new RandomIndexWriter(random(), directory,
        newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random()))
          .setMergePolicy(newLogMergePolicy())
          .setSimilarity(new DefaultSimilarity()));

    Document doc = new Document();
    doc.add(newTextField("field", "foo firstname lastname foo", Field.Store.YES));
    writer.addDocument(doc);
   
    Document doc2 = new Document();
    doc2.add(newTextField("field", "foo firstname zzz lastname foo", Field.Store.YES));
    writer.addDocument(doc2);
   
    Document doc3 = new Document();
    doc3.add(newTextField("field", "foo firstname zzz yyy lastname foo", Field.Store.YES));
    writer.addDocument(doc3);
   
    IndexReader reader = writer.getReader();
    writer.close();

    IndexSearcher searcher = newSearcher(reader);
    searcher.setSimilarity(new DefaultSimilarity());
    PhraseQuery query = new PhraseQuery();
    query.add(new Term("field", "firstname"));
    query.add(new Term("field", "lastname"));
    query.setSlop(Integer.MAX_VALUE);
    ScoreDoc[] hits = searcher.search(query, null, 1000).scoreDocs;
View Full Code Here

TOP

Related Classes of org.apache.lucene.search.similarities.DefaultSimilarity

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.