Package org.apache.nutch.searcher.Query

Examples of org.apache.nutch.searcher.Query.Clause


    // examine each clause in the Nutch query
    Clause[] clauses = input.getClauses();
   
    for (int i = 0; i <clauses.length; i++) {
      Clause c = clauses[i];
     
      //skip if not date clauses
      if (!c.getField().equals(FIELD_NAME))
        continue;
           
      String x = c.getTerm().toString();
      
      Matcher matcher = pattern.matcher(x);
      if (!matcher.matches()) {
        throw new QueryException("Wrong query syntax "+FIELD_NAME+":"+x);
      }

      // do it as lucene RangeQuery
      Term xLower = new Term(FIELD_NAME, matcher.group(1));
      Term xUpper = new Term(FIELD_NAME, matcher.group(2));

      // inclusive
      RangeQuery rangeQuery = new RangeQuery(xLower, xUpper, true);

      rangeQuery.setBoost(0.0f);                  // trigger filterization
         
      output.add(rangeQuery,
          (c.isProhibited()
              ? BooleanClause.Occur.MUST_NOT
              : (c.isRequired()
                  ? BooleanClause.Occur.MUST
                  : BooleanClause.Occur.SHOULD
                 )
           ));
            
View Full Code Here


    throws QueryException {
   
    // examine each clause in the Nutch query
    Clause[] clauses = input.getClauses();
    for (int i = 0; i < clauses.length; i++) {
      Clause c = clauses[i];

      // skip non-matching clauses
      if (!c.getField().equals(field))
        continue;

      // get the field value from the clause
      // raw fields are guaranteed to be Terms, not Phrases
      String value = c.getTerm().toString();
      if (lowerCase)
        value = value.toLowerCase();

      // add a Lucene TermQuery for this clause
      TermQuery clause = new TermQuery(new Term(field, value));
      // set boost
      clause.setBoost(boost);
      // add it as specified in query
     
      output.add(clause,
          (c.isProhibited()
              ? BooleanClause.Occur.MUST_NOT
              : (c.isRequired()
                  ? BooleanClause.Occur.MUST
                  : BooleanClause.Occur.SHOULD
                 )
           ));
    }
View Full Code Here

    throws QueryException {
   
    // examine each clause in the Nutch query
    Clause[] clauses = input.getClauses();
    for (int i = 0; i < clauses.length; i++) {
      Clause c = clauses[i];

      // skip non-matching clauses
      if (!c.getField().equals(field))
        continue;

      // get the field value from the clause
      // raw fields are guaranteed to be Terms, not Phrases
      String value = c.getTerm().toString();
      if (lowerCase)
        value = value.toLowerCase();

      // add a Lucene TermQuery for this clause
      TermQuery clause = new TermQuery(new Term(field, value));
      // set boost
      clause.setBoost(boost);
      // add it as specified in query
      output.add(clause, c.isRequired(), c.isProhibited());
    }
   
    // return the modified Lucene query
    return output;
  }
View Full Code Here

  /** Run all defined filters. */
  public static BooleanQuery filter(Query input) throws QueryException {
    // first check that all field names are claimed by some plugin
    Clause[] clauses = input.getClauses();
    for (int i = 0; i < clauses.length; i++) {
      Clause c = clauses[i];
      if (!isField(c.getField()))
        throw new QueryException("Not a known field name:"+c.getField());
    }

    // then run each plugin
    BooleanQuery output = new BooleanQuery();
    for (int i = 0 ; i < CACHE.length; i++) {
View Full Code Here

    // examine each clause in the Nutch query
    Clause[] clauses = input.getClauses();
   
    for (int i = 0; i <clauses.length; i++) {
      Clause c = clauses[i];
     
      //skip if not date clauses
      if (!c.getField().equals(FIELD_NAME))
        continue;
           
      String x = c.getTerm().toString();
      
      Matcher matcher = pattern.matcher(x);
      if (!matcher.matches()) {
        throw new QueryException("Wrong query syntax "+FIELD_NAME+":"+x);
      }

      // do it as lucene RangeQuery
      Term xLower = new Term(FIELD_NAME, matcher.group(1));
      Term xUpper = new Term(FIELD_NAME, matcher.group(2));

      // inclusive
      RangeQuery rangeQuery = new RangeQuery(xLower, xUpper, true);

      rangeQuery.setBoost(0.0f);                  // trigger filterization
         
      output.add(rangeQuery, c.isRequired(), c.isProhibited());
            
    }

    return output;
  }
View Full Code Here

    throws QueryException {
   
    // examine each clause in the Nutch query
    Clause[] clauses = input.getClauses();
    for (int i = 0; i < clauses.length; i++) {
      Clause c = clauses[i];

      // skip non-matching clauses
      if (!c.getField().equals(field))
        continue;

      // optimize phrase clause
      if (c.isPhrase()) {
        String[] opt = CommonGrams.optimizePhrase(c.getPhrase(), field);
        if (opt.length==1) {
          c = new Clause(new Query.Term(opt[0]),
                         c.isRequired(), c.isProhibited());
        } else {
          c = new Clause(new Phrase(opt), c.isRequired(), c.isProhibited());
        }
      }

      // construct appropriate Lucene clause
      org.apache.lucene.search.Query luceneClause;
      if (c.isPhrase()) {
        Phrase nutchPhrase = c.getPhrase();
        Query.Term[] terms = nutchPhrase.getTerms();
        PhraseQuery lucenePhrase = new PhraseQuery();
        for (int j = 0; j < terms.length; j++) {
          lucenePhrase.add(new Term(field, terms[j].toString()));
        }
        luceneClause = lucenePhrase;
      } else {
        luceneClause = new TermQuery(new Term(field, c.getTerm().toString()));
      }

      // set boost
      luceneClause.setBoost(boost);
      // add it as specified in query
      output.add(luceneClause, c.isRequired(), c.isProhibited());
    }
   
    // return the modified Lucene query
    return output;
  }
View Full Code Here

    // examine each clause in the Nutch query
    Clause[] clauses = input.getClauses();
   
    for (int i = 0; i <clauses.length; i++) {
      Clause c = clauses[i];
     
      //skip if not date clauses
      if (!c.getField().equals(FIELD_NAME))
        continue;
           
      String x = c.getTerm().toString();
      
      Matcher matcher = pattern.matcher(x);
      if (!matcher.matches()) {
        throw new QueryException("Wrong query syntax "+FIELD_NAME+":"+x);
      }

      // do it as lucene RangeQuery
      String xLower = matcher.group(1);
      String xUpper = matcher.group(2);

      // inclusive
      TermRangeQuery rangeQuery = new TermRangeQuery(
          c.getField(), xLower, xUpper, true, true);

      rangeQuery.setBoost(0.0f);                  // trigger filterization
         
      output.add(rangeQuery,
          (c.isProhibited()
              ? BooleanClause.Occur.MUST_NOT
              : (c.isRequired()
                  ? BooleanClause.Occur.MUST
                  : BooleanClause.Occur.SHOULD
                 )
           ));
            
View Full Code Here

    // examine each clause in the Nutch query
    Clause[] clauses = input.getClauses();
   
    for (int i = 0; i <clauses.length; i++) {
      Clause c = clauses[i];
     
      //skip if not date clauses
      if (!c.getField().equals(FIELD_NAME))
        continue;
           
      String x = c.getTerm().toString();
      
      Matcher matcher = pattern.matcher(x);
      if (!matcher.matches()) {
        throw new QueryException("Wrong query syntax "+FIELD_NAME+":"+x);
      }

      // do it as lucene RangeQuery
      Term xLower = new Term(FIELD_NAME, matcher.group(1));
      Term xUpper = new Term(FIELD_NAME, matcher.group(2));

      // inclusive
      RangeQuery rangeQuery = new RangeQuery(xLower, xUpper, true);

      rangeQuery.setBoost(0.0f);                  // trigger filterization
         
      output.add(rangeQuery,
          (c.isProhibited()
              ? BooleanClause.Occur.MUST_NOT
              : (c.isRequired()
                  ? BooleanClause.Occur.MUST
                  : BooleanClause.Occur.SHOULD
                 )
           ));
            
View Full Code Here

    throws QueryException {
   
    // examine each clause in the Nutch query
    Clause[] clauses = input.getClauses();
    for (int i = 0; i < clauses.length; i++) {
      Clause c = clauses[i];

      // skip non-matching clauses
      if (!c.getField().equals(field))
        continue;

      // optimize phrase clause
      if (c.isPhrase()) {
        String[] opt = this.commonGrams.optimizePhrase(c.getPhrase(), field);
        if (opt.length==1) {
          c = new Clause(new Query.Term(opt[0]),
                         c.isRequired(), c.isProhibited(), getConf());
        } else {
          c = new Clause(new Phrase(opt), c.isRequired(), c.isProhibited(), getConf());
        }
      }

      // construct appropriate Lucene clause
      org.apache.lucene.search.Query luceneClause;
      if (c.isPhrase()) {
        Phrase nutchPhrase = c.getPhrase();
        Query.Term[] terms = nutchPhrase.getTerms();
        PhraseQuery lucenePhrase = new PhraseQuery();
        for (int j = 0; j < terms.length; j++) {
          lucenePhrase.add(new Term(field, terms[j].toString()));
        }
        luceneClause = lucenePhrase;
      } else {
        luceneClause = new TermQuery(new Term(field, c.getTerm().toString()));
      }

      // set boost
      luceneClause.setBoost(boost);
      // add it as specified in query
     
      output.add(luceneClause,
          (c.isProhibited()
              ? BooleanClause.Occur.MUST_NOT
              : (c.isRequired()
                  ? BooleanClause.Occur.MUST
                  : BooleanClause.Occur.SHOULD
                 )
           ));
    }
View Full Code Here

  /** Run all defined filters. */
  public BooleanQuery filter(Query input) throws QueryException {
    // first check that all field names are claimed by some plugin
    Clause[] clauses = input.getClauses();
    for (int i = 0; i < clauses.length; i++) {
      Clause c = clauses[i];
      if (!isField(c.getField()))
        throw new QueryException("Not a known field name:"+c.getField());
    }

    // then run each plugin
    BooleanQuery output = new BooleanQuery();
    for (int i = 0; i < this.queryFilters.length; i++) {
View Full Code Here

TOP

Related Classes of org.apache.nutch.searcher.Query.Clause

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.