Skip to content

Commit

Permalink
move sub-query parsing logic to superclass, may be a partial fix (may…
Browse files Browse the repository at this point in the history
…be) for #5
  • Loading branch information
nolanlawson committed Feb 17, 2013
1 parent 2f7101e commit 2460ab6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 29 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.healthonnet.lucene</groupId>
<artifactId>hon-lucene-synonyms</artifactId>
<version>1.2.1-solr-4.1.0</version>
<version>1.2.2-solr-4.1.0</version>
<dependencies>
<dependency>
<groupId>org.apache.solr</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -490,47 +490,27 @@ private List<String> buildUpAlternateQueries(List<List<TextInQuery>> textsInQuer
* @return
*/
private List<Query> createSynonymQueries(SolrParams solrParams, List<String> alternateQueryTexts) {

//
// begin copied code from ExtendedDismaxQParser
//

// have to build up the queryFields again because in Solr 3.6.1 they made it private.
Map<String,Float> queryFields = SolrPluginUtils.parseFieldBoosts(solrParams.getParams(DisMaxParams.QF));
if (0 == queryFields.size()) {
queryFields.put(req.getSchema().getDefaultSearchFieldName(), 1.0f);
}

if (queryFields.keySet().iterator().next() == null) {
throw new RuntimeException("'qf' is null and there's no 'defaultSearchField' in schema.xml. " +
"Synonyms cannot be generated in these conditions! " +
"Please either add 'qf', or add 'defaultSearchField'");
}

float tiebreaker = solrParams.getFloat(DisMaxParams.TIE, 0.0f);
int qslop = solrParams.getInt(DisMaxParams.QS, 0);
ExtendedSolrQueryParser up = new ExtendedSolrQueryParser(this,
Const.IMPOSSIBLE_FIELD_NAME);
up.addAlias(Const.IMPOSSIBLE_FIELD_NAME, tiebreaker, queryFields);
up.setPhraseSlop(qslop); // slop for explicit user phrase queries
up.setAllowLeadingWildcard(true);
//
// end copied code
//
String originalString = getString();
String nullsafeOriginalString = getQueryStringFromParser();

List<Query> result = new ArrayList<Query>();
for (String alternateQueryText : alternateQueryTexts) {
if (alternateQueryText.equals(getQueryStringFromParser())) { // alternate query is the same as what the user entered
if (alternateQueryText.equalsIgnoreCase(nullsafeOriginalString)) {
// alternate query is the same as what the user entered
continue;
}
super.setString(alternateQueryText);
try {
result.add(up.parse(alternateQueryText));
result.add(super.parse());
} catch (SyntaxError e) {
// TODO: better error handling - for now just bail out; ignore this synonym
e.printStackTrace(System.err);
}
}

super.setString(originalString); // cover our tracks

return result;
}

Expand Down

0 comments on commit 2460ab6

Please sign in to comment.