當前位置: 首頁>>代碼示例>>Java>>正文


Java Token.getPositionIncrement方法代碼示例

本文整理匯總了Java中org.apache.lucene.analysis.Token.getPositionIncrement方法的典型用法代碼示例。如果您正苦於以下問題:Java Token.getPositionIncrement方法的具體用法?Java Token.getPositionIncrement怎麽用?Java Token.getPositionIncrement使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.lucene.analysis.Token的用法示例。


在下文中一共展示了Token.getPositionIncrement方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testZeroPosIncrSloppyPqAnd

import org.apache.lucene.analysis.Token; //導入方法依賴的package包/類
/**
 * PQ AND Mode - Manually creating a phrase query
 */
public void testZeroPosIncrSloppyPqAnd() throws IOException {
  final PhraseQuery pq = new PhraseQuery();
  int pos = -1;
  for (Token tap : INCR_0_QUERY_TOKENS_AND) {
    pos += tap.getPositionIncrement();
    pq.add(new Term("field",tap.toString()), pos);
  }
  doTestZeroPosIncrSloppy(pq, 0);
  pq.setSlop(1);
  doTestZeroPosIncrSloppy(pq, 0);
  pq.setSlop(2);
  doTestZeroPosIncrSloppy(pq, 1);
}
 
開發者ID:europeana,項目名稱:search,代碼行數:17,代碼來源:TestMultiPhraseQuery.java

示例2: testZeroPosIncrSloppyMpqAnd

import org.apache.lucene.analysis.Token; //導入方法依賴的package包/類
/**
 * MPQ AND Mode - Manually creating a multiple phrase query
 */
public void testZeroPosIncrSloppyMpqAnd() throws IOException {
  final MultiPhraseQuery mpq = new MultiPhraseQuery();
  int pos = -1;
  for (Token tap : INCR_0_QUERY_TOKENS_AND) {
    pos += tap.getPositionIncrement();
    mpq.add(new Term[]{new Term("field",tap.toString())}, pos); //AND logic
  }
  doTestZeroPosIncrSloppy(mpq, 0);
  mpq.setSlop(1);
  doTestZeroPosIncrSloppy(mpq, 0);
  mpq.setSlop(2);
  doTestZeroPosIncrSloppy(mpq, 1);
}
 
開發者ID:europeana,項目名稱:search,代碼行數:17,代碼來源:TestMultiPhraseQuery.java

示例3: compare

import org.apache.lucene.analysis.Token; //導入方法依賴的package包/類
@Override
public int compare(final Token o1, final Token o2) {
  return o1.getPositionIncrement() - o2.getPositionIncrement();
}
 
開發者ID:europeana,項目名稱:search,代碼行數:5,代碼來源:TokenStreamFromTermPositionVector.java

示例4: getCollation

import org.apache.lucene.analysis.Token; //導入方法依賴的package包/類
private String getCollation(String origQuery,
                            List<SpellCheckCorrection> corrections) {
  StringBuilder collation = new StringBuilder(origQuery);
  int offset = 0;
  String corr = "";
  for(int i=0 ; i<corrections.size() ; i++) {
    SpellCheckCorrection correction = corrections.get(i);   
    Token tok = correction.getOriginal();
    // we are replacing the query in order, but injected terms might cause
    // illegal offsets due to previous replacements.
    if (tok.getPositionIncrement() == 0)
      continue;
    corr = correction.getCorrection();
    boolean addParenthesis = false;
    Character requiredOrProhibited = null;
    int indexOfSpace = corr.indexOf(' ');
    StringBuilder corrSb = new StringBuilder(corr);
    int bump = 1;
    
    //If the correction contains whitespace (because it involved breaking a word in 2+ words),
    //then be sure all of the new words have the same optional/required/prohibited status in the query.
    while(indexOfSpace>-1 && indexOfSpace<corr.length()-1) {
      addParenthesis = true;
      char previousChar = tok.startOffset()>0 ? origQuery.charAt(tok.startOffset()-1) : ' ';
      if(previousChar=='-' || previousChar=='+') {
        corrSb.insert(indexOfSpace + bump, previousChar);
        if(requiredOrProhibited==null) {
          requiredOrProhibited = previousChar;
        }
        bump++;
      } else if ((tok.getFlags() & QueryConverter.TERM_IN_BOOLEAN_QUERY_FLAG) == QueryConverter.TERM_IN_BOOLEAN_QUERY_FLAG) {
        corrSb.insert(indexOfSpace + bump, "AND ");
        bump += 4;
      }
      indexOfSpace = correction.getCorrection().indexOf(' ', indexOfSpace + bump);
    }
    
    int oneForReqOrProhib = 0;
    if(addParenthesis) { 
      if(requiredOrProhibited!=null) {
        corrSb.insert(0, requiredOrProhibited);
        oneForReqOrProhib++;
      }
      corrSb.insert(0, '(');
      corrSb.append(')');
    }
    corr = corrSb.toString();  
    int startIndex = tok.startOffset() + offset - oneForReqOrProhib;
    int endIndex = tok.endOffset() + offset;
    collation.replace(startIndex, endIndex, corr);
    offset += corr.length() - oneForReqOrProhib - (tok.endOffset() - tok.startOffset());      
  }
  return collation.toString();
}
 
開發者ID:europeana,項目名稱:search,代碼行數:55,代碼來源:SpellCheckCollator.java


注:本文中的org.apache.lucene.analysis.Token.getPositionIncrement方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。