From 2460ab61fcea917c591bdf05f3d3003078c34269 Mon Sep 17 00:00:00 2001 From: Nolan Lawson Date: Sun, 17 Feb 2013 17:24:49 +0100 Subject: [PATCH] move sub-query parsing logic to superclass, may be a partial fix (maybe) for #5 --- pom.xml | 2 +- ...mExpandingExtendedDismaxQParserPlugin.java | 36 +++++-------------- 2 files changed, 9 insertions(+), 29 deletions(-) diff --git a/pom.xml b/pom.xml index 783698b..90ad1e9 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 org.healthonnet.lucene hon-lucene-synonyms - 1.2.1-solr-4.1.0 + 1.2.2-solr-4.1.0 org.apache.solr diff --git a/src/main/java/org/apache/solr/search/SynonymExpandingExtendedDismaxQParserPlugin.java b/src/main/java/org/apache/solr/search/SynonymExpandingExtendedDismaxQParserPlugin.java index cd94d43..084621f 100644 --- a/src/main/java/org/apache/solr/search/SynonymExpandingExtendedDismaxQParserPlugin.java +++ b/src/main/java/org/apache/solr/search/SynonymExpandingExtendedDismaxQParserPlugin.java @@ -490,47 +490,27 @@ private List buildUpAlternateQueries(List> textsInQuer * @return */ private List createSynonymQueries(SolrParams solrParams, List alternateQueryTexts) { - - // - // begin copied code from ExtendedDismaxQParser - // - - // have to build up the queryFields again because in Solr 3.6.1 they made it private. - Map 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 result = new ArrayList(); 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; }