Skip to content

Commit 6569a8f

Browse files
Merge pull request #1834 from vespa-engine/lucene-linguistics-grammar
lucene-linguistics: added query clause profile override example
2 parents b89417b + b81d7fe commit 6569a8f

File tree

1 file changed

+25
-5
lines changed
  • examples/lucene-linguistics/multiple-profiles

1 file changed

+25
-5
lines changed

examples/lucene-linguistics/multiple-profiles/README.md

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ through the <code>vespa deploy</code> step, cloning `examples/lucene-linguistics
3535
vespa feed ext/*.json
3636
```
3737

38-
## Run test queries
38+
## Run queries
39+
40+
### Basic example
3941

4042
This will confirm that ASCII folding is working on the `title` field, because it will match `åao` with `åäö`:
4143
```bash
@@ -46,7 +48,21 @@ curl -s -X POST -d '{
4648
"trace.level":2}' -H "Content-Type: application/json" 'http://localhost:8080/search/' | jq .
4749
```
4850

49-
You can also force a different profile for the query via `model.type.profile`. This will match "dubious" with "special" (our test synonym expansion):
51+
### Different profiles for query and index
52+
53+
For the `description` field, [the schema defines a different profile for search time](app/schemas/doc.sd) which does synonym expansion. So it will match "dubious" from the query string with "special" in the index:
54+
55+
```bash
56+
curl -s -X POST -d '{
57+
"yql":"select * from sources * where description contains \"dubious\"",
58+
"presentation.summary": "debug-text-tokens",
59+
"model.locale": "en",
60+
"trace.level":2}' -H "Content-Type: application/json" 'http://localhost:8080/search/' | jq .
61+
```
62+
63+
### Force a different profile for the query
64+
65+
`model.type.profile` defines the profile to use for parsing the query string. This will match "dubious" with "special" (our test synonym expansion) even for the `title` field (which is bound to the `lowerFolding` profile which doesn't do synonym expansion):
5066

5167
```bash
5268
curl -s -X POST -d '{
@@ -57,12 +73,16 @@ curl -s -X POST -d '{
5773
"trace.level":2}' -H "Content-Type: application/json" 'http://localhost:8080/search/' | jq .
5874
```
5975

60-
For the `description` field, we already use a different profile for search time which already does synonym expansion (as defined in [the schema](app/schemas/doc.sd)). So it will match "dubious" with "special" out of the box:
76+
### Force a different profile for a specific query clause
77+
78+
This works with `userInput()` and the `grammar.profile` annotation:
6179

6280
```bash
6381
curl -s -X POST -d '{
64-
"yql":"select * from sources * where description contains \"dubious\"",
82+
"yql":"select * from sources * where where {defaultIndex:'title', grammar.profile: 'lowerFoldingStemmingSynonyms', grammar:'linguistics'}userInput('dubious')",
6583
"presentation.summary": "debug-text-tokens",
6684
"model.locale": "en",
6785
"trace.level":2}' -H "Content-Type: application/json" 'http://localhost:8080/search/' | jq .
68-
```
86+
```
87+
88+
**NOTE**: The `grammar: 'linguistics'` annotation isn't required in this case, but makes sure that no additional parsing (besides the defined profile) is done. This is useful, for example, with collapsing synonyms (e.g., `wi fi => wifi`). Otherwise, the query becomes `["wi", "fi"]` along the way.

0 commit comments

Comments
 (0)