Package org.apache.lucene.search

Examples of org.apache.lucene.search.TermsFilter


   *
   * @see org.apache.lucene.xmlparser.FilterBuilder#process(org.w3c.dom.Element)
   */
  public Filter getFilter(Element e) throws ParserException
  {
    TermsFilter tf = new TermsFilter();
    String text = DOMUtils.getNonBlankTextOrFail(e);
    String fieldName = DOMUtils.getAttributeWithInheritanceOrFail(e, "fieldName");
   
    try
    {
      TokenStream ts = analyzer.reusableTokenStream(fieldName, new StringReader(text));
      CharTermAttribute termAtt = ts.addAttribute(CharTermAttribute.class);
      Term term = null;
      ts.reset();
        while (ts.incrementToken()) {
        if (term == null)
        {
          term = new Term(fieldName, termAtt.toString());
        } else
        {
//           create from previous to save fieldName.intern overhead
          term = term.createTerm(termAtt.toString());
        }
        tf.addTerm(term);
      }
      ts.end();
      ts.close();
    }
    catch (IOException ioe)
View Full Code Here


   *
   * @see org.apache.lucene.xmlparser.FilterBuilder#process(org.w3c.dom.Element)
   */
  public Filter getFilter(Element e) throws ParserException
  {
    TermsFilter tf = new TermsFilter();
    String text = DOMUtils.getNonBlankTextOrFail(e);
    String fieldName = DOMUtils.getAttributeWithInheritanceOrFail(e, "fieldName");
    TokenStream ts = analyzer.tokenStream(fieldName, new StringReader(text));
    TermAttribute termAtt = ts.addAttribute(TermAttribute.class);
   
    try
    {
      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());
        }
        tf.addTerm(term);
      }
    }
    catch (IOException ioe)
    {
      throw new RuntimeException("Error constructing terms from index:"
View Full Code Here

   *
   * @see org.apache.lucene.xmlparser.FilterBuilder#process(org.w3c.dom.Element)
   */
  public Filter getFilter(Element e) throws ParserException
  {
    TermsFilter tf = new TermsFilter();
    String text = DOMUtils.getNonBlankTextOrFail(e);
    String fieldName = DOMUtils.getAttributeWithInheritanceOrFail(e, "fieldName");
    TokenStream ts = analyzer.tokenStream(fieldName, new StringReader(text));

    try
    {
      Token token = ts.next();
      Term term = null;
      while (token != null)
      {
        if (term == null)
        {
          term = new Term(fieldName, token.termText());
        } else
        {
//           create from previous to save fieldName.intern overhead
          term = term.createTerm(token.termText());
        }
        tf.addTerm(term);
        token = ts.next();
      }
    }
    catch (IOException ioe)
    {
View Full Code Here

   *
   * @see org.apache.lucene.xmlparser.FilterBuilder#process(org.w3c.dom.Element)
   */
  public Filter getFilter(Element e) throws ParserException
  {
    TermsFilter tf = new TermsFilter();
    String text = DOMUtils.getNonBlankTextOrFail(e);
    String fieldName = DOMUtils.getAttributeWithInheritanceOrFail(e, "fieldName");
    TokenStream ts = analyzer.tokenStream(fieldName, new StringReader(text));

    try
    {
      Token token = ts.next();
      Term term = null;
      while (token != null)
      {
        if (term == null)
        {
          term = new Term(fieldName, token.termText());
        } else
        {
//           create from previous to save fieldName.intern overhead
          term = term.createTerm(token.termText());
        }
        tf.addTerm(term);
        token = ts.next();
      }
    }
    catch (IOException ioe)
    {
View Full Code Here

  /* (non-Javadoc)
   * @see org.apache.lucene.xmlparser.FilterBuilder#process(org.w3c.dom.Element)
   */
  public Filter getFilter(Element e) throws ParserException
  {
    TermsFilter tf=new TermsFilter();
    NodeList nl = e.getElementsByTagName("Field");
    for(int i=0;i<nl.getLength();i++)
    {
      Element fieldElem=(Element) nl.item(i);
      String fieldName=DOMUtils.getAttributeWithInheritance(fieldElem,"fieldName");
     
      if(fieldName==null)
      {
        throw new ParserException("TermsFilter missing \"fieldName\" element");       
      }
      String text=DOMUtils.getText(fieldElem).trim();
      TokenStream ts = analyzer.tokenStream(fieldName, new StringReader(text));
      try
      {
      Token token=ts.next();
      Term term=null;
      while(token!=null)
      {
        if(term==null)
        {
          term=new Term(fieldName,token.termText());
        }
        else
        {
          term=term.createTerm(token.termText()); //create from previous to save fieldName.intern overhead
        }
        tf.addTerm(term);
        token=ts.next();
      }
      }
      catch(IOException ioe)
      {
View Full Code Here

   *
   * @see org.apache.lucene.xmlparser.FilterBuilder#process(org.w3c.dom.Element)
   */
  public Filter getFilter(Element e) throws ParserException
  {
    TermsFilter tf = new TermsFilter();
    String text = DOMUtils.getNonBlankTextOrFail(e);
    String fieldName = DOMUtils.getAttributeWithInheritanceOrFail(e, "fieldName");
    TokenStream ts = analyzer.tokenStream(fieldName, new StringReader(text));

    try
    {
      Token token = ts.next();
      Term term = null;
      while (token != null)
      {
        if (term == null)
        {
          term = new Term(fieldName, token.termText());
        } else
        {
//           create from previous to save fieldName.intern overhead
          term = term.createTerm(token.termText());
        }
        tf.addTerm(term);
        token = ts.next();
      }
    }
    catch (IOException ioe)
    {
View Full Code Here

   *
   * @see org.apache.lucene.xmlparser.FilterBuilder#process(org.w3c.dom.Element)
   */
  public Filter getFilter(Element e) throws ParserException
  {
    TermsFilter tf = new TermsFilter();
    String text = DOMUtils.getNonBlankTextOrFail(e);
    String fieldName = DOMUtils.getAttributeWithInheritanceOrFail(e, "fieldName");
    TokenStream ts = analyzer.tokenStream(fieldName, new StringReader(text));

    try
    {
                  final Token reusableToken = new Token();
      Term term = null;
                  for (Token nextToken = ts.next(reusableToken); nextToken != null; nextToken = ts.next(reusableToken)) {
        if (term == null)
        {
          term = new Term(fieldName, nextToken.term());
        } else
        {
//           create from previous to save fieldName.intern overhead
          term = term.createTerm(nextToken.term());
        }
        tf.addTerm(term);
      }
    }
    catch (IOException ioe)
    {
      throw new RuntimeException("Error constructing terms from index:"
View Full Code Here

   *
   * @see org.apache.lucene.xmlparser.FilterBuilder#process(org.w3c.dom.Element)
   */
  public Filter getFilter(Element e) throws ParserException
  {
    TermsFilter tf = new TermsFilter();
    String text = DOMUtils.getNonBlankTextOrFail(e);
    String fieldName = DOMUtils.getAttributeWithInheritanceOrFail(e, "fieldName");
    TokenStream ts = analyzer.tokenStream(fieldName, new StringReader(text));
    TermAttribute termAtt = (TermAttribute) ts.addAttribute(TermAttribute.class);
   
    try
    {
      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());
        }
        tf.addTerm(term);
      }
    }
    catch (IOException ioe)
    {
      throw new RuntimeException("Error constructing terms from index:"
View Full Code Here

   *
   * @see org.apache.lucene.xmlparser.FilterBuilder#process(org.w3c.dom.Element)
   */
  public Filter getFilter(Element e) throws ParserException
  {
    TermsFilter tf = new TermsFilter();
    String text = DOMUtils.getNonBlankTextOrFail(e);
    String fieldName = DOMUtils.getAttributeWithInheritanceOrFail(e, "fieldName");
    TokenStream ts = analyzer.tokenStream(fieldName, new StringReader(text));
    CharTermAttribute termAtt = ts.addAttribute(CharTermAttribute.class);
   
    try
    {
      Term term = null;
        while (ts.incrementToken()) {
        if (term == null)
        {
          term = new Term(fieldName, termAtt.toString());
        } else
        {
//           create from previous to save fieldName.intern overhead
          term = term.createTerm(termAtt.toString());
        }
        tf.addTerm(term);
      }
    }
    catch (IOException ioe)
    {
      throw new RuntimeException("Error constructing terms from index:"
View Full Code Here

TOP

Related Classes of org.apache.lucene.search.TermsFilter

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.