1

I have a full_name field in my dataset, which contains first_name and last_name.

"fields": {
"full_name": "first_name last_name"
}

I need to query using the following conditions-

//1. with first_name last_name

search/?yql=select * from sources test where full_name contains 'first_name last_name'; 

//2. with only first_name

search/?yql=select * from sources test where full_name contains 'first_name';

//3. with only last_name

search/?yql=select * from sources test where full_name contains 'last_name';

//4. with last_name first_name

search/?yql=select * from sources test where full_name contains 'last_name first_name';

I have tried indexing as index and I am successful to get data using 1st, 2nd, and 3rd condition but not able to query with 4th condition.

Also is there any way where the spelling of first_name or last_name in full_name is not correct still I get the matching results?

suyash308
  • 347
  • 1
  • 7

1 Answers1

4

In 4 you create a single phrase item while you want to separate items combined with AND:

search/?yql=select * from sources test where full_name contains "last_name" and full_name contains "first_name";

Alternatively, if the goal is to match unstructured input you want to send that input as a separate request parameter instead:

search/?yql=select * from sources test where [{"defaultIndex": "full_name"}]userInput(@name);&name=first_name last_name

see https://docs.vespa.ai/documentation/reference/query-language-reference.html

You can see how the query is parsed by adding &tracelevel=1 to the query.

If you need to build various shapes of queries it is usually better to do it in a Searcher component from raw request parameters instead of building a YQL string on the client side, see https://docs.vespa.ai/documentation/searcher-development.html.

Jon
  • 2,043
  • 11
  • 9
  • what if the spelling in first_name and last name are wrong? – suyash308 Dec 27 '19 at 12:22
  • 1
    If you want fuzzy matching, use n-grams, see under https://docs.vespa.ai/documentation/reference/search-definitions-reference.html#match – Jon Dec 28 '19 at 15:34