Package org.apache.lucene.index

Examples of org.apache.lucene.index.Term


   //*-- clean up the Lucene index
   FSDirectory fsd = FSDirectory.getDirectory(new File(Constants.getINDEXDIR()), false);
   IndexReader ir = IndexReader.open(fsd);
   for (int i = 0; i < delFiles.size(); i++)
    ir.deleteDocuments(new Term("key", (String) delFiles.get(i)) );
   ir.close();
  }
  catch (DatabaseException dbe)
  { logger.error("Could not open cursor to browse File index" + dbe.getMessage() ); }
  catch (UnsupportedEncodingException ue)
View Full Code Here


        if (newsDoc.addFields()) {
          docCount++;

          /* Update Event */
          if (isUpdate) {
            Term term = createTerm(news);
            fIndexWriter.updateDocument(term, newsDoc.getDocument());
          }

          /* Added Event */
          else
View Full Code Here

    /* For each entity */
    for (ListIterator<INews> it = entities.listIterator(entities.size()); it.hasPrevious();) {
      INews news = it.previous();
      it.remove();
      Term term = createTerm(news);
      fIndexWriter.deleteDocuments(term);
      docCount++;
    }

    /* Mark as in need for a flush */
 
View Full Code Here

    return indexWriter;
  }

  private Term createTerm(IEntity entity) {
    String value = String.valueOf(entity.getId());
    return new Term(SearchDocument.ENTITY_ID_TEXT, value);
  }
View Full Code Here

    String fieldName = String.valueOf(INews.STATE);
    Occur occur = condition.getSpecifier().isNegation() ? Occur.MUST_NOT : Occur.SHOULD;
    EnumSet<INews.State> newsStates = (EnumSet<State>) condition.getValue();
    for (INews.State state : newsStates) {
      String value = String.valueOf(state.ordinal());
      TermQuery stateQuery = new TermQuery(new Term(fieldName, value));
      statesQuery.add(new BooleanClause(stateQuery, occur));
    }

    /* Check if the match-all-docs query is required */
    if (newsStates.size() == 1 && condition.getSpecifier().isNegation())
View Full Code Here

    Token token = null;
    while ((token = tokenStream.next()) != null) {
      String termText = token.termText();

      /* Contained in Title */
      WildcardQuery titleQuery = new WildcardQuery(new Term(String.valueOf(INews.TITLE), termText));
      allFieldsQuery.add(new BooleanClause(titleQuery, Occur.SHOULD));

      /* Contained in Description */
      WildcardQuery descriptionQuery = new WildcardQuery(new Term(String.valueOf(INews.DESCRIPTION), termText));
      allFieldsQuery.add(new BooleanClause(descriptionQuery, Occur.SHOULD));

      /* Contained in Attachment */
      WildcardQuery attachmentQuery = new WildcardQuery(new Term(String.valueOf(INews.ATTACHMENTS_CONTENT), termText));
      allFieldsQuery.add(new BooleanClause(attachmentQuery, Occur.SHOULD));

      /* Matches Author */
      WildcardQuery authorQuery = new WildcardQuery(new Term(String.valueOf(INews.AUTHOR), termText));
      allFieldsQuery.add(new BooleanClause(authorQuery, Occur.SHOULD));

      /* Matches Category */
      WildcardQuery categoryQuery = new WildcardQuery(new Term(String.valueOf(INews.CATEGORIES), termText));
      allFieldsQuery.add(new BooleanClause(categoryQuery, Occur.SHOULD));
    }

    /* Determine Occur (MUST, SHOULD, MUST NOT) */
    Occur occur = getOccur(condition.getSpecifier(), matchAllConditions);
View Full Code Here

    cal.setTimeInMillis(System.currentTimeMillis() - age * DAY);
    String value = DateTools.dateToString(cal.getTime(), Resolution.DAY);

    switch (condition.getSpecifier()) {
      case IS: {
        return new TermQuery(new Term(fieldname, value));
      }

      case IS_GREATER_THAN: {
        Term lowerBound = new Term(fieldname, MIN_DATE);
        Term upperBound = new Term(fieldname, value);

        return new ConstantScoreRangeQuery(fieldname, lowerBound.text(), upperBound.text(), false, false);
      }

      case IS_LESS_THAN: {
        Term lowerBound = new Term(fieldname, value);
        Term upperBound = new Term(fieldname, MAX_DATE);

        return new ConstantScoreRangeQuery(fieldname, lowerBound.text(), upperBound.text(), false, false);
      }
    }

    throw new UnsupportedOperationException("Unsupported Specifier for Age Query");
  }
View Full Code Here

    switch (specifier) {

      /* Create Wildcard-Query */
      case IS:
      case IS_NOT: {
        Term term = new Term(fieldname, value.toLowerCase());
        return new WildcardQuery(term);
      }

        /* Let Query-Parser handle this */
      case CONTAINS:
      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();
        Term term = new Term(fieldname, value);
        WildcardQuery query = new WildcardQuery(term);
        return query;
      }

        /* Wildcard-Query with leading '*' */
      case ENDS_WITH: {
        value = new StringBuilder("*").append(value.toLowerCase()).toString();
        Term term = new Term(fieldname, value);
        return new WildcardQuery(term);
      }

        /* Fuzzy Query */
      case SIMILIAR_TO: {
        BooleanQuery similarityQuery = new BooleanQuery();

        LowercaseWhitespaceAnalyzer analyzer = new LowercaseWhitespaceAnalyzer();
        TokenStream tokenStream = analyzer.tokenStream(String.valueOf(IEntity.ALL_FIELDS), new StringReader(value));
        Token token = null;
        while ((token = tokenStream.next()) != null) {
          Term term = new Term(fieldname, token.termText());
          similarityQuery.add(new BooleanClause(new FuzzyQuery(term), Occur.MUST));
        }

        return similarityQuery;
      }
View Full Code Here

    else
      value = String.valueOf(condition.getValue());

    String fieldname = String.valueOf(condition.getField().getId());

    Term term = new Term(fieldname, value);
    return new TermQuery(term);
  }
View Full Code Here

    String fieldname = String.valueOf(condition.getField().getId());

    switch (specifier) {
      case IS:
      case IS_NOT:
        return new TermQuery(new Term(fieldname, value));

      case IS_AFTER: {
        Term lowerBound = new Term(fieldname, value);
        Term upperBound = new Term(fieldname, MAX_DATE);

        return new ConstantScoreRangeQuery(fieldname, lowerBound.text(), upperBound.text(), false, false);
      }

      case IS_BEFORE: {
        Term lowerBound = new Term(fieldname, MIN_DATE);
        Term upperBound = new Term(fieldname, value);

        return new ConstantScoreRangeQuery(fieldname, lowerBound.text(), upperBound.text(), false, false);
      }
    }

    throw new UnsupportedOperationException("Unsupported Specifier for Date/Time Queries");
  }
View Full Code Here

TOP

Related Classes of org.apache.lucene.index.Term

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.