@Test public void queryIsUnmodifiedWhenLanguageIsNotSupported() throws ComponentLookupException { LocalizationContext ctx = this.mocker.getInstance(LocalizationContext.class); when(ctx.getCurrentLocale()).thenReturn(Locale.forLanguageTag("fr")); SolrQuery query = new SolrQuery(); query.set(DisMaxParams.PF, "name^20 nameSpell^36 nameExact^100 namePrefix^30 " + "synonym^15 synonymSpell^25 synonymExact^70 synonymPrefix^20 " + "text^3 textSpell^5"); query.set(DisMaxParams.QF, "name^10 nameSpell^18 nameStub^5 synonym^6 synonymSpell^10 synonymStub^3 text^1 textSpell^2 textStub^0.5"); this.extension.extendQuery(query, this.vocabularyInstance); Assert.assertEquals("name^20 nameSpell^36 nameExact^100 namePrefix^30 " + "synonym^15 synonymSpell^25 synonymExact^70 synonymPrefix^20 " + "text^3 textSpell^5", query.get(DisMaxParams.PF)); Assert.assertEquals( "name^10 nameSpell^18 nameStub^5 synonym^6 synonymSpell^10 synonymStub^3 text^1 textSpell^2 textStub^0.5", query.get(DisMaxParams.QF)); }
@Override public void extendQuery(SolrQuery query, Vocabulary vocabulary) { if (!isCurrentLocaleTargeted()) { return; } Locale targetLocale = getTargetLocale(); if (StringUtils.isNotBlank(query.get(DisMaxParams.PF))) { try (Formatter f = new Formatter()) { f.out().append(query.get(DisMaxParams.PF)); f.format(" name_%1$s^60 synonym_%1$s^45 def_%1$s^12 ", targetLocale); query.set(DisMaxParams.PF, f.toString()); } catch (IOException ex) { this.logger.warn( "Unexpected exception while formatting SolrQuery PF for vocabulary [{}] and locale [{}]: {}", vocabulary.getIdentifier(), targetLocale, ex.getMessage()); } } if (StringUtils.isNotBlank(query.get(DisMaxParams.QF))) { try (Formatter f = new Formatter()) { f.out().append(query.get(DisMaxParams.QF)); f.format(" name_%1$s^30 synonym_%1$s^21 def_%1$s^6 ", targetLocale); query.set(DisMaxParams.QF, f.toString()); } catch (IOException ex) { this.logger.warn( "Unexpected exception while formatting SolrQuery QF for vocabulary [{}] and locale [{}]: {}", vocabulary.getIdentifier(), targetLocale, ex.getMessage()); } } }
AbstractXliffTranslatedVocabularyExtension implements VocabularyExtension { @Override public void extendQuery(SolrQuery query, Vocabulary vocabulary) { if (!isCurrentLocaleTargeted()) { return; } Locale targetLocale = getTargetLocale(); if (StringUtils.isNotBlank(query.get(DisMaxParams.PF))) { try (Formatter f = new Formatter()) { f.out().append(query.get(DisMaxParams.PF)); f.format(" name_%1$s^60 synonym_%1$s^45 def_%1$s^12 ", targetLocale); query.set(DisMaxParams.PF, f.toString()); } catch (IOException ex) { this.logger.warn( "Unexpected exception while formatting SolrQuery PF for vocabulary [{}] and locale [{}]: {}", vocabulary.getIdentifier(), targetLocale, ex.getMessage()); } } if (StringUtils.isNotBlank(query.get(DisMaxParams.QF))) { try (Formatter f = new Formatter()) { f.out().append(query.get(DisMaxParams.QF)); f.format(" name_%1$s^30 synonym_%1$s^21 def_%1$s^6 ", targetLocale); query.set(DisMaxParams.QF, f.toString()); } catch (IOException ex) { this.logger.warn( "Unexpected exception while formatting SolrQuery QF for vocabulary [{}] and locale [{}]: {}", vocabulary.getIdentifier(), targetLocale, ex.getMessage()); } } } }
AbstractXliffTranslatedVocabularyExtension implements VocabularyExtension { @Override public void extendQuery(SolrQuery query, Vocabulary vocabulary) { if (!isCurrentLocaleTargeted()) { return; } Locale targetLocale = getTargetLocale(); if (StringUtils.isNotBlank(query.get(DisMaxParams.PF))) { try (Formatter f = new Formatter()) { f.out().append(query.get(DisMaxParams.PF)); f.format(" name_%1$s^60 synonym_%1$s^45 def_%1$s^12 ", targetLocale); query.set(DisMaxParams.PF, f.toString()); } catch (IOException ex) { this.logger.warn( "Unexpected exception while formatting SolrQuery PF for vocabulary [{}] and locale [{}]: {}", vocabulary.getIdentifier(), targetLocale, ex.getMessage()); } } if (StringUtils.isNotBlank(query.get(DisMaxParams.QF))) { try (Formatter f = new Formatter()) { f.out().append(query.get(DisMaxParams.QF)); f.format(" name_%1$s^30 synonym_%1$s^21 def_%1$s^6 ", targetLocale); query.set(DisMaxParams.QF, f.toString()); } catch (IOException ex) { this.logger.warn( "Unexpected exception while formatting SolrQuery QF for vocabulary [{}] and locale [{}]: {}", vocabulary.getIdentifier(), targetLocale, ex.getMessage()); } } }  }
AbstractXliffTranslatedVocabularyExtension implements VocabularyExtension { @Override public void extendQuery(SolrQuery query, Vocabulary vocabulary) { if (!isCurrentLocaleTargeted()) { return; } Locale targetLocale = getTargetLocale(); if (StringUtils.isNotBlank(query.get(DisMaxParams.PF))) { try (Formatter f = new Formatter()) { f.out().append(query.get(DisMaxParams.PF)); f.format(" name_%1$s^60 synonym_%1$s^45 def_%1$s^12 ", targetLocale); query.set(DisMaxParams.PF, f.toString()); } catch (IOException ex) { this.logger.warn( "Unexpected exception while formatting SolrQuery PF for vocabulary [{}] and locale [{}]: {}", vocabulary.getIdentifier(), targetLocale, ex.getMessage()); } } if (StringUtils.isNotBlank(query.get(DisMaxParams.QF))) { try (Formatter f = new Formatter()) { f.out().append(query.get(DisMaxParams.QF)); f.format(" name_%1$s^30 synonym_%1$s^21 def_%1$s^6 ", targetLocale); query.set(DisMaxParams.QF, f.toString()); } catch (IOException ex) { this.logger.warn( "Unexpected exception while formatting SolrQuery QF for vocabulary [{}] and locale [{}]: {}", vocabulary.getIdentifier(), targetLocale, ex.getMessage()); } } }  @Override boolean isVocabularySupported(Vocabulary vocabulary); @Override void indexingStarted(Vocabulary vocabulary); @Override void extendTerm(VocabularyInputTerm term, Vocabulary vocabulary); @Override void indexingEnded(Vocabulary vocabulary); @Override void extendQuery(SolrQuery query, Vocabulary vocabulary); }
AbstractXliffTranslatedVocabularyExtension implements VocabularyExtension { @Override public void extendQuery(SolrQuery query, Vocabulary vocabulary) { if (!isCurrentLocaleTargeted()) { return; } Locale targetLocale = getTargetLocale(); if (StringUtils.isNotBlank(query.get(DisMaxParams.PF))) { try (Formatter f = new Formatter()) { f.out().append(query.get(DisMaxParams.PF)); f.format(" name_%1$s^60 synonym_%1$s^45 def_%1$s^12 ", targetLocale); query.set(DisMaxParams.PF, f.toString()); } catch (IOException ex) { this.logger.warn( "Unexpected exception while formatting SolrQuery PF for vocabulary [{}] and locale [{}]: {}", vocabulary.getIdentifier(), targetLocale, ex.getMessage()); } } if (StringUtils.isNotBlank(query.get(DisMaxParams.QF))) { try (Formatter f = new Formatter()) { f.out().append(query.get(DisMaxParams.QF)); f.format(" name_%1$s^30 synonym_%1$s^21 def_%1$s^6 ", targetLocale); query.set(DisMaxParams.QF, f.toString()); } catch (IOException ex) { this.logger.warn( "Unexpected exception while formatting SolrQuery QF for vocabulary [{}] and locale [{}]: {}", vocabulary.getIdentifier(), targetLocale, ex.getMessage()); } } }  @Override boolean isVocabularySupported(Vocabulary vocabulary); @Override void indexingStarted(Vocabulary vocabulary); @Override void extendTerm(VocabularyInputTerm term, Vocabulary vocabulary); @Override void indexingEnded(Vocabulary vocabulary); @Override void extendQuery(SolrQuery query, Vocabulary vocabulary);  }