Index search via JDito
This guide describes how to use JDito to perform advanced searches against the ADITO index. It covers join queries, Solr’s Local Parameter Syntax, and nested patterns. These techniques enable powerful, fine-grained filtering of indexed data. Note that field names from IndexRecordContainers cannot be referenced directly. Solr generates native field names dynamically, so you must use builder functions to resolve them correctly.
Join Queries
The JDito module for index search supports join queries, similar to SQL-style joins. This allows linking documents from different index groups using matching field values.
Basic syntax of a Solr join query:
// Join for documents of "foo", where all matching
// "bar" documents contain the value "test".
{!join from=bar_id to=foo_bar_id}field_in_bar:test
Building a Join query
To create a join query, you need:
- an index query via
indexsearch.createIndexQuery()
- a join query via
indexsearch.createJoinQuery()
Define the from
and to
fields using their respective index groups and field names. Then set the join condition as a pattern. Finally, add the join as a filter to the main index query and execute the search.
Example:
import { indexsearch } from "@aditosoftware/jdito-types";
// In this example, an index query is created that retrieves
// all organisations for which an open offer exists in the index.
// 1. Create a query object for the actual search.
var indexQuery = indexsearch.createIndexQuery()
.setIndexGroups(["Organisation"]); // set the required index group.
// 2. Create a join query builder that joins organisation with the offer group.
// - In order to work the appropriate 'from' and 'to' fields must be specified.
var joinQ = indexsearch.createJoinQuery()
// the field in the target group on which to join.
.from("Offer", "organisation_contact_id")
// the field that is used to join.
.to("Organisation", indexsearch.FIELD_ID)
// the pattern that is applied to filter on the target group
.setPattern("statuscode:OPEN");
// 3. Add the final join query as a filter pattern for the actual search.
indexQuery.addFilter(indexsearch.buildPattern(joinQ));
indexsearch.searchIndex(indexQuery);
The fields used to join index documents must have compatible index field types:
For example:
- STRING → STRING
- TEXT → TEXT or TEXT_PLAIN → TEXT
- BOOLEAN → BOOLEAN
Most text-based field types can be used with each other, but some strange behavior may occur, e.g., if only one of the two fields contains stop words.
The best way is to only join fields having the same index field type.
To inspect actual Solr field names, review the generated schema via the Solr Admin UI.
LocalParamsPattern
Solr supports advanced search modifiers using Local Parameter Syntax. JDito provides the createLocalParamsPattern()
builder to construct such queries.
Example pattern: {!lucene q.op=AND df=text}foo bar
To create this type of search pattern, JDito offers the builder function
indexsearch.createLocalParamsPattern()
, which creates an object that
in turn offers setter functions to configure the pattern.
Since Solr generates field names at runtime, they differ from IndexRecordContainer names. The builder provides setRawIndexFieldParam()
to reference the correct native field name.
Example code:
import { indexsearch } from "@aditosoftware/jdito-types";
// The example constructs a pattern that uses local params.
// The resulting pattern will use the Lucene query parser
// of the index to search in a specific index field.
// Note: The pattern must be converted into
// a nested query in order to use it as the actual pattern
// and not as filter.
// The pattern will search all organisations that start
// with 'A' and also contain 'GmbH' in their name.
// -> {!lucene q.op=AND df=name_value_idx_sto_textnostopwords}A* GmbH
//
// Create the local parameter pattern builder
var localParamsBuilder = indexsearch.createLocalParamsPattern()
// Specifiy the requsted query parser.
.setType("lucene")
// Set the parameter for the default operator.
.setParam("q.op", indexsearch.OPERATOR_AND)
// Specify an index field for a parameter.
.setRawIndexFieldParam("df", "Organisation", "name_value")
// Set the pattern used by the specified parser.
.setPattern("A* GmbH");
// Construct the embedded pattern used for the search
// -> +_query_:"{!lucene q.op=AND df=name_value_idx_sto_textnostopwords}A* GmbH"
var pattern = indexsearch.buildPattern(
indexsearch.createPatternConfig()
.plus(localParamsBuilder.asNestedPattern())
);
// Create an index query for the pattern limited
// to search only for organisations.
var indexQuery = indexsearch.createIndexQuery()
.setPattern(pattern)
.setIndexGroups(["Organisation"]);
// Execute search
indexsearch.searchIndex(indexQuery);
By default, ADITO uses the edismax
query parser for Global Search. If you want to apply other Solr parsers (e.g., lucene
), Local Parameter Syntax must be used explicitly. Refer to the Apache Solr Reference Guide for available parsers and supported parameters.
NestedPattern
Complex queries often require nested expressions. Use createNestedPattern()
to encapsulate pattern strings or other builder-based queries. This improves readability and allows integration into larger query expressions using the query
pseudo-field.
Example code using nested patterns:
import { indexsearch } from "@aditosoftware/jdito-types";
// Construct a nested pattern with a pattern string.
var nestedPattern = indexsearch.createNestedPattern("\"foo bar\"+name:(bar -ba)");
// Add the nested pattern to the config object.
var patternConfig = indexsearch.createPatternConfig()
.or(indexsearch.createTerm("123"))
// Add like any other term object.
.and(nestedPattern);
// Build the final pattern string.
// -> 123 +_query_:"{!edismax}\"foo bar\" +name:(bar -ba)"
var pattern = indexsearch.buildPattern(patternConfig);
The Join Query Builder and the Local Params Builder offer a getter
called asNestedPattern()
to get these query object in the required
nested pattern syntax, so they can easily be combined using the index
query builder, skipping the step of manually using the Nested Pattern
Builder.
Use asNestedPattern()
on join or local parameter builders to directly convert them into nested pattern objects without manually calling createNestedPattern()
.