Query translator objects are used to help translate queries from Perceptive Enterprise Search syntax into a format understood by the federated system. The default translator handles simple mapping for you, it loads settings from the connector configuration file, see Simple Query Translator.
You can override certain aspects of the default query translator if the query syntax of the federated system is more complex than can be achieved using the simple mapping.
To create your own QueryTranslator, you must create a new class that extends the QueryTranslator class; you then specify your class in the constructor of the connector.
The query translator uses a recursive decent parser to walk the query text calling back into handler methods of your class. This gives you flexibility to easily make minor tweaks to the existing translator, or completely replace it with your own.
Your query translator can override any of the following handlers:
Handler | Description |
GetWord | Called for each no operator |
GetPhrase | Called for each phrase |
GetProximity | Called to handle proximity searches such as “in the same paragraph†|
GetFielded | Called to handle fielded searches such as “John IN author†|
GetFilter | Called to handle filters such as “FNAMELIKE *.pdf†|
GetRange | Called to handle range searches such as “GE 1000†|
GetOperator | Called to handle Boolean operators such as AND, OR and NOT |
To understand the parsing process, consider the following examples. For each query, the following methods in the query translator are called.
CAT AND DOG NOT FISH
1. GetWord(“CATâ€)
2. GetWord(“DOGâ€)
3. GetOperator(“ANDâ€, “CATâ€, “DOGâ€)
4. GetWord(“FISHâ€)
5. GetOperator(“NOTâ€, “CAT AND DOGâ€, “FISHâ€)
CAT AND (DOG OR FISH)
1. GetWord(“CATâ€)
2. GetWord(“DOGâ€)
3. GetWord(“FISHâ€)
4. GetOperator(“ORâ€, “DOGâ€, “FISHâ€)
5. GetOperator(“ANDâ€, “CATâ€, “DOG OR FISHâ€)
TAX // RATES NOT 2004
1. GetWord(“TAXâ€)
2. GetWord(“RATESâ€)
3. GetProximity(“//â€, “â€, “TAXâ€,â€RATESâ€)
4. GetWord(“2004â€)
5. GetOperator(“NOTâ€, “TAX // RATESâ€, “2004â€)
(JOHN CITIZEN IN AUTHOR) NOT (CREDIT OR PAY) AND RETIREMENT
1. GetPhrase(“JOHN CITIZENâ€)
2. GetWord(“AUTHORâ€)
3. GetFielded(“AUTHORâ€, “JOHN CITIZENâ€)
4. GetWord(“CREDITâ€)
5. GetWord(“PAYâ€)
6. GetOperator(“ORâ€, “CREDITâ€, “PAYâ€)
7. GetWord(“RETIREMENTâ€)
8. GetOperator(“ANDâ€, “JOHN CITIZEN IN AUTHOR NOT CREDIT OR PAYâ€, “RETIREMENTâ€)