You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by yo...@apache.org on 2010/10/16 15:48:51 UTC
svn commit: r1023283 - in
/lucene/dev/trunk/solr/src/java/org/apache/solr/spelling:
SpellCheckCollation.java SpellCheckCollator.java SpellCheckCorrection.java
Author: yonik
Date: Sat Oct 16 13:48:51 2010
New Revision: 1023283
URL: http://svn.apache.org/viewvc?rev=1023283&view=rev
Log:
formatting/indenting changes only
Modified:
lucene/dev/trunk/solr/src/java/org/apache/solr/spelling/SpellCheckCollation.java
lucene/dev/trunk/solr/src/java/org/apache/solr/spelling/SpellCheckCollator.java
lucene/dev/trunk/solr/src/java/org/apache/solr/spelling/SpellCheckCorrection.java
Modified: lucene/dev/trunk/solr/src/java/org/apache/solr/spelling/SpellCheckCollation.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/src/java/org/apache/solr/spelling/SpellCheckCollation.java?rev=1023283&r1=1023282&r2=1023283&view=diff
==============================================================================
--- lucene/dev/trunk/solr/src/java/org/apache/solr/spelling/SpellCheckCollation.java (original)
+++ lucene/dev/trunk/solr/src/java/org/apache/solr/spelling/SpellCheckCollation.java Sat Oct 16 13:48:51 2010
@@ -20,49 +20,49 @@ package org.apache.solr.spelling;
import org.apache.solr.common.util.NamedList;
public class SpellCheckCollation implements Comparable<SpellCheckCollation> {
- private NamedList<String> misspellingsAndCorrections;
- private int hits;
- private int internalRank;
- private String collationQuery;
-
- public int compareTo(SpellCheckCollation scc) {
- int c = new Integer(internalRank).compareTo(scc.internalRank);
- if (c == 0) {
- return collationQuery.compareTo(scc.collationQuery);
- }
- return c;
- }
-
- public NamedList<String> getMisspellingsAndCorrections() {
- return misspellingsAndCorrections;
- }
-
- public void setMisspellingsAndCorrections(
- NamedList<String> misspellingsAndCorrections) {
- this.misspellingsAndCorrections = misspellingsAndCorrections;
- }
-
- public int getHits() {
- return hits;
- }
-
- public void setHits(int hits) {
- this.hits = hits;
- }
-
- public String getCollationQuery() {
- return collationQuery;
- }
-
- public void setCollationQuery(String collationQuery) {
- this.collationQuery = collationQuery;
- }
-
- public int getInternalRank() {
- return internalRank;
- }
-
- public void setInternalRank(int internalRank) {
- this.internalRank = internalRank;
- }
+ private NamedList<String> misspellingsAndCorrections;
+ private int hits;
+ private int internalRank;
+ private String collationQuery;
+
+ public int compareTo(SpellCheckCollation scc) {
+ int c = new Integer(internalRank).compareTo(scc.internalRank);
+ if (c == 0) {
+ return collationQuery.compareTo(scc.collationQuery);
+ }
+ return c;
+ }
+
+ public NamedList<String> getMisspellingsAndCorrections() {
+ return misspellingsAndCorrections;
+ }
+
+ public void setMisspellingsAndCorrections(
+ NamedList<String> misspellingsAndCorrections) {
+ this.misspellingsAndCorrections = misspellingsAndCorrections;
+ }
+
+ public int getHits() {
+ return hits;
+ }
+
+ public void setHits(int hits) {
+ this.hits = hits;
+ }
+
+ public String getCollationQuery() {
+ return collationQuery;
+ }
+
+ public void setCollationQuery(String collationQuery) {
+ this.collationQuery = collationQuery;
+ }
+
+ public int getInternalRank() {
+ return internalRank;
+ }
+
+ public void setInternalRank(int internalRank) {
+ this.internalRank = internalRank;
+ }
}
Modified: lucene/dev/trunk/solr/src/java/org/apache/solr/spelling/SpellCheckCollator.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/src/java/org/apache/solr/spelling/SpellCheckCollator.java?rev=1023283&r1=1023282&r2=1023283&view=diff
==============================================================================
--- lucene/dev/trunk/solr/src/java/org/apache/solr/spelling/SpellCheckCollator.java (original)
+++ lucene/dev/trunk/solr/src/java/org/apache/solr/spelling/SpellCheckCollator.java Sat Oct 16 13:48:51 2010
@@ -36,107 +36,107 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class SpellCheckCollator {
- private static final Logger LOG = LoggerFactory.getLogger(SpellCheckCollator.class);
+ private static final Logger LOG = LoggerFactory.getLogger(SpellCheckCollator.class);
- public List<SpellCheckCollation> collate(SpellingResult result, String originalQuery, ResponseBuilder ultimateResponse,
- int maxCollations, int maxTries) {
- List<SpellCheckCollation> collations = new ArrayList<SpellCheckCollation>();
-
- QueryComponent queryComponent = null;
- if (ultimateResponse.components != null) {
- for (SearchComponent sc : ultimateResponse.components) {
- if (sc instanceof QueryComponent) {
- queryComponent = (QueryComponent) sc;
- break;
- }
- }
- }
-
- boolean verifyCandidateWithQuery = true;
- if (maxTries < 1) {
- maxTries = 1;
- verifyCandidateWithQuery = false;
- }
- if (queryComponent == null && verifyCandidateWithQuery) {
- LOG.warn("Could not find an instance of QueryComponent. Disabling collation verification against the index.");
- maxTries = 1;
- verifyCandidateWithQuery = false;
- }
-
- int tryNo = 0;
- int collNo = 0;
- PossibilityIterator possibilityIter = new PossibilityIterator(result.getSuggestions());
- while (tryNo < maxTries && collNo < maxCollations && possibilityIter.hasNext()) {
-
- RankedSpellPossibility possibility = possibilityIter.next();
- String collationQueryStr = getCollation(originalQuery, possibility.getCorrections());
- int hits = 0;
-
- if (verifyCandidateWithQuery) {
- tryNo++;
-
- ResponseBuilder checkResponse = new ResponseBuilder();
- checkResponse.setQparser(ultimateResponse.getQparser());
- checkResponse.setFilters(ultimateResponse.getFilters());
- checkResponse.setQueryString(collationQueryStr);
- checkResponse.components = Arrays.asList(new SearchComponent[] { queryComponent });
-
- ModifiableSolrParams params = new ModifiableSolrParams(ultimateResponse.req.getParams());
- params.remove(CommonParams.Q);
- params.add(CommonParams.Q, collationQueryStr);
- params.remove(CommonParams.START);
- params.remove(CommonParams.ROWS);
- params.add(CommonParams.FL, "id");
- params.add(CommonParams.ROWS, "0");
- //Would rather have found a concrete class to use...
- checkResponse.req = new SolrQueryRequestBase(ultimateResponse.req.getCore(), params) { };
- checkResponse.rsp = new SolrQueryResponse();
-
- try {
- queryComponent.prepare(checkResponse);
- queryComponent.process(checkResponse);
- hits = (Integer) checkResponse.rsp.getToLog().get("hits");
- } catch (Exception e) {
- Log.warn("Exception trying to re-query to check if a spell check possibility would return any hits.", e);
- }
- }
- if (hits > 0 || !verifyCandidateWithQuery) {
- collNo++;
- SpellCheckCollation collation = new SpellCheckCollation();
- collation.setCollationQuery(collationQueryStr);
- collation.setHits(hits);
- collation.setInternalRank(possibility.getRank());
-
- NamedList<String> misspellingsAndCorrections = new NamedList<String>();
- for (SpellCheckCorrection corr : possibility.getCorrections()) {
- misspellingsAndCorrections.add(corr.getOriginal().toString(), corr.getCorrection());
- }
- collation.setMisspellingsAndCorrections(misspellingsAndCorrections);
- collations.add(collation);
- }
- if (LOG.isDebugEnabled()) {
- LOG.debug("Collation: " + collationQueryStr + (verifyCandidateWithQuery ? (" will return " + hits + " hits.") : ""));
- }
- }
- return collations;
- }
-
- private String getCollation(String origQuery,
- List<SpellCheckCorrection> corrections) {
- StringBuilder collation = new StringBuilder(origQuery);
- int offset = 0;
- for (SpellCheckCorrection correction : corrections) {
- Token tok = correction.getOriginal();
- // we are replacing the query in order, but injected terms might cause
- // illegal offsets due to previous replacements.
- if (tok.getPositionIncrement() == 0)
- continue;
- collation.replace(tok.startOffset() + offset, tok.endOffset() + offset,
- correction.getCorrection());
- offset += correction.getCorrection().length()
- - (tok.endOffset() - tok.startOffset());
- }
- return collation.toString();
- }
+ public List<SpellCheckCollation> collate(SpellingResult result, String originalQuery, ResponseBuilder ultimateResponse,
+ int maxCollations, int maxTries) {
+ List<SpellCheckCollation> collations = new ArrayList<SpellCheckCollation>();
+
+ QueryComponent queryComponent = null;
+ if (ultimateResponse.components != null) {
+ for (SearchComponent sc : ultimateResponse.components) {
+ if (sc instanceof QueryComponent) {
+ queryComponent = (QueryComponent) sc;
+ break;
+ }
+ }
+ }
+
+ boolean verifyCandidateWithQuery = true;
+ if (maxTries < 1) {
+ maxTries = 1;
+ verifyCandidateWithQuery = false;
+ }
+ if (queryComponent == null && verifyCandidateWithQuery) {
+ LOG.warn("Could not find an instance of QueryComponent. Disabling collation verification against the index.");
+ maxTries = 1;
+ verifyCandidateWithQuery = false;
+ }
+
+ int tryNo = 0;
+ int collNo = 0;
+ PossibilityIterator possibilityIter = new PossibilityIterator(result.getSuggestions());
+ while (tryNo < maxTries && collNo < maxCollations && possibilityIter.hasNext()) {
+
+ RankedSpellPossibility possibility = possibilityIter.next();
+ String collationQueryStr = getCollation(originalQuery, possibility.getCorrections());
+ int hits = 0;
+
+ if (verifyCandidateWithQuery) {
+ tryNo++;
+
+ ResponseBuilder checkResponse = new ResponseBuilder();
+ checkResponse.setQparser(ultimateResponse.getQparser());
+ checkResponse.setFilters(ultimateResponse.getFilters());
+ checkResponse.setQueryString(collationQueryStr);
+ checkResponse.components = Arrays.asList(new SearchComponent[] { queryComponent });
+
+ ModifiableSolrParams params = new ModifiableSolrParams(ultimateResponse.req.getParams());
+ params.remove(CommonParams.Q);
+ params.add(CommonParams.Q, collationQueryStr);
+ params.remove(CommonParams.START);
+ params.remove(CommonParams.ROWS);
+ params.add(CommonParams.FL, "id");
+ params.add(CommonParams.ROWS, "0");
+ //Would rather have found a concrete class to use...
+ checkResponse.req = new SolrQueryRequestBase(ultimateResponse.req.getCore(), params) { };
+ checkResponse.rsp = new SolrQueryResponse();
+
+ try {
+ queryComponent.prepare(checkResponse);
+ queryComponent.process(checkResponse);
+ hits = (Integer) checkResponse.rsp.getToLog().get("hits");
+ } catch (Exception e) {
+ Log.warn("Exception trying to re-query to check if a spell check possibility would return any hits.", e);
+ }
+ }
+ if (hits > 0 || !verifyCandidateWithQuery) {
+ collNo++;
+ SpellCheckCollation collation = new SpellCheckCollation();
+ collation.setCollationQuery(collationQueryStr);
+ collation.setHits(hits);
+ collation.setInternalRank(possibility.getRank());
+
+ NamedList<String> misspellingsAndCorrections = new NamedList<String>();
+ for (SpellCheckCorrection corr : possibility.getCorrections()) {
+ misspellingsAndCorrections.add(corr.getOriginal().toString(), corr.getCorrection());
+ }
+ collation.setMisspellingsAndCorrections(misspellingsAndCorrections);
+ collations.add(collation);
+ }
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Collation: " + collationQueryStr + (verifyCandidateWithQuery ? (" will return " + hits + " hits.") : ""));
+ }
+ }
+ return collations;
+ }
+
+ private String getCollation(String origQuery,
+ List<SpellCheckCorrection> corrections) {
+ StringBuilder collation = new StringBuilder(origQuery);
+ int offset = 0;
+ for (SpellCheckCorrection correction : corrections) {
+ Token tok = correction.getOriginal();
+ // we are replacing the query in order, but injected terms might cause
+ // illegal offsets due to previous replacements.
+ if (tok.getPositionIncrement() == 0)
+ continue;
+ collation.replace(tok.startOffset() + offset, tok.endOffset() + offset,
+ correction.getCorrection());
+ offset += correction.getCorrection().length()
+ - (tok.endOffset() - tok.startOffset());
+ }
+ return collation.toString();
+ }
}
Modified: lucene/dev/trunk/solr/src/java/org/apache/solr/spelling/SpellCheckCorrection.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/src/java/org/apache/solr/spelling/SpellCheckCorrection.java?rev=1023283&r1=1023282&r2=1023283&view=diff
==============================================================================
--- lucene/dev/trunk/solr/src/java/org/apache/solr/spelling/SpellCheckCorrection.java (original)
+++ lucene/dev/trunk/solr/src/java/org/apache/solr/spelling/SpellCheckCorrection.java Sat Oct 16 13:48:51 2010
@@ -19,32 +19,32 @@ package org.apache.solr.spelling;
import org.apache.lucene.analysis.Token;
public class SpellCheckCorrection {
- private Token original;
- private String correction;
- private int numberOfOccurences;
-
- public Token getOriginal() {
- return original;
- }
-
- public void setOriginal(Token original) {
- this.original = original;
- }
-
- public String getCorrection() {
- return correction;
- }
-
- public void setCorrection(String correction) {
- this.correction = correction;
- }
-
- public int getNumberOfOccurences() {
- return numberOfOccurences;
- }
-
- public void setNumberOfOccurences(int numberOfOccurences) {
- this.numberOfOccurences = numberOfOccurences;
- }
+ private Token original;
+ private String correction;
+ private int numberOfOccurences;
+
+ public Token getOriginal() {
+ return original;
+ }
+
+ public void setOriginal(Token original) {
+ this.original = original;
+ }
+
+ public String getCorrection() {
+ return correction;
+ }
+
+ public void setCorrection(String correction) {
+ this.correction = correction;
+ }
+
+ public int getNumberOfOccurences() {
+ return numberOfOccurences;
+ }
+
+ public void setNumberOfOccurences(int numberOfOccurences) {
+ this.numberOfOccurences = numberOfOccurences;
+ }
}