Package org.apache.lucene.analysis.tokenattributes

Examples of org.apache.lucene.analysis.tokenattributes.TermAttribute


    assertFalse(ts.incrementToken());
  }


  private void assertNext(TokenStream ts, String text, int startOffset, int endOffset) throws IOException {
    TermAttribute termAtt = (TermAttribute) ts.addAttribute(TermAttribute.class);
    OffsetAttribute offsetAtt = (OffsetAttribute) ts.addAttribute(OffsetAttribute.class);

    assertTrue(ts.incrementToken());
    assertEquals(text, termAtt.term());
    assertEquals(startOffset, offsetAtt.startOffset());
    assertEquals(endOffset, offsetAtt.endOffset());
  }
View Full Code Here


    assertFalse(ts.incrementToken());
  }


  private void assertNext(TokenStream ts, String text, int startOffset, int endOffset) throws IOException {
    TermAttribute termAtt = (TermAttribute) ts.addAttribute(TermAttribute.class);
    OffsetAttribute offsetAtt = (OffsetAttribute) ts.addAttribute(OffsetAttribute.class);

    assertTrue(ts.incrementToken());
    assertEquals(text, termAtt.term());
    assertEquals(startOffset, offsetAtt.startOffset());
    assertEquals(endOffset, offsetAtt.endOffset());
  }
View Full Code Here

      wlist.add(tmpBuffer.toString());
    }

    // get Analyzer from superclass and tokenize the term
    TokenStream source = getAnalyzer().tokenStream(field, new StringReader(termStr));
    TermAttribute termAtt = (TermAttribute) source.addAttribute(TermAttribute.class);
   
    int countTokens = 0;
    while (true) {
      try {
        if (!source.incrementToken()) break;
      } catch (IOException e) {
        break;
      }
      String term = termAtt.term();
      if (!"".equals(term)) {
        try {
          tlist.set(countTokens++, term);
        } catch (IndexOutOfBoundsException ioobe) {
          countTokens = -1;
View Full Code Here

   */
  protected Query getPrefixQuery(String field, String termStr) throws ParseException {
    // get Analyzer from superclass and tokenize the term
    TokenStream source = getAnalyzer().tokenStream(field, new StringReader(termStr));
    List tlist = new ArrayList();
    TermAttribute termAtt = (TermAttribute) source.addAttribute(TermAttribute.class);
   
    while (true) {
      try {
        if (!source.incrementToken()) break;
      } catch (IOException e) {
        break;
      }
      tlist.add(termAtt.term());
    }

    try {
      source.close();
    } catch (IOException e) {
View Full Code Here

   */
  protected Query getFuzzyQuery(String field, String termStr, float minSimilarity)
      throws ParseException {
    // get Analyzer from superclass and tokenize the term
    TokenStream source = getAnalyzer().tokenStream(field, new StringReader(termStr));
    TermAttribute termAtt = (TermAttribute) source.addAttribute(TermAttribute.class);
    String nextToken = null;
    boolean multipleTokens = false;
   
    try {
      if (source.incrementToken()) {
        nextToken = termAtt.term();
      }
      multipleTokens = source.incrementToken();
    } catch (IOException e) {
      nextToken = null;
    }
View Full Code Here

   */
  protected Query getRangeQuery(String field, String part1, String part2, boolean inclusive)
      throws ParseException {
    // get Analyzer from superclass and tokenize the terms
    TokenStream source = getAnalyzer().tokenStream(field, new StringReader(part1));
    TermAttribute termAtt = (TermAttribute) source.addAttribute(TermAttribute.class);
    boolean multipleTokens = false;

    // part1
    try {
      if (source.incrementToken()) {
        part1 = termAtt.term();
      }
      multipleTokens = source.incrementToken();
    } catch (IOException e) {
      // ignore
    }
    try {
      source.close();
    } catch (IOException e) {
      // ignore
    }
    if (multipleTokens) {
      throw new ParseException("Cannot build RangeQuery with analyzer " + getAnalyzer().getClass()
          + " - tokens were added to part1");
    }

    // part2
    source = getAnalyzer().tokenStream(field, new StringReader(part2));
    termAtt = (TermAttribute) source.addAttribute(TermAttribute.class);
   
    try {
      if (source.incrementToken()) {
        part2 = termAtt.term();
      }
      multipleTokens = source.incrementToken();
    } catch (IOException e) {
      // ignore
    }
View Full Code Here

   
    private void addTerms(IndexReader reader,FieldVals f) throws IOException
    {
        if(f.queryString==null) return;
        TokenStream ts=analyzer.tokenStream(f.fieldName,new StringReader(f.queryString));
        TermAttribute termAtt = ts.addAttribute(TermAttribute.class);
       
        int corpusNumDocs=reader.numDocs();
        Term internSavingTemplateTerm =new Term(f.fieldName); //optimization to avoid constructing new Term() objects
        HashSet<String> processedTerms=new HashSet<String>();
        while (ts.incrementToken())
        {
                String term = termAtt.term();
          if(!processedTerms.contains(term))
          {
            processedTerms.add(term);
                ScoreTermQueue variantsQ=new ScoreTermQueue(MAX_VARIANTS_PER_TERM); //maxNum variants considered for any one term
                float minScore=0;
View Full Code Here

    BooleanQuery bq=new BooleanQuery(DOMUtils.getAttribute(e,"disableCoord",false));
    bq.setMinimumNumberShouldMatch(DOMUtils.getAttribute(e,"minimumNumberShouldMatch",0));
    TokenStream ts = analyzer.tokenStream(fieldName, new StringReader(text));
    try
    {
      TermAttribute termAtt = ts.addAttribute(TermAttribute.class);
      Term term = null;
      while (ts.incrementToken()) {
        if (term == null)
        {
          term = new Term(fieldName, termAtt.term());
        } else
        {
//           create from previous to save fieldName.intern overhead
          term = term.createTerm(termAtt.term());
        }
        bq.add(new BooleanClause(new TermQuery(term),BooleanClause.Occur.SHOULD));
      }
    }
    catch (IOException ioe)
View Full Code Here

      wlist.add(tmpBuffer.toString());
    }

    // get Analyzer from superclass and tokenize the term
    TokenStream source = getAnalyzer().tokenStream(field, new StringReader(termStr));
    TermAttribute termAtt = source.addAttribute(TermAttribute.class);
   
    int countTokens = 0;
    while (true) {
      try {
        if (!source.incrementToken()) break;
      } catch (IOException e) {
        break;
      }
      String term = termAtt.term();
      if (!"".equals(term)) {
        try {
          tlist.set(countTokens++, term);
        } catch (IndexOutOfBoundsException ioobe) {
          countTokens = -1;
View Full Code Here

  @Override
  protected Query getPrefixQuery(String field, String termStr) throws ParseException {
    // get Analyzer from superclass and tokenize the term
    TokenStream source = getAnalyzer().tokenStream(field, new StringReader(termStr));
    List<String> tlist = new ArrayList<String>();
    TermAttribute termAtt = source.addAttribute(TermAttribute.class);
   
    while (true) {
      try {
        if (!source.incrementToken()) break;
      } catch (IOException e) {
        break;
      }
      tlist.add(termAtt.term());
    }

    try {
      source.close();
    } catch (IOException e) {
View Full Code Here

TOP

Related Classes of org.apache.lucene.analysis.tokenattributes.TermAttribute

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.