Package org.apache.lucene.index

Examples of org.apache.lucene.index.FieldInvertState


      if (!field.equals(cachedFieldName) || sim != cachedSimilarity) { // not cached?
        Info info = getInfo(field);
        int numTokens = info != null ? info.numTokens : 0;
        int numOverlapTokens = info != null ? info.numOverlapTokens : 0;
        float boost = info != null ? info.getBoost() : 1.0f;
        FieldInvertState invertState = new FieldInvertState(field, 0, numTokens, numOverlapTokens, 0, boost);
        long value = sim.computeNorm(invertState);
        norms = new MemoryIndexNormDocValues(value);
        // cache it for future reuse
        cachedNormValues = norms;
        cachedFieldName = field;
View Full Code Here


      if (!field.equals(cachedFieldName) || sim != cachedSimilarity) { // not cached?
        Info info = getInfo(field);
        int numTokens = info != null ? info.numTokens : 0;
        int numOverlapTokens = info != null ? info.numOverlapTokens : 0;
        float boost = info != null ? info.getBoost() : 1.0f;
        FieldInvertState invertState = new FieldInvertState(field, 0, numTokens, numOverlapTokens, 0, boost);
        long value = sim.computeNorm(invertState);
        norms = new MemoryIndexNormDocValues(value);
        // cache it for future reuse
        cachedNormValues = norms;
        cachedFieldName = field;
View Full Code Here

      if (!field.equals(cachedFieldName) || sim != cachedSimilarity) { // not cached?
        Info info = getInfo(field);
        int numTokens = info != null ? info.numTokens : 0;
        int numOverlapTokens = info != null ? info.numOverlapTokens : 0;
        float boost = info != null ? info.getBoost() : 1.0f;
        FieldInvertState invertState = new FieldInvertState(field, 0, numTokens, numOverlapTokens, 0, boost);
        long value = sim.computeNorm(invertState);
        norms = new MemoryIndexNormDocValues(value);
        // cache it for future reuse
        cachedNormValues = norms;
        cachedFieldName = field;
View Full Code Here

    Similarity d = new DefaultSimilarity();
    Similarity s = ss;


    // base case, should degrade
    FieldInvertState invertState = new FieldInvertState("bogus");
    invertState.setBoost(1.0f);
    for (int i = 1; i < 1000; i++) {
      invertState.setLength(i);
      assertEquals("base case: i="+i,
                   computeAndGetNorm(d, invertState),
                   computeAndGetNorm(s, invertState),
                   0.0f);
    }

    // make a sweet spot
 
    ss.setLengthNormFactors(3,10,0.5f,true);
 
    for (int i = 3; i <=10; i++) {
      invertState.setLength(i);
      assertEquals("3,10: spot i="+i,
                   1.0f,
                   computeAndDecodeNorm(ss, ss, invertState),
                   0.0f);
    }
 
    for (int i = 10; i < 1000; i++) {
      invertState.setLength(i-9);
      final byte normD = computeAndGetNorm(d, invertState);
      invertState.setLength(i);
      final byte normS = computeAndGetNorm(s, invertState);
      assertEquals("3,10: 10<x : i="+i,
                   normD,
                   normS,
                   0.0f);
    }


    // separate sweet spot for certain fields

    final SweetSpotSimilarity ssBar = new SweetSpotSimilarity();
    ssBar.setLengthNormFactors(8,13, 0.5f, false);
    final SweetSpotSimilarity ssYak = new SweetSpotSimilarity();
    ssYak.setLengthNormFactors(6,9, 0.5f, false);
    final SweetSpotSimilarity ssA = new SweetSpotSimilarity();
    ssA.setLengthNormFactors(5,8,0.5f, false);
    final SweetSpotSimilarity ssB = new SweetSpotSimilarity();
    ssB.setLengthNormFactors(5,8,0.1f, false);
   
    Similarity sp = new PerFieldSimilarityWrapper() {
      @Override
      public Similarity get(String field) {
        if (field.equals("bar"))
          return ssBar;
        else if (field.equals("yak"))
          return ssYak;
        else if (field.equals("a"))
          return ssA;
        else if (field.equals("b"))
          return ssB;
        else
          return ss;
      }
    };

    invertState = new FieldInvertState("foo");
    invertState.setBoost(1.0f);
    for (int i = 3; i <=10; i++) {
      invertState.setLength(i);
      assertEquals("f: 3,10: spot i="+i,
                   1.0f,
                   computeAndDecodeNorm(ss, sp, invertState),
                   0.0f);
    }
   
    for (int i = 10; i < 1000; i++) {
      invertState.setLength(i-9);
      final byte normD = computeAndGetNorm(d, invertState);
      invertState.setLength(i);
      final byte normS = computeAndGetNorm(sp, invertState);
      assertEquals("f: 3,10: 10<x : i="+i,
                   normD,
                   normS,
                   0.0f);
    }
   
    invertState = new FieldInvertState("bar");
    invertState.setBoost(1.0f);
    for (int i = 8; i <=13; i++) {
      invertState.setLength(i);
      assertEquals("f: 8,13: spot i="+i,
                   1.0f,
                   computeAndDecodeNorm(ss, sp, invertState),
                   0.0f);
    }
   
    invertState = new FieldInvertState("yak");
    invertState.setBoost(1.0f);
    for (int i = 6; i <=9; i++) {
      invertState.setLength(i);
      assertEquals("f: 6,9: spot i="+i,
                   1.0f,
                   computeAndDecodeNorm(ss, sp, invertState),
                   0.0f);
    }
   
    invertState = new FieldInvertState("bar");
    invertState.setBoost(1.0f);
    for (int i = 13; i < 1000; i++) {
      invertState.setLength(i-12);
      final byte normD = computeAndGetNorm(d, invertState);
      invertState.setLength(i);
      final byte normS = computeAndGetNorm(sp, invertState);
      assertEquals("f: 8,13: 13<x : i="+i,
                   normD,
                   normS,
                   0.0f);
    }
   
    invertState = new FieldInvertState("yak");
    invertState.setBoost(1.0f);
    for (int i = 9; i < 1000; i++) {
      invertState.setLength(i-8);
      final byte normD = computeAndGetNorm(d, invertState);
      invertState.setLength(i);
      final byte normS = computeAndGetNorm(sp, invertState);
      assertEquals("f: 6,9: 9<x : i="+i,
                   normD,
                   normS,
                   0.0f);
    }


    // steepness

    for (int i = 9; i < 1000; i++) {
      invertState = new FieldInvertState("a");
      invertState.setBoost(1.0f);
      invertState.setLength(i);
      final byte normSS = computeAndGetNorm(sp, invertState);
      invertState = new FieldInvertState("b");
      invertState.setBoost(1.0f);
      invertState.setLength(i);
      final byte normS = computeAndGetNorm(sp, invertState);
      assertTrue("s: i="+i+" : a="+normSS+
                 " < b="+normS,
                 normSS < normS);
    }
View Full Code Here

      if (!field.equals(cachedFieldName) || sim != cachedSimilarity) { // not cached?
        Info info = getInfo(field);
        int numTokens = info != null ? info.numTokens : 0;
        int numOverlapTokens = info != null ? info.numOverlapTokens : 0;
        float boost = info != null ? info.getBoost() : 1.0f;
        FieldInvertState invertState = new FieldInvertState(field, 0, numTokens, numOverlapTokens, 0, boost);
        long value = sim.computeNorm(invertState);
        norms = new MemoryIndexNormDocValues(value);
        // cache it for future reuse
        cachedNormValues = norms;
        cachedFieldName = field;
View Full Code Here

  public void testDiscountOverlapsBoost() throws IOException {
    DefaultSimilarity expected = new DefaultSimilarity();
    SimilarityBase actual = new DFRSimilarity(new BasicModelIne(), new AfterEffectB(), new NormalizationH2());
    expected.setDiscountOverlaps(false);
    actual.setDiscountOverlaps(false);
    FieldInvertState state = new FieldInvertState("foo");
    state.setLength(5);
    state.setNumOverlap(2);
    state.setBoost(3);
    assertEquals(expected.computeNorm(state), actual.computeNorm(state));
    expected.setDiscountOverlaps(true);
    actual.setDiscountOverlaps(true);
    assertEquals(expected.computeNorm(state), actual.computeNorm(state));
  }
View Full Code Here

      if (!field.equals(cachedFieldName) || sim != cachedSimilarity) { // not cached?
        Info info = getInfo(field);
        int numTokens = info != null ? info.numTokens : 0;
        int numOverlapTokens = info != null ? info.numOverlapTokens : 0;
        float boost = info != null ? info.getBoost() : 1.0f;
        FieldInvertState invertState = new FieldInvertState(field, 0, numTokens, numOverlapTokens, 0, boost);
        long value = sim.computeNorm(invertState);
        norms = new MemoryIndexNormDocValues(value);
        // cache it for future reuse
        cachedNormValues = norms;
        cachedFieldName = field;
View Full Code Here

    Similarity d = new DefaultSimilarity();
    Similarity s = ss;


    // base case, should degrade
    FieldInvertState invertState = new FieldInvertState("bogus");
    invertState.setBoost(1.0f);
    for (int i = 1; i < 1000; i++) {
      invertState.setLength(i);
      assertEquals("base case: i="+i,
                   computeAndGetNorm(d, invertState),
                   computeAndGetNorm(s, invertState),
                   0.0f);
    }

    // make a sweet spot
 
    ss.setLengthNormFactors(3,10,0.5f,true);
 
    for (int i = 3; i <=10; i++) {
      invertState.setLength(i);
      assertEquals("3,10: spot i="+i,
                   1.0f,
                   computeAndDecodeNorm(ss, ss, invertState),
                   0.0f);
    }
 
    for (int i = 10; i < 1000; i++) {
      invertState.setLength(i-9);
      final byte normD = computeAndGetNorm(d, invertState);
      invertState.setLength(i);
      final byte normS = computeAndGetNorm(s, invertState);
      assertEquals("3,10: 10<x : i="+i,
                   normD,
                   normS,
                   0.0f);
    }


    // separate sweet spot for certain fields

    final SweetSpotSimilarity ssBar = new SweetSpotSimilarity();
    ssBar.setLengthNormFactors(8,13, 0.5f, false);
    final SweetSpotSimilarity ssYak = new SweetSpotSimilarity();
    ssYak.setLengthNormFactors(6,9, 0.5f, false);
    final SweetSpotSimilarity ssA = new SweetSpotSimilarity();
    ssA.setLengthNormFactors(5,8,0.5f, false);
    final SweetSpotSimilarity ssB = new SweetSpotSimilarity();
    ssB.setLengthNormFactors(5,8,0.1f, false);
   
    Similarity sp = new PerFieldSimilarityWrapper() {
      @Override
      public Similarity get(String field) {
        if (field.equals("bar"))
          return ssBar;
        else if (field.equals("yak"))
          return ssYak;
        else if (field.equals("a"))
          return ssA;
        else if (field.equals("b"))
          return ssB;
        else
          return ss;
      }
    };

    invertState = new FieldInvertState("foo");
    invertState.setBoost(1.0f);
    for (int i = 3; i <=10; i++) {
      invertState.setLength(i);
      assertEquals("f: 3,10: spot i="+i,
                   1.0f,
                   computeAndDecodeNorm(ss, sp, invertState),
                   0.0f);
    }
   
    for (int i = 10; i < 1000; i++) {
      invertState.setLength(i-9);
      final byte normD = computeAndGetNorm(d, invertState);
      invertState.setLength(i);
      final byte normS = computeAndGetNorm(sp, invertState);
      assertEquals("f: 3,10: 10<x : i="+i,
                   normD,
                   normS,
                   0.0f);
    }
   
    invertState = new FieldInvertState("bar");
    invertState.setBoost(1.0f);
    for (int i = 8; i <=13; i++) {
      invertState.setLength(i);
      assertEquals("f: 8,13: spot i="+i,
                   1.0f,
                   computeAndDecodeNorm(ss, sp, invertState),
                   0.0f);
    }
   
    invertState = new FieldInvertState("yak");
    invertState.setBoost(1.0f);
    for (int i = 6; i <=9; i++) {
      invertState.setLength(i);
      assertEquals("f: 6,9: spot i="+i,
                   1.0f,
                   computeAndDecodeNorm(ss, sp, invertState),
                   0.0f);
    }
   
    invertState = new FieldInvertState("bar");
    invertState.setBoost(1.0f);
    for (int i = 13; i < 1000; i++) {
      invertState.setLength(i-12);
      final byte normD = computeAndGetNorm(d, invertState);
      invertState.setLength(i);
      final byte normS = computeAndGetNorm(sp, invertState);
      assertEquals("f: 8,13: 13<x : i="+i,
                   normD,
                   normS,
                   0.0f);
    }
   
    invertState = new FieldInvertState("yak");
    invertState.setBoost(1.0f);
    for (int i = 9; i < 1000; i++) {
      invertState.setLength(i-8);
      final byte normD = computeAndGetNorm(d, invertState);
      invertState.setLength(i);
      final byte normS = computeAndGetNorm(sp, invertState);
      assertEquals("f: 6,9: 9<x : i="+i,
                   normD,
                   normS,
                   0.0f);
    }


    // steepness

    for (int i = 9; i < 1000; i++) {
      invertState = new FieldInvertState("a");
      invertState.setBoost(1.0f);
      invertState.setLength(i);
      final byte normSS = computeAndGetNorm(sp, invertState);
      invertState = new FieldInvertState("b");
      invertState.setBoost(1.0f);
      invertState.setLength(i);
      final byte normS = computeAndGetNorm(sp, invertState);
      assertTrue("s: i="+i+" : a="+normSS+
                 " < b="+normS,
                 normSS < normS);
    }
View Full Code Here

      if (fieldName != cachedFieldName || sim != cachedSimilarity) { // not cached?
        Info info = getInfo(fieldName);
        int numTokens = info != null ? info.numTokens : 0;
        int numOverlapTokens = info != null ? info.numOverlapTokens : 0;
        float boost = info != null ? info.getBoost() : 1.0f;
        FieldInvertState invertState = new FieldInvertState(0, numTokens, numOverlapTokens, 0, boost);
        float n = sim.computeNorm(fieldName, invertState);
        byte norm = Similarity.encodeNorm(n);
        norms = new byte[] {norm};
       
        // cache it for future reuse
View Full Code Here

      if (fieldName != cachedFieldName || sim != cachedSimilarity) { // not cached?
        Info info = getInfo(fieldName);
        int numTokens = info != null ? info.numTokens : 0;
        int numOverlapTokens = info != null ? info.numOverlapTokens : 0;
        float boost = info != null ? info.getBoost() : 1.0f;
        FieldInvertState invertState = new FieldInvertState(0, numTokens, numOverlapTokens, 0, boost);
        float n = sim.computeNorm(fieldName, invertState);
        byte norm = Similarity.encodeNorm(n);
        norms = new byte[] {norm};
       
        // cache it for future reuse
View Full Code Here

TOP

Related Classes of org.apache.lucene.index.FieldInvertState

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.