0

Im having trouble finding a way how to have 2 differently structured fields in one suggest component. (https://cwiki.apache.org/confluence/display/solr/Suggester)

The goal is to have an autocomplete module with these fields.

  • A field where StandardTokenizer is used example output: This is a title
  • A field where a Custom tokenizer is used (Basically a regex to get a base domain of a full URL) example output: thisisatitle.com

Therefore the requesthandler containing the the suggestcomponent is able to show both strings in the results array: thisisatitle.com and This is a title

Things ive tried are:

  • Multiple suggestcomponents

Ive googled and the only solution ive currently found is using shards as they allow for different schemas to be combined. To my mind that is rather ineffective as running 2 servers would be a waste of resources and also maintainability would suffer.

Any suggestions/workarounds are welcome.

Jointts
  • 121
  • 3
  • 11
  • 1
    Any reason why you can't query the two fields using `qf=field1 field2` or `q=field1:foo OR field2:foo`? – MatsLindh Jan 06 '17 at 13:33
  • @MatsLindh I see where youre aiming, but wouldnt that only solve the fact how to query 2 fields? The problem is not how can I query the 2 fields, but its the fact that these two fields have different field types. Putting fields with different field types in one request handler results in Solr throwing an error in that endpoint. – Jointts Jan 08 '17 at 13:45
  • Each field runs its own analysis chain before comparing the resulting tokens, so having different definitions shouldn't be an issue. Exactly what are you doing and how are you implementing that? There shouldn't be a need to change anything in a request handler to implement this? – MatsLindh Jan 08 '17 at 18:13
  • Sorry maybe i phrased the question wrong, im trying to implement a Suggester ( https://cwiki.apache.org/confluence/display/solr/Suggester ). Lets say i want to put 2 fields link that corresponds to the field type link and another field named title that maps to the field type title. How would you approach this? – Jointts Jan 09 '17 at 10:41
  • 1
    That changes everything. :-) Have you tried the "Multiple dictionaries" strategy described at the wiki? https://cwiki.apache.org/confluence/display/solr/Suggester#Suggester-MultipleDictionaries.1 – MatsLindh Jan 09 '17 at 11:13
  • 1
    This solved the problem, thank you! I tried what you suggested but the first time I was actually using SearchComponent combined with which resulted in ConjunctionalSpellCheck.java error. Your anwser actually made me think about switching the spellchecker with suggester and the SearchComponent with SuggestComponent. This worked! Again many thanks and you can put the comment as the answer so i can accept :) – Jointts Jan 09 '17 at 13:03

1 Answers1

1

To use multiple suggestion dictionaries (that can have different analyzers applied), you can use the "multiple dictionaries" configuration as shown in the documentation:

<searchComponent name="suggest" class="solr.SuggestComponent">
  <lst name="suggester">
    <str name="name">mySuggester</str>
    <str name="lookupImpl">FuzzyLookupFactory</str>     
    <str name="dictionaryImpl">DocumentDictionaryFactory</str>     
    <str name="field">cat</str>
    <str name="weightField">price</str>
    <str name="suggestAnalyzerFieldType">string</str>
  </lst>
  <lst name="suggester">
    <str name="name">altSuggester</str>
    <str name="dictionaryImpl">DocumentExpressionDictionaryFactory</str>
    <str name="lookupImpl">FuzzyLookupFactory</str>
    <str name="field">product_name</str>
    <str name="weightExpression">((price * 2) + ln(popularity))</str>
    <str name="sortField">weight</str>
    <str name="sortField">price</str>
    <str name="storeDir">suggest_fuzzy_doc_expr_dict</str>
    <str name="suggestAnalyzerFieldType">text_en</str>
  </lst> 
</searchComponent>
MatsLindh
  • 49,529
  • 4
  • 53
  • 84