Search code examples
javamarklogicautosuggestmarklogic-8

MarkLogic - How to switch Language of Suggest


i want to use the suggestion feature of MarkLogic database in conjunction with the Java Client API.

The problem with that is, to do a suggest call i need a field or something that serves as a suggestion source. The next step is to create query options that reference this suggestion source. The last step is to call:

SuggestionDefinition def = marklogicClient.newQueryManager().newSuggestionDefinition();
def.setLimit(10);
def.setOptionsName("my-query-options");
def.setStringCriteria("Test");
//setup lang?

The question is: How to switch language? If my frontend can be switched between german and english, then i have to switch the search/suggest language. In order to do this i have to switch the collation but how?

The query options are static after upload, containing something like:

<default-suggestion-source>
    <word collation="http://marklogic.com/collation/de">
        <field name="my-suggest" />
    </word>
</default-suggestion-source>

Solution

  • The solution comes through two possible (and practical) ideas:

    Either create more than one query options file per language as suggested (and additional indexes per language) or just ignore the problem!

    If the field behind the suggestion (the source) points to elements that are tagged with different xml:lang attributes, than a suggest call with say "books" will return only english suggestions and a call with the german "Bücher" will return only german suggestions.

    The only exception is if there is german text in an english tagged element. This could lead to false positives.

    Additional thought: Searching through suggestions like "books" and setting the search language to german will return nothing.

    Conclusion: Searching under a specific language is a complex topic. It really depends on how the user want to search and how the application works.

    P.S: I used the second solution to just ignore the problem for now.