Package org.apache.lucene.search.spans

Examples of org.apache.lucene.search.spans.SpanQuery


  public SpanQuery getSpanQuery(Element e) throws ParserException
  {
      int end=DOMUtils.getAttribute(e,"end",1);
      Element child=DOMUtils.getFirstChildElement(e);
      SpanQuery q=factory.getSpanQuery(child);
     
    SpanFirstQuery sfq = new SpanFirstQuery(q,end);
   
    sfq.setBoost(DOMUtils.getAttribute(e,"boost",1.0f));
    return sfq;
View Full Code Here


        includeElem=DOMUtils.getFirstChildOrFail(includeElem);

        Element excludeElem=DOMUtils.getChildByTagOrFail(e,"Exclude");
        excludeElem=DOMUtils.getFirstChildOrFail(excludeElem);

        SpanQuery include=factory.getSpanQuery(includeElem);
        SpanQuery exclude=factory.getSpanQuery(excludeElem);
     
    SpanNotQuery snq = new SpanNotQuery(include,exclude);
   
    snq.setBoost(DOMUtils.getAttribute(e,"boost",1.0f));
    return snq;
View Full Code Here

  public SpanQuery makeSpanNearClause() {
    SpanQuery [] spanQueries = new SpanQuery[size()];
    Iterator sqi = weightBySpanQuery.keySet().iterator();
    int i = 0;
    while (sqi.hasNext()) {
      SpanQuery sq = (SpanQuery) sqi.next();
      sq.setBoost(((Float)weightBySpanQuery.get(sq)).floatValue());
      spanQueries[i++] = sq;
    }
   
    /* CHECKME: Does the underlying implementation of SpanQuery need sorting? */
    if (false) /* true when sorting needed */
      Arrays.sort(spanQueries, new Comparator() {
        public int compare(Object o1, Object o2) {
          SpanQuery sq1 = (SpanQuery) o1;
          SpanQuery sq2 = (SpanQuery) o2;
          /* compare the text of the first term of each SpanQuery */
          return  ((Term)sq1.getTerms().iterator().next()).text().compareTo(
                  ((Term)sq2.getTerms().iterator().next()).text());
        }
        public boolean equals(Object o) {return false;}
      });
      
    if (spanQueries.length == 1)
View Full Code Here

    }
      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);
   
    snq.setBoost(DOMUtils.getAttribute(e,"boost",1.0f));
    return snq;
View Full Code Here

  }

  // LUCENE-3831
  public void testNullPointerException() throws IOException {
    RegexpQuery regex = new RegexpQuery(new Term("field", "worl."));
    SpanQuery wrappedquery = new SpanMultiTermQueryWrapper<RegexpQuery>(regex);
       
    MemoryIndex mindex = new MemoryIndex(random().nextBoolean(),  random().nextInt(50) * 1024 * 1024);
    mindex.addField("field", new MockAnalyzer(random()).tokenStream("field", "hello there"));

    // This throws an NPE
View Full Code Here

  }
   
  // LUCENE-3831
  public void testPassesIfWrapped() throws IOException {
    RegexpQuery regex = new RegexpQuery(new Term("field", "worl."));
    SpanQuery wrappedquery = new SpanOrQuery(new SpanMultiTermQueryWrapper<RegexpQuery>(regex));

    MemoryIndex mindex = new MemoryIndex(random().nextBoolean(),  random().nextInt(50) * 1024 * 1024);
    mindex.addField("field", new MockAnalyzer(random()).tokenStream("field", "hello there"));

    // This passes though
View Full Code Here

      ArrayList clausesList=new ArrayList();
    for (Node kid = e.getFirstChild(); kid != null; kid = kid.getNextSibling())
    {
      if (kid.getNodeType() == Node.ELEMENT_NODE)
      {
        SpanQuery clause=factory.getSpanQuery((Element) kid);
        clausesList.add(clause);       
      }
    }     
    SpanQuery[] clauses=(SpanQuery[]) clausesList.toArray(new SpanQuery[clausesList.size()]);
    SpanOrQuery soq = new SpanOrQuery(clauses);   
View Full Code Here

    //Currently highlights "John" and "Kennedy" separately
    assertTrue("Failed to find correct number of highlights " + numHighlights + " found", numHighlights == 2);
  }
  public void testGetBestFragmentsSpan() throws Exception
  {
    SpanQuery clauses[]={
      new SpanTermQuery(new Term("contents","john")),
      new SpanTermQuery(new Term("contents","kennedy")),
      };
   
    SpanNearQuery snq=new SpanNearQuery(clauses,1,true);
View Full Code Here

    assertTrue("Failed to find correct number of highlights " + numHighlights + " found", numHighlights == 2);
  }
  public void testGetBestFragmentsFilteredQuery() throws Exception
  {
    RangeFilter rf=new RangeFilter("contents","john","john",true,true);
    SpanQuery clauses[]={
        new SpanTermQuery(new Term("contents","john")),
        new SpanTermQuery(new Term("contents","kennedy")),
        };
    SpanNearQuery snq=new SpanNearQuery(clauses,1,true);
    FilteredQuery fq=new FilteredQuery(snq,rf);
View Full Code Here

    //Currently highlights "John" and "Kennedy" separately
    assertTrue("Failed to find correct number of highlights " + numHighlights + " found", numHighlights == 2);
  }
  public void testGetBestFragmentsSpan() throws Exception
  {
    SpanQuery clauses[]={
      new SpanTermQuery(new Term("contents","john")),
      new SpanTermQuery(new Term("contents","kennedy")),
      };
   
    SpanNearQuery snq=new SpanNearQuery(clauses,1,true);
View Full Code Here

TOP

Related Classes of org.apache.lucene.search.spans.SpanQuery

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.