Package org.apache.lucene.xmlparser

Examples of org.apache.lucene.xmlparser.ParserException


  {
    String fieldName=DOMUtils.getAttributeWithInheritance(e,"fieldName");
    String value=DOMUtils.getText(e);
    if((fieldName==null)||(fieldName.length()==0))
    {
      throw new ParserException("SpanTermQuery missing fieldName property ");
    }
    if((value==null)||(value.length()==0))
    {
      throw new ParserException("TermQuery missing value property ");
    }
    SpanTermQuery stq = new SpanTermQuery(new Term(fieldName,value));
   
    stq.setBoost(DOMUtils.getAttribute(e,"boost",1.0f));
    return stq;
View Full Code Here


  public SpanQuery getSpanQuery(Element e) throws ParserException
  {
    String fieldName=DOMUtils.getAttributeWithInheritance(e,"fieldName");
    if(fieldName==null)
    {
      throw new ParserException("Error: SpanOrTermsBuilder missing \"fieldName\" property");
    }

    String value=DOMUtils.getText(e);
   
    try
    {
      ArrayList clausesList=new ArrayList();
      TokenStream ts=analyzer.tokenStream(fieldName,new StringReader(value));
      Token token=ts.next();
      while(token!=null)
      {
          SpanTermQuery stq=new SpanTermQuery(new Term(fieldName,token.termText()));
          clausesList.add(stq);
        token=ts.next();       
      }
      SpanOrQuery soq=new SpanOrQuery((SpanQuery[]) clausesList.toArray(new SpanQuery[clausesList.size()]));
      soq.setBoost(DOMUtils.getAttribute(e,"boost",1.0f));
      return soq;
    }
    catch(IOException ioe)
    {
        throw new ParserException("IOException parsing value:"+value);
    }
  }
View Full Code Here

  {
   
    Element mainQueryElem=DOMUtils.getChildByTagName(e,"Query");
    if(mainQueryElem==null)
    {
      throw new ParserException("BoostingQuery missing a \"Query\" child element");
    }
    mainQueryElem=DOMUtils.getFirstChildElement(mainQueryElem);
    if(mainQueryElem==null)
    {
      throw new ParserException("BoostingQuery \"Query\" element missing a child element");
    }
    Query mainQuery=factory.getQuery(mainQueryElem);
   

    Element boostQueryElem=DOMUtils.getChildByTagName(e,"BoostQuery");
    float boost=DOMUtils.getAttribute(boostQueryElem,"boost",defaultBoost);
    if(boostQueryElem==null)
    {
      throw new ParserException("BoostingQuery missing a \"BoostQuery\" child element");
    }
    boostQueryElem=DOMUtils.getFirstChildElement(boostQueryElem);
    if(boostQueryElem==null)
    {
      throw new ParserException("BoostingQuery \"BoostQuery\" element missing a child element");
    }
    Query boostQuery=factory.getQuery(boostQueryElem);
   
    BoostingQuery bq = new BoostingQuery(mainQuery,boostQuery,boost);
    bq.setBoost(DOMUtils.getAttribute(e,"boost",1.0f));
View Full Code Here

  public SpanQuery getSpanQuery(Element e) throws ParserException
  {
    String slopString=e.getAttribute("slop");
    if((slopString==null)||(slopString.length()==0))
    {
      throw new ParserException("SpanTermQuery missing slop property ");     
    }
    int slop=Integer.parseInt(slopString);
    boolean inOrder=DOMUtils.getAttribute(e,"inOrder",false);
    ArrayList spans=new ArrayList();
    for (Node kid = e.getFirstChild(); kid != null; kid = kid.getNextSibling())
View Full Code Here

    {
          includeElem=DOMUtils.getFirstChildElement(includeElem);
    }
      if(includeElem==null)
      {
      throw new ParserException("SpanNotQuery missing Include child Element");         
      }
      Element excludeElem=DOMUtils.getChildByTagName(e,"Exclude");
      if(excludeElem!=null)
    {
          excludeElem=DOMUtils.getFirstChildElement(excludeElem);
    }
      if(excludeElem==null)
      {
      throw new ParserException("SpanNotQuery missing Exclude child Element");         
      }
      SpanQuery include=factory.getSpanQuery(includeElem);
      SpanQuery exclude=factory.getSpanQuery(excludeElem);
     
    SpanNotQuery snq = new SpanNotQuery(include,exclude);
View Full Code Here

  public Query getQuery(Element e) throws ParserException
  {
    Element filterElem=DOMUtils.getFirstChildElement(e);
    if(filterElem==null)
    {
      throw new ParserException("ConstantScoreQuery missing child element with filter");
    }
    Query q=new ConstantScoreQuery(filterFactory.getFilter(filterElem));
    q.setBoost(DOMUtils.getAttribute(e,"boost",1.0f));
    return q;
  }
View Full Code Here

      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
      {
View Full Code Here

  public Query getQuery(Element e) throws ParserException {
    String field=DOMUtils.getAttributeWithInheritance(e,"fieldName");
    String value=DOMUtils.getText(e);
    if((field==null)||(field.length()==0))
    {
      throw new ParserException("TermQuery element missing fieldName attribute");
    }
    if((value==null)||(value.length()==0))
    {
      throw new ParserException("TermQuery element missing child text property ");
    }
    TermQuery tq = new TermQuery(new Term(field,value));
   
    tq.setBoost(DOMUtils.getAttribute(e,"boost",1.0f));
    return tq;
View Full Code Here

        bq.add(new BooleanClause(q,occurs));
       
      }
      else
      {
        throw new ParserException("BooleanClause missing child query element ");
      }
    }
   
    return bq;
  }
View Full Code Here

        }     
        else       
        {
          if(occs!=null)
          {
            throw new ParserException("Invalid value for \"occurs\" attribute of clause:"+occs);
          }
        }
      }
    }
    return occurs;
View Full Code Here

TOP

Related Classes of org.apache.lucene.xmlparser.ParserException

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.