Is there any way in vespa.ai by which I can query with shuffled query strings? - bigdata

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?

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.

Related

Search string which contains multiple words using CATSEARCH query in PL/SQL

String record : Blueoba Mountain Company
SQL Query :
SELECT from table
WHERE CATSEARCH(account_partner_name_type,'%Blueoba% %Mountain% %Company%', NULL) > 0)
where rn <=500;
If I write the full name of the string in the query (i.e.%Blueoba% %Mountain% %Company%) then it gives me the record.
But if I write %Blueoba% %Mountain% %Comp% or %Blue% %Company% or %Comp% then its not returning any record.
So ideally, if I write a word %comp% then it should search all the records which contains 'comp' word and show the records but its not showing.
Can anybody suggest something?
You can try using wild card characters
SELECT * from table
WHERE account_partner_name_type like '%Blueoba%'
and rn <=500;

Query SQLite using uuid returns nothing

I'm querying a SQLite db file using the id column, which is UNIQUEIDENTIFIER type.
The two commands are :
SELECT * FROM scanned_images WHERE id = cast('5D878B98-71B2-4DEE-BA43-61D11C8EA497' as uniqueidentifier)
or
SELECT * FROM scanned_images WHERE id = '5D878B98-71B2-4DEE-BA43-61D11C8EA497'
However, the above commands both returned nothing.
I also tried:
SELECT * FROM scanned_images WHERE rowid = 1
this command returns the correct data.
There is no uniqueidentifier data type in SQLite.
According to the rules of type affinity described here in 3.1. Determination Of Column Affinity, the column's affinity is numeric.
All that this expression does:
cast('5D878B98-71B2-4DEE-BA43-61D11C8EA497' as uniqueidentifier)
is return 5.
You should have defined the column's data type as TEXT, because you have to treat it like TEXT and write the condition:
WHERE id = '5D878B98-71B2-4DEE-BA43-61D11C8EA497'
or:
WHERE id = '(5D878B98-71B2-4DEE-BA43-61D11C8EA497)'
if as shown in the image it contains surrounding parentheses.

Rank on SQLite SubQuery

I have a table Person with ID(Guid), FirstName(string), LastName(string) and 3000 entries. What I desperately need is the rank of a certain entry by ID in a sorted query by FirstName and LastName.
So for example: I search for any entries with FirstName or LastName containing the String 'mil' which returns 62 entries sorted. Since I know the ID of an entry somewhere in this result, I need the row_index of this entry.
I tried this with a Temp Table before, but since I'm working with sqlite-pcl for UWP I can't use 'CREATE TEMP TABLE' statements and so on, thus I need a solution in a single query.
PRAGMA temp_store = MEMORY;
DROP TABLE IF EXISTS TempQuery;
CREATE TEMP TABLE TempQuery AS SELECT ID FROM Person WHERE (Firstname LIKE '%mil%' OR LastName LIKE '%%');
SELECT rowid FROM TempQuery WHERE ID = '48a0231a-af41-450d-a291-5912d39119c9' LIMIT 1;

Entity having two entities of the same type

I'm programming a small game and a database representing Players and Matches.
A player has a name, a player ID and a rank.
A match has an ID, and two players.
Player
* id (bigint)
name (string)
playerID (string)
rank (integer)
Match
* id (bigint)
matchID (string)
playerOne (Player)
playerTwo (Player)
I would like to have a "matches" relationship in a Player, but how do I have an entity having two entities of same type and what type relationship should I use?
I tried a one-to-one relationship, but the UNIQUE condition it created is a problem.
You need a many-to-many relationship. This is usually done with a "middle" or "link" table. In this example the PlayedMatch table is the link table.
This is effectively a single many-to-many relationship between Player and Match. However it is represented by 2 one-to-many relationships :
Player [1] --> [n] PlayedMatch
Match [1] --> [n] PlayedMatch
Player
Id
Name
Rank
Match
Id
PlayedMatch
Id
MatchId
Player1Id
Player2Id
I see you've got some string properties named PlayerId and MatchId. Avoid these names if you can because they are usually used for foreign key relationships.
You would probably want some more properties in the PlayedMatch table like WinnerId (linking to Player).
A SQL query on the above would look something like this:
SELECT
*
FROM
PlayedMatch pm
INNER JOIN Player p1 ON pm.Player1Id = p1.Id
INNER JOIN Player p2 ON pm.Player2Id = p2.Id
INNER JOIN Match m ON pm.MatchId = m.Id
If you want to easily find all matches per player you will need to use a ManyToMany relationship. The following is a simplified snippet of what the classes would look like.
class Player {
/**
* #ORM\ManyToMany(targetEntity="Match", mappedBy="players")
*/
protected $matches;
}
class Match {
/**
* #ORM\ManyToMany(targetEntity="Player", inversedBy="matches")
*/
protected $players;
}
Then you run the following command from the root directory:
php app/console doctrine:generate:entities Your/AwesomeBundle/Entity
And you will be able to use methods such as:
Match::getPlayers()
Match::addPlayer()
Player::addMatch() // probably will have an 'e' at the end of the word match
Player::getMatches() // which is the one that will give you all matches of a user
You will need to restrict the number of players per match in your code.

SELECT * ... WHERE col="string" returns invalid row

I'm getting a confusing select...where result, the table definition is:
CREATE TABLE modes (
key INTEGER,
mode INTEGER,
channel INTEGER,
name TEXT,
short_name TEXT,
def INTEGER,
highlight INTEGER,
catagory TEXT,
subcatagory TEXT);
It's populated with:
sqlite> select * from modes;
3|6|5|Green|G|0|255|a|b
3|6|6|Blue|B|0|255|a|b
3|9|1|Mode|Mode|0|255|a|b
3|9|2|Auto Mode Speed|Speed|0|255|a|b
3|9|3|Strobe|Strobe|0|255|a|b
3|9|4|Red|R|0|255|a|b
3|9|5|Green|G|0|255|a|b
3|9|6|Blue|B|0|255|a|b
3|9|7|Red2|R2|0|255|a|b
3|9|8|Green2|G2|0|255|a|b
3|9|9|Blue2|B2|0|255|a|b
3|6|4|Red|R|0|255|a|b
3|6|1|6|6|0|255|a|b
3|6|2|Auto mode speed|speed|0|255|a|b
3|6|3|Strobe|Strobe|0|255|strobe|b
Note the row 3rd from the bottom:
3|6|1|6|6|0|255|a|b
If I do a select:
SELECT * FROM modes where mode=6 and name="Mode" order by channel;
It returns:
3|6|1|6|6|0|255|a|b
Columns 4 and 5 (name and short_name) should not match, they are 6 and the match term is "Mode". If I change the match string "Mode" to any other string it works as expected. Is "Mode" a reserved word? or Did I somehow set a variable "Mode" to 6?. I don't understand this behavior.
If you use ["] it means columns, so when you do
name="Mode"
it means you search in column name that have same value as column Mode. So you select where mode=6 and name=6 actually on your code.
If you want to use string, use ['] not ["]
I try to use that code on my database..
select * from products
where name="Mode"
And I got error
ERROR: column "Mode" does not exist
LINE 2: where name="Mode"
I finally found it in the docs if anyone else is looking.
it's in the the sqlite3 FAQ
My familiarity is not with sqlite3, but I would say that it looks to me like you are doing name="Mode" which is taking the modes.mode object and checking it.
If you do SELECT * FROM modes where name="Mode" order by channel. You may find that it just gives you 3|6|1|6|6|0|255|a|b as well.

Resources