You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ds...@apache.org on 2016/11/17 16:25:45 UTC
[2/2] lucene-solr:branch_6x: LUCENE-7559: fix indentation of entire
file
LUCENE-7559: fix indentation of entire file
(cherry picked from commit cbc8392)
Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/06ee34c6
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/06ee34c6
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/06ee34c6
Branch: refs/heads/branch_6x
Commit: 06ee34c68225fd904b8909af44173574890d881e
Parents: 23b8bb6
Author: David Smiley <ds...@apache.org>
Authored: Thu Nov 17 11:23:40 2016 -0500
Committer: David Smiley <ds...@apache.org>
Committed: Thu Nov 17 11:25:36 2016 -0500
----------------------------------------------------------------------
.../uhighlight/DefaultPassageFormatter.java | 204 ++++++-------
.../lucene/search/uhighlight/Passage.java | 292 ++++++++++---------
2 files changed, 250 insertions(+), 246 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/06ee34c6/lucene/highlighter/src/java/org/apache/lucene/search/uhighlight/DefaultPassageFormatter.java
----------------------------------------------------------------------
diff --git a/lucene/highlighter/src/java/org/apache/lucene/search/uhighlight/DefaultPassageFormatter.java b/lucene/highlighter/src/java/org/apache/lucene/search/uhighlight/DefaultPassageFormatter.java
index bc27a43..62d58df 100644
--- a/lucene/highlighter/src/java/org/apache/lucene/search/uhighlight/DefaultPassageFormatter.java
+++ b/lucene/highlighter/src/java/org/apache/lucene/search/uhighlight/DefaultPassageFormatter.java
@@ -24,115 +24,117 @@ package org.apache.lucene.search.uhighlight;
* ellipses between unconnected passages.
*/
public class DefaultPassageFormatter extends PassageFormatter {
- /** text that will appear before highlighted terms */
- protected final String preTag;
- /** text that will appear after highlighted terms */
- protected final String postTag;
- /** text that will appear between two unconnected passages */
- protected final String ellipsis;
- /** true if we should escape for html */
- protected final boolean escape;
+ /** text that will appear before highlighted terms */
+ protected final String preTag;
+ /** text that will appear after highlighted terms */
+ protected final String postTag;
+ /** text that will appear between two unconnected passages */
+ protected final String ellipsis;
+ /** true if we should escape for html */
+ protected final boolean escape;
- /**
- * Creates a new DefaultPassageFormatter with the default tags.
- */
- public DefaultPassageFormatter() {
- this("<b>", "</b>", "... ", false);
- }
+ /**
+ * Creates a new DefaultPassageFormatter with the default tags.
+ */
+ public DefaultPassageFormatter() {
+ this("<b>", "</b>", "... ", false);
+ }
- /**
- * Creates a new DefaultPassageFormatter with custom tags.
- * @param preTag text which should appear before a highlighted term.
- * @param postTag text which should appear after a highlighted term.
- * @param ellipsis text which should be used to connect two unconnected passages.
- * @param escape true if text should be html-escaped
- */
- public DefaultPassageFormatter(String preTag, String postTag, String ellipsis, boolean escape) {
- if (preTag == null || postTag == null || ellipsis == null) {
- throw new NullPointerException();
- }
- this.preTag = preTag;
- this.postTag = postTag;
- this.ellipsis = ellipsis;
- this.escape = escape;
+ /**
+ * Creates a new DefaultPassageFormatter with custom tags.
+ *
+ * @param preTag text which should appear before a highlighted term.
+ * @param postTag text which should appear after a highlighted term.
+ * @param ellipsis text which should be used to connect two unconnected passages.
+ * @param escape true if text should be html-escaped
+ */
+ public DefaultPassageFormatter(String preTag, String postTag, String ellipsis, boolean escape) {
+ if (preTag == null || postTag == null || ellipsis == null) {
+ throw new NullPointerException();
}
+ this.preTag = preTag;
+ this.postTag = postTag;
+ this.ellipsis = ellipsis;
+ this.escape = escape;
+ }
- @Override
- public String format(Passage passages[], String content) {
- StringBuilder sb = new StringBuilder();
- int pos = 0;
- for (Passage passage : passages) {
- // don't add ellipsis if its the first one, or if its connected.
- if (passage.getStartOffset() > pos && pos > 0) {
- sb.append(ellipsis);
- }
- pos = passage.getStartOffset();
- for (int i = 0; i < passage.getNumMatches(); i++) {
- int start = passage.getMatchStarts()[i];
- int end = passage.getMatchEnds()[i];
- // its possible to have overlapping terms
- if (start > pos) {
- append(sb, content, pos, start);
- }
- if (end > pos) {
- sb.append(preTag);
- append(sb, content, Math.max(pos, start), end);
- sb.append(postTag);
- pos = end;
- }
- }
- // its possible a "term" from the analyzer could span a sentence boundary.
- append(sb, content, pos, Math.max(pos, passage.getEndOffset()));
- pos = passage.getEndOffset();
+ @Override
+ public String format(Passage passages[], String content) {
+ StringBuilder sb = new StringBuilder();
+ int pos = 0;
+ for (Passage passage : passages) {
+ // don't add ellipsis if its the first one, or if its connected.
+ if (passage.getStartOffset() > pos && pos > 0) {
+ sb.append(ellipsis);
+ }
+ pos = passage.getStartOffset();
+ for (int i = 0; i < passage.getNumMatches(); i++) {
+ int start = passage.getMatchStarts()[i];
+ int end = passage.getMatchEnds()[i];
+ // its possible to have overlapping terms
+ if (start > pos) {
+ append(sb, content, pos, start);
+ }
+ if (end > pos) {
+ sb.append(preTag);
+ append(sb, content, Math.max(pos, start), end);
+ sb.append(postTag);
+ pos = end;
}
- return sb.toString();
+ }
+ // its possible a "term" from the analyzer could span a sentence boundary.
+ append(sb, content, pos, Math.max(pos, passage.getEndOffset()));
+ pos = passage.getEndOffset();
}
+ return sb.toString();
+ }
- /**
- * Appends original text to the response.
- * @param dest resulting text, possibly transformed or encoded
- * @param content original text content
- * @param start index of the first character in content
- * @param end index of the character following the last character in content
- */
- protected void append(StringBuilder dest, String content, int start, int end) {
- if (escape) {
- // note: these are the rules from owasp.org
- for (int i = start; i < end; i++) {
- char ch = content.charAt(i);
- switch(ch) {
- case '&':
- dest.append("&");
- break;
- case '<':
- dest.append("<");
- break;
- case '>':
- dest.append(">");
- break;
- case '"':
- dest.append(""");
- break;
- case '\'':
- dest.append("'");
- break;
- case '/':
- dest.append("/");
- break;
- default:
- if (ch >= 0x30 && ch <= 0x39 || ch >= 0x41 && ch <= 0x5A || ch >= 0x61 && ch <= 0x7A) {
- dest.append(ch);
- } else if (ch < 0xff) {
- dest.append("&#");
- dest.append((int)ch);
- dest.append(";");
- } else {
- dest.append(ch);
- }
- }
+ /**
+ * Appends original text to the response.
+ *
+ * @param dest resulting text, possibly transformed or encoded
+ * @param content original text content
+ * @param start index of the first character in content
+ * @param end index of the character following the last character in content
+ */
+ protected void append(StringBuilder dest, String content, int start, int end) {
+ if (escape) {
+ // note: these are the rules from owasp.org
+ for (int i = start; i < end; i++) {
+ char ch = content.charAt(i);
+ switch (ch) {
+ case '&':
+ dest.append("&");
+ break;
+ case '<':
+ dest.append("<");
+ break;
+ case '>':
+ dest.append(">");
+ break;
+ case '"':
+ dest.append(""");
+ break;
+ case '\'':
+ dest.append("'");
+ break;
+ case '/':
+ dest.append("/");
+ break;
+ default:
+ if (ch >= 0x30 && ch <= 0x39 || ch >= 0x41 && ch <= 0x5A || ch >= 0x61 && ch <= 0x7A) {
+ dest.append(ch);
+ } else if (ch < 0xff) {
+ dest.append("&#");
+ dest.append((int) ch);
+ dest.append(";");
+ } else {
+ dest.append(ch);
}
- } else {
- dest.append(content, start, end);
}
+ }
+ } else {
+ dest.append(content, start, end);
}
+ }
}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/06ee34c6/lucene/highlighter/src/java/org/apache/lucene/search/uhighlight/Passage.java
----------------------------------------------------------------------
diff --git a/lucene/highlighter/src/java/org/apache/lucene/search/uhighlight/Passage.java b/lucene/highlighter/src/java/org/apache/lucene/search/uhighlight/Passage.java
index a131d86..d64b96e 100644
--- a/lucene/highlighter/src/java/org/apache/lucene/search/uhighlight/Passage.java
+++ b/lucene/highlighter/src/java/org/apache/lucene/search/uhighlight/Passage.java
@@ -23,7 +23,7 @@ import org.apache.lucene.util.InPlaceMergeSorter;
import org.apache.lucene.util.RamUsageEstimator;
/**
- * Represents a passage (typically a sentence of the document).
+ * Represents a passage (typically a sentence of the document).
* <p>
* A passage contains {@link #getNumMatches} highlights from the query,
* and the offsets and query terms that correspond with each match.
@@ -31,149 +31,151 @@ import org.apache.lucene.util.RamUsageEstimator;
* @lucene.experimental
*/
public class Passage {
- private int startOffset = -1;
- private int endOffset = -1;
- private float score = 0.0f;
-
- private int[] matchStarts = new int[8];
- private int[] matchEnds = new int[8];
- private BytesRef[] matchTerms = new BytesRef[8];
- private int numMatches = 0;
-
- /** @lucene.internal */
- public void addMatch(int startOffset, int endOffset, BytesRef term) {
- assert startOffset >= this.startOffset && startOffset <= this.endOffset;
- if (numMatches == matchStarts.length) {
- int newLength = ArrayUtil.oversize(numMatches+1, RamUsageEstimator.NUM_BYTES_OBJECT_REF);
- int newMatchStarts[] = new int[newLength];
- int newMatchEnds[] = new int[newLength];
- BytesRef newMatchTerms[] = new BytesRef[newLength];
- System.arraycopy(matchStarts, 0, newMatchStarts, 0, numMatches);
- System.arraycopy(matchEnds, 0, newMatchEnds, 0, numMatches);
- System.arraycopy(matchTerms, 0, newMatchTerms, 0, numMatches);
- matchStarts = newMatchStarts;
- matchEnds = newMatchEnds;
- matchTerms = newMatchTerms;
- }
- assert matchStarts.length == matchEnds.length && matchEnds.length == matchTerms.length;
- matchStarts[numMatches] = startOffset;
- matchEnds[numMatches] = endOffset;
- matchTerms[numMatches] = term;
- numMatches++;
- }
-
- /** @lucene.internal */
- public void sort() {
- final int starts[] = matchStarts;
- final int ends[] = matchEnds;
- final BytesRef terms[] = matchTerms;
- new InPlaceMergeSorter() {
- @Override
- protected void swap(int i, int j) {
- int temp = starts[i];
- starts[i] = starts[j];
- starts[j] = temp;
-
- temp = ends[i];
- ends[i] = ends[j];
- ends[j] = temp;
-
- BytesRef tempTerm = terms[i];
- terms[i] = terms[j];
- terms[j] = tempTerm;
- }
-
- @Override
- protected int compare(int i, int j) {
- return Integer.compare(starts[i], starts[j]);
- }
-
- }.sort(0, numMatches);
- }
-
- /** @lucene.internal */
- public void reset() {
- startOffset = endOffset = -1;
- score = 0.0f;
- numMatches = 0;
- }
-
- /**
- * Start offset of this passage.
- * @return start index (inclusive) of the passage in the
- * original content: always >= 0.
- */
- public int getStartOffset() {
- return startOffset;
- }
-
- /**
- * End offset of this passage.
- * @return end index (exclusive) of the passage in the
- * original content: always >= {@link #getStartOffset()}
- */
- public int getEndOffset() {
- return endOffset;
- }
-
- /**
- * Passage's score.
- */
- public float getScore() {
- return score;
- }
-
- /**
- * Number of term matches available in
- * {@link #getMatchStarts}, {@link #getMatchEnds},
- * {@link #getMatchTerms}
- */
- public int getNumMatches() {
- return numMatches;
- }
-
- /**
- * Start offsets of the term matches, in increasing order.
- * <p>
- * Only {@link #getNumMatches} are valid. Note that these
- * offsets are absolute (not relative to {@link #getStartOffset()}).
- */
- public int[] getMatchStarts() {
- return matchStarts;
- }
-
- /**
- * End offsets of the term matches, corresponding with {@link #getMatchStarts}.
- * <p>
- * Only {@link #getNumMatches} are valid. Note that its possible that an end offset
- * could exceed beyond the bounds of the passage ({@link #getEndOffset()}), if the
- * Analyzer produced a term which spans a passage boundary.
- */
- public int[] getMatchEnds() {
- return matchEnds;
- }
-
- /**
- * BytesRef (term text) of the matches, corresponding with {@link #getMatchStarts()}.
- * <p>
- * Only {@link #getNumMatches()} are valid.
- */
- public BytesRef[] getMatchTerms() {
- return matchTerms;
- }
-
- /** @lucene.internal */
- public void setStartOffset(int startOffset) {
- this.startOffset = startOffset;
- }
-
- /** @lucene.internal */
- public void setEndOffset(int endOffset) {
- this.endOffset = endOffset;
- }
-
- /** @lucene.internal */
- public void setScore(float score) {
- this.score = score;
+ private int startOffset = -1;
+ private int endOffset = -1;
+ private float score = 0.0f;
+
+ private int[] matchStarts = new int[8];
+ private int[] matchEnds = new int[8];
+ private BytesRef[] matchTerms = new BytesRef[8];
+ private int numMatches = 0;
+
+ /** @lucene.internal */
+ public void addMatch(int startOffset, int endOffset, BytesRef term) {
+ assert startOffset >= this.startOffset && startOffset <= this.endOffset;
+ if (numMatches == matchStarts.length) {
+ int newLength = ArrayUtil.oversize(numMatches + 1, RamUsageEstimator.NUM_BYTES_OBJECT_REF);
+ int newMatchStarts[] = new int[newLength];
+ int newMatchEnds[] = new int[newLength];
+ BytesRef newMatchTerms[] = new BytesRef[newLength];
+ System.arraycopy(matchStarts, 0, newMatchStarts, 0, numMatches);
+ System.arraycopy(matchEnds, 0, newMatchEnds, 0, numMatches);
+ System.arraycopy(matchTerms, 0, newMatchTerms, 0, numMatches);
+ matchStarts = newMatchStarts;
+ matchEnds = newMatchEnds;
+ matchTerms = newMatchTerms;
}
+ assert matchStarts.length == matchEnds.length && matchEnds.length == matchTerms.length;
+ matchStarts[numMatches] = startOffset;
+ matchEnds[numMatches] = endOffset;
+ matchTerms[numMatches] = term;
+ numMatches++;
+ }
+
+ /** @lucene.internal */
+ public void sort() {
+ final int starts[] = matchStarts;
+ final int ends[] = matchEnds;
+ final BytesRef terms[] = matchTerms;
+ new InPlaceMergeSorter() {
+ @Override
+ protected void swap(int i, int j) {
+ int temp = starts[i];
+ starts[i] = starts[j];
+ starts[j] = temp;
+
+ temp = ends[i];
+ ends[i] = ends[j];
+ ends[j] = temp;
+
+ BytesRef tempTerm = terms[i];
+ terms[i] = terms[j];
+ terms[j] = tempTerm;
+ }
+
+ @Override
+ protected int compare(int i, int j) {
+ return Integer.compare(starts[i], starts[j]);
+ }
+
+ }.sort(0, numMatches);
+ }
+
+ /** @lucene.internal */
+ public void reset() {
+ startOffset = endOffset = -1;
+ score = 0.0f;
+ numMatches = 0;
+ }
+
+ /**
+ * Start offset of this passage.
+ *
+ * @return start index (inclusive) of the passage in the
+ * original content: always >= 0.
+ */
+ public int getStartOffset() {
+ return startOffset;
+ }
+
+ /**
+ * End offset of this passage.
+ *
+ * @return end index (exclusive) of the passage in the
+ * original content: always >= {@link #getStartOffset()}
+ */
+ public int getEndOffset() {
+ return endOffset;
+ }
+
+ /**
+ * Passage's score.
+ */
+ public float getScore() {
+ return score;
+ }
+
+ /**
+ * Number of term matches available in
+ * {@link #getMatchStarts}, {@link #getMatchEnds},
+ * {@link #getMatchTerms}
+ */
+ public int getNumMatches() {
+ return numMatches;
+ }
+
+ /**
+ * Start offsets of the term matches, in increasing order.
+ * <p>
+ * Only {@link #getNumMatches} are valid. Note that these
+ * offsets are absolute (not relative to {@link #getStartOffset()}).
+ */
+ public int[] getMatchStarts() {
+ return matchStarts;
+ }
+
+ /**
+ * End offsets of the term matches, corresponding with {@link #getMatchStarts}.
+ * <p>
+ * Only {@link #getNumMatches} are valid. Note that its possible that an end offset
+ * could exceed beyond the bounds of the passage ({@link #getEndOffset()}), if the
+ * Analyzer produced a term which spans a passage boundary.
+ */
+ public int[] getMatchEnds() {
+ return matchEnds;
+ }
+
+ /**
+ * BytesRef (term text) of the matches, corresponding with {@link #getMatchStarts()}.
+ * <p>
+ * Only {@link #getNumMatches()} are valid.
+ */
+ public BytesRef[] getMatchTerms() {
+ return matchTerms;
+ }
+
+ /** @lucene.internal */
+ public void setStartOffset(int startOffset) {
+ this.startOffset = startOffset;
+ }
+
+ /** @lucene.internal */
+ public void setEndOffset(int endOffset) {
+ this.endOffset = endOffset;
+ }
+
+ /** @lucene.internal */
+ public void setScore(float score) {
+ this.score = score;
+ }
}