Package org.apache.lucene.queryParser

Examples of org.apache.lucene.queryParser.QueryParser


  protected String go() throws Exception {
    logger.debug("Start SearchTermSuggestion. q = " + getQ()
        + " keywords size: " + keywords.size());
    if (q != null && searchTermSuggestion != null) {   
      TermQuery termQuery = null;
      QueryParser parser = new QueryParser(DocumentCreator.FIELD_TEXT,DocumentCreator.createDocumentAnalyzer());
      Query query = null;
      try{
        query = parser.parse(q);
      }catch(Exception e){
        logger.debug("QueryParser error: " + e);
      }
      if(query == null){
        return SUCCESS;
View Full Code Here


//  String query = queryString.toString();
//System.out.println("query string " + query);
//System.out.println("gen q: " + theQuery);

  analyzer.setExtractEntities(false);
  QueryParser qp = new QueryParser("contents", analyzer)
  try { return(qp.parse(queryString.toString()) ); }
  catch(ParseException pe) { }
 
  return(theQuery);
}
View Full Code Here

public Hits getHits(String str, boolean filter)
{
  Hits hits = null; bgramAnalyzer.setExtractEntities(false);
  try
  {
   QueryParser qp = new QueryParser("contents", bgramAnalyzer );
   if (filter) str = str.replaceAll("[^a-zA-Z0-9\"']", " ");
   query = qp.parse(str);
   logger.info("Query " + str + " is parsed to -->" + query + "<---");
   hits = is.search(query);
   setAlt( (sc != null) ? sc.didYouMean(query.toString("contents")): "");
  }
  catch (IOException ie) { logger.error("Problem with reading the Lucene index directory " + ie.getMessage()); }
View Full Code Here

      case CONTAINS_NOT: {
        Analyzer analyzer;
        synchronized (this) {
          analyzer = fIndexer.createAnalyzer();
        }
        QueryParser parser = new QueryParser(fieldname, analyzer);
        parser.setAllowLeadingWildcard(true);

        /* Prepare the value for parsing */
        value = prepareForParsing(value);

        /* Parse */
        return parser.parse(value);
      }

        /* Wildcard-Query with trailing '*' */
      case BEGINS_WITH: {
        value = new StringBuilder(value.toLowerCase()).append("*").toString();
 
View Full Code Here

        /* Let Query-Parser handle this */
      case CONTAINS:
      case CONTAINS_ALL:
      case CONTAINS_NOT: {
        QueryParser parser = new QueryParser(fieldname, analyzer);
        Operator operator = (specifier == SearchSpecifier.CONTAINS || specifier == SearchSpecifier.CONTAINS_NOT) ? QueryParser.OR_OPERATOR : QueryParser.AND_OPERATOR;
        parser.setDefaultOperator(operator);
        parser.setAllowLeadingWildcard(true);

        /* Prepare the value for parsing */
        value = prepareForParsing(value);

        /* Parse */
        return parser.parse(value);
      }

        /* Wildcard-Query with trailing '*' */
      case BEGINS_WITH: {
        value = value.toLowerCase() + "*"; //$NON-NLS-1$
View Full Code Here

      indexWriter = new IndexWriter(indexDirectory,
          new IndexWriterConfig(Version.LUCENE_31,
              new LimitTokenCountAnalyzer(analyzer,
                  Integer.MAX_VALUE))
              .setOpenMode(OpenMode.CREATE));
      queryParser = new QueryParser(Version.LUCENE_31, "text", analyzer);
      queryParser.setDefaultOperator(QueryParser.AND_OPERATOR);

      fulltext = new Field("text", "", Field.Store.NO,
          Field.Index.ANALYZED);
      fulltext.setOmitTermFreqAndPositions(true);
View Full Code Here

    return score.floatValue();
  }
 
  /** parses a Lucene query */
  private Query parse(String query, Analyzer analyzer) throws ParseException {
    QueryParser parser = new QueryParser(FIELD_NAME, analyzer);
    return parser.parse(query);
  }
View Full Code Here

      indexes[i].addField(field, lines.get(i).getValue(), textAnalyzer);
    }
    doc = null;   // help gc
    lines = null; // help gc
   
    Query query = new QueryParser(field, queryAnalyzer).parse(queryExpr);
   
    float sum = 0;
    for (int run=0; run < runs; run++) {
      System.out.println("\nrun=" + run);
      long start = System.currentTimeMillis();
View Full Code Here

      return ((MemoryIndex) index).getMemorySize();
    }
  }
 
  private Query parseQuery(String expression) throws ParseException {
    QueryParser parser = new QueryParser(FIELD_NAME, analyzer);
//    parser.setPhraseSlop(0);
    return parser.parse(expression);
  }
View Full Code Here

      {
         Map<String,Float> boostPerField = new HashMap<String,Float>();
         boostPerField.put( "title:en", 4f );
         boostPerField.put( "body:en", 1f );
         String[] productFields = {"title:en", "body:en"};
         QueryParser parser = new MultiFieldQueryParser(productFields, new StandardAnalyzer(), boostPerField);
         parser.setAllowLeadingWildcard(true);
         org.apache.lucene.search.Query luceneQuery;
         try
         {
            luceneQuery = parser.parse(searchPattern);
         }
         catch (ParseException e)
         {
            return null;
         }
View Full Code Here

TOP

Related Classes of org.apache.lucene.queryParser.QueryParser

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.