Package org.apache.lucene.search.vectorhighlight.FieldTermStack

Examples of org.apache.lucene.search.vectorhighlight.FieldTermStack.TermInfo


    QueryPhraseMap nextMap = null;
    while( !fieldTermStack.isEmpty() && (phraseList.size() < phraseLimit) )
    {     
      phraseCandidate.clear();

      TermInfo ti = fieldTermStack.pop();
      currMap = fieldQuery.getFieldTermMap( field, ti.getText() );

      // if not found, discard top TermInfo from stack, then try next element
      if( currMap == null ) continue;
     
      // if found, search the longest phrase
      phraseCandidate.add( ti );
      while( true ){
        ti = fieldTermStack.pop();
        nextMap = null;
        if( ti != null )
          nextMap = currMap.getTermMap( ti.getText() );
        if( ti == null || nextMap == null ){
          if( ti != null )
            fieldTermStack.push( ti );
          if( currMap.isValidTermOrPhrase( phraseCandidate ) ){
            addIfNoOverlap( new WeightedPhraseInfo( phraseCandidate, currMap.getBoost(), currMap.getTermOrPhraseNumber() ) );
View Full Code Here


     
      // We keep TermInfos for further operations
      termsInfos = new ArrayList<TermInfo>( terms );
     
      termsOffsets = new ArrayList<Toffs>( terms.size() );
      TermInfo ti = terms.get( 0 );
      termsOffsets.add( new Toffs( ti.getStartOffset(), ti.getEndOffset() ) );
      if( terms.size() == 1 ){
        return;
      }
      int pos = ti.getPosition();
      for( int i = 1; i < terms.size(); i++ ){
        ti = terms.get( i );
        if( ti.getPosition() - pos == 1 ){
          Toffs to = termsOffsets.get( termsOffsets.size() - 1 );
          to.setEndOffset( ti.getEndOffset() );
        }
        else{
          termsOffsets.add( new Toffs( ti.getStartOffset(), ti.getEndOffset() ) );
        }
        pos = ti.getPosition();
      }
    }
View Full Code Here

    // phraseHighlight = true, fieldMatch = true
    FieldQuery fq = new FieldQuery( query, true, true );
   
    // "a"
    List<TermInfo> phraseCandidate = new ArrayList<TermInfo>();
    phraseCandidate.add( new TermInfo( "a", 0, 1, 0, 1 ) );
    assertNull( fq.searchPhrase( F, phraseCandidate ) );
    // "a b"
    phraseCandidate.add( new TermInfo( "b", 2, 3, 1, 1 ) );
    assertNull( fq.searchPhrase( F, phraseCandidate ) );
    // "a b c"
    phraseCandidate.add( new TermInfo( "c", 4, 5, 2, 1 ) );
    assertNotNull( fq.searchPhrase( F, phraseCandidate ) );
    assertNull( fq.searchPhrase( "x", phraseCandidate ) );

    // phraseHighlight = true, fieldMatch = false
    fq = new FieldQuery( query, true, false );
   
    // "a b c"
    assertNotNull( fq.searchPhrase( F, phraseCandidate ) );
    assertNotNull( fq.searchPhrase( "x", phraseCandidate ) );

    // phraseHighlight = false, fieldMatch = true
    fq = new FieldQuery( query, false, true );
   
    // "a"
    phraseCandidate.clear();
    phraseCandidate.add( new TermInfo( "a", 0, 1, 0, 1 ) );
    assertNotNull( fq.searchPhrase( F, phraseCandidate ) );
    // "a b"
    phraseCandidate.add( new TermInfo( "b", 2, 3, 1, 1 ) );
    assertNull( fq.searchPhrase( F, phraseCandidate ) );
    // "a b c"
    phraseCandidate.add( new TermInfo( "c", 4, 5, 2, 1 ) );
    assertNotNull( fq.searchPhrase( F, phraseCandidate ) );
    assertNull( fq.searchPhrase( "x", phraseCandidate ) );
  }
View Full Code Here

    // phraseHighlight = true, fieldMatch = true
    FieldQuery fq = new FieldQuery( query, true, true );
   
    // "a b c" w/ position-gap = 2
    List<TermInfo> phraseCandidate = new ArrayList<TermInfo>();
    phraseCandidate.add( new TermInfo( "a", 0, 1, 0, 1 ) );
    phraseCandidate.add( new TermInfo( "b", 2, 3, 2, 1 ) );
    phraseCandidate.add( new TermInfo( "c", 4, 5, 4, 1 ) );
    assertNull( fq.searchPhrase( F, phraseCandidate ) );

    // "a b c"~1
    query = pqF( 1F, 1, "a", "b", "c" );

    // phraseHighlight = true, fieldMatch = true
    fq = new FieldQuery( query, true, true );
   
    // "a b c" w/ position-gap = 2
    assertNotNull( fq.searchPhrase( F, phraseCandidate ) );
   
    // "a b c" w/ position-gap = 3
    phraseCandidate.clear();
    phraseCandidate.add( new TermInfo( "a", 0, 1, 0, 1 ) );
    phraseCandidate.add( new TermInfo( "b", 2, 3, 3, 1 ) );
    phraseCandidate.add( new TermInfo( "c", 4, 5, 6, 1 ) );
    assertNull( fq.searchPhrase( F, phraseCandidate ) );
  }
View Full Code Here

    FieldQuery fq = new FieldQuery( query, reader, true, true );
    QueryPhraseMap qpm = fq.getFieldTermMap(F, "defg");
    assertNotNull (qpm);
    assertNull (fq.getFieldTermMap(F, "dog"));
    List<TermInfo> phraseCandidate = new ArrayList<TermInfo>();
    phraseCandidate.add( new TermInfo( "defg", 0, 12, 0, 1 ) );
    assertNotNull (fq.searchPhrase(F, phraseCandidate));
  }
View Full Code Here

    assertConsistentLessThan( d, c );
  }

  private WeightedPhraseInfo newInfo( int startOffset, int endOffset, float boost ) {
    LinkedList< TermInfo > infos = new LinkedList< TermInfo >();
    infos.add( new TermInfo( _TestUtil.randomUnicodeString( random() ), startOffset, endOffset, 0, 0 ) );
    return new WeightedPhraseInfo( infos, boost );
  }
View Full Code Here

    assertEquals ("the(153,156,23)", stack.pop().toString());
    assertEquals ("the(195,198,31)", stack.pop().toString());
  }

  public void testTermInfoComparisonConsistency() {
    TermInfo a = new TermInfo( _TestUtil.randomUnicodeString( random() ), 0, 0, 0, 1 );
    TermInfo b = new TermInfo( _TestUtil.randomUnicodeString( random() ), 0, 0, 1, 1 );
    TermInfo c = new TermInfo( _TestUtil.randomUnicodeString( random() ), 0, 0, 2, 1 );
    TermInfo d = new TermInfo( _TestUtil.randomUnicodeString( random() ), 0, 0, 0, 1 );

    assertConsistentEquals( a, a );
    assertConsistentEquals( b, b );
    assertConsistentEquals( c, c );
    assertConsistentEquals( d, d );
View Full Code Here

    QueryPhraseMap nextMap = null;
    while( !fieldTermStack.isEmpty() && (phraseList.size() < phraseLimit) )
    {     
      phraseCandidate.clear();

      TermInfo ti = null;
      TermInfo first = null;
     
      first = ti = fieldTermStack.pop();
      currMap = fieldQuery.getFieldTermMap( field, ti.getText() );
      while (currMap == null && ti.getNext() != first) {
        ti = ti.getNext();
View Full Code Here

     
      // We keep TermInfos for further operations
      termsInfos = new ArrayList<TermInfo>( terms );
     
      termsOffsets = new ArrayList<Toffs>( terms.size() );
      TermInfo ti = terms.get( 0 );
      termsOffsets.add( new Toffs( ti.getStartOffset(), ti.getEndOffset() ) );
      if( terms.size() == 1 ){
        return;
      }
      int pos = ti.getPosition();
      for( int i = 1; i < terms.size(); i++ ){
        ti = terms.get( i );
        if( ti.getPosition() - pos == 1 ){
          Toffs to = termsOffsets.get( termsOffsets.size() - 1 );
          to.setEndOffset( ti.getEndOffset() );
        }
        else{
          termsOffsets.add( new Toffs( ti.getStartOffset(), ti.getEndOffset() ) );
        }
        pos = ti.getPosition();
      }
    }
View Full Code Here

    QueryPhraseMap nextMap = null;
    while( !fieldTermStack.isEmpty() ){
     
      phraseCandidate.clear();

      TermInfo ti = fieldTermStack.pop();
      currMap = fieldQuery.getFieldTermMap( field, ti.getText() );

      // if not found, discard top TermInfo from stack, then try next element
      if( currMap == null ) continue;
     
      // if found, search the longest phrase
      phraseCandidate.add( ti );
      while( true ){
        ti = fieldTermStack.pop();
        nextMap = null;
        if( ti != null )
          nextMap = currMap.getTermMap( ti.getText() );
        if( ti == null || nextMap == null ){
          if( ti != null )
            fieldTermStack.push( ti );
          if( currMap.isValidTermOrPhrase( phraseCandidate ) ){
            addIfNoOverlap( new WeightedPhraseInfo( phraseCandidate, currMap.getBoost(), currMap.getTermOrPhraseNumber() ) );
View Full Code Here

TOP

Related Classes of org.apache.lucene.search.vectorhighlight.FieldTermStack.TermInfo

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.