View Javadoc

    1   /*
    2    * This file is part of dependency-check-core.
    3    *
    4    * Dependency-check-core is free software: you can redistribute it and/or modify it
    5    * under the terms of the GNU General Public License as published by the Free
    6    * Software Foundation, either version 3 of the License, or (at your option) any
    7    * later version.
    8    *
    9    * Dependency-check-core is distributed in the hope that it will be useful, but
    10   * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    11   * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
    12   * details.
    13   *
    14   * You should have received a copy of the GNU General Public License along with
    15   * dependency-check-core. If not, see http://www.gnu.org/licenses/.
    16   *
    17   * Copyright (c) 2012 Jeremy Long. All Rights Reserved.
    18   */
    19  package org.owasp.dependencycheck.data.lucene;
    20
    21  import java.io.Reader;
    22  import org.apache.lucene.analysis.Analyzer;
    23  import org.apache.lucene.analysis.TokenStream;
    24  import org.apache.lucene.analysis.Tokenizer;
    25  import org.apache.lucene.analysis.core.LowerCaseFilter;
    26  import org.apache.lucene.analysis.core.WhitespaceTokenizer;
    27  import org.apache.lucene.util.Version;
    28
    29  /**
    30   * SearchVersionAnalyzer is a Lucene Analyzer used to analyze version
    31   * information.
    32   *
    33   * @author Jeremy Long (jeremy.long@owasp.org)
    34   * @deprecated version information is no longer stored in lucene
    35   */
    36  @Deprecated
    37  public class SearchVersionAnalyzer extends Analyzer {
    38      //TODO consider implementing payloads/custom attributes...
    39      // use custom attributes for major, minor, x, x, x, rcx
    40      // these can then be used to weight the score for searches on the version.
    41      // see http://lucene.apache.org/core/3_6_1/api/core/org/apache/lucene/analysis/package-summary.html#package_description
    42      // look at this article to implement
    43      // http://www.codewrecks.com/blog/index.php/2012/08/25/index-your-blog-using-tags-and-lucene-net/
    44
    45      /**
    46       * The Lucene Version used.
    47       */
    48      private final Version version;
    49
    50      /**
    51       * Creates a new SearchVersionAnalyzer.
    52       *
    53       * @param version the Lucene version
    54       */
    55      public SearchVersionAnalyzer(Version version) {
    56          this.version = version;
    57      }
    58
    59      /**
    60       * Creates the TokenStreamComponents
    61       *
    62       * @param fieldName the field name being analyzed
    63       * @param reader the reader containing the input
    64       * @return the TokenStreamComponents
    65       */
    66      @Override
    67      protected TokenStreamComponents createComponents(String fieldName, Reader reader) {
    68          final Tokenizer source = new WhitespaceTokenizer(version, reader);
    69          TokenStream stream = source;
    70          stream = new LowerCaseFilter(version, stream);
    71          stream = new VersionTokenizingFilter(stream);
    72          return new TokenStreamComponents(source, stream);
    73      }
    74  }