Ejemplo n.º 1
0
  /* (non-Javadoc)
   * @see com.limegroup.gnutella.gui.search.SearchResult#match(com.limegroup.gnutella.gui.search.AbstractSearchResult, org.limewire.collection.ApproximateMatcher)
   */
  public final int match(SearchResult sr, final ApproximateMatcher matcher) {

    if (!(sr instanceof AbstractSearchResult)) return 3;

    AbstractSearchResult o = (AbstractSearchResult) sr;

    // Same file type?
    if (!getExtension().equals(o.getExtension())) return 1;

    long thisSize = getSize();
    long thatSize = o.getSize();

    // Sizes same?
    if (thisSize != thatSize) return 2;

    // Preprocess the processed fileNames
    getProcessedFilename(matcher);
    o.getProcessedFilename(matcher);

    // Filenames close?  This is the most expensive test, so it should go
    // last.  Allow 5% edit difference in filenames or 4 characters,
    // whichever is smaller.
    int allowedDifferences =
        Math.round(
            Math.min(
                0.10f * (getFilenameNoExtension().length()),
                0.10f * (o.getFilenameNoExtension().length())));
    allowedDifferences = Math.min(allowedDifferences, 4);
    if (!matcher.matches(
        getProcessedFilename(matcher), o.getProcessedFilename(matcher), allowedDifferences))
      return 3;
    return 0;
  }
Ejemplo n.º 2
0
 /** Gets the processed filename. */
 private String getProcessedFilename(ApproximateMatcher matcher) {
   if (processedFilename != null) return processedFilename;
   processedFilename = matcher.process(getFilenameNoExtension());
   return processedFilename;
 }