Strange field index issue with SphinxQL - sphinx

I indexed a new table and did a sphinxql search:
select id from idx_Table WHERE (MATCH('#(Title) Word')
Which finds matches.
However if I try the search field in the Select command:
select id,Title from idx_Table WHERE (MATCH('#(Title) Word')
I get an error:
[Err] 1064 - index idx_Table: parse error: unknown column: Title
I checked the Title field and the matches are correct so clearly the index is indexing the field and then searching in the field correctly. So not quite sure why adding the same field to the Select command indicates it was not indexed.

You can only specify Attributes in the 'select' part, not Fields.
As a general rule, fields are matched in the full text query (the MATCH(...)), attributes are used everywhere else (select, group, order, filter etc) .
Edited to add....
So a solution is to make your title, into both an attribute and a field, so can be used as either. For strings its easy with sql_field_string.

Related

How to define a tags / value query in Grafana 7.4?

I am having some trouble understanding the concept of Value groups/tags in Grafana 7.4.x with MySQL as a data source.
My main query gets the Countries
SELECT
NAME as __text,
id AS __value
from
countries
The tags query gets the Continents
SELECT
NAME as __text,
id AS __value
from
continents
That works so far, tags are shown in the list, but nothing happens once I click on them.
My tags query:
continents.$tag.*
The tags query seems to be the problem. Any help is greatly appreciated.
3 queries are involved:
The first one is under "Query Options" -> "Query": This one should list all the values (all the countries in your case).
The second query is the "Tags query" under "Value groups/tags": This query should list all the Tags you want (continents).
The third query is "Tag values query": This is where the magic happens, this query should return all the different values matching the selected tags, so, you must add a WHERE clause somewhere that Grafana will use to create a query to get the correct values, ...WHERE continent = '$tag'. <- $tag will automatically be replaced by a list of tags the user has chosen.
Be aware that the official documentation provides examples for InfluxDB datasource, since you are using MySQL, you must use SQL queries everywhere, so continents.$tag.* is invalid.

Unable to filter on a numeric field in a custom index

I have created a custom smart search index in Kentico but I am unable to get the index to return any results when I search against a four character year field.
I have tried adding the field to the index as an integer and used the suggested search syntax
publishedyear:10000002016
publishedyear:(int)2016
I have also added as a string and tried
publishedyear:2016
In all cases I am unable to get the search preview to return any results
Searching against an alphanumeric field such as
country:Canada
works fine.
I can view the index using the Luke tool and can confirm the expected values for publishedyear are in the index
What am I missing?

How to get best matching products by number of matches in postgres

Postgres 9.1 shopping cart contains product table
create table products (
id char(30) primary key,
name char(50),
description text );
Cart has search field. If something is entered into it, autocomplete dropdown must show best matching products ordered by number products matched to this criteria.
How to implement such query in postgres 9.1 ? Search should performed by name and description fields in products table.
It is sufficient to use substring match. Full text search with sophisticated text match is not strictly required.
Update
Word joote can be part of product name or description.
For example for first match in image text may contain
.. See on jootetina ..
and for other product
Kasutatakse jootetina tegemiseks ..
and another with upper case
Jootetina on see ..
In this case query should return word jootetina and matching count 3.
How to make it working like auotcomplete which happens when search term is typed in Google Chrome address bar ?
How to implement this ?
Or if this is difficult, how to return word jootetina form all those texts which matches search term joote ?
select word, count(distinct id) as total
from (
select id,
regexp_split_to_table(name || ' ' || description, E'\\s+') as word
from products
) s
where position(lower('joote') in lower(word)) > 0
group by word
order by 2 desc, 1
First of all, do not use the data type char(n). That's a misunderstanding, you want varchar(n) or just text. I suggest text.
Any downsides of using data type "text" for storing strings?
With that fixed, you need a smart index-based approach or this is a performance nightmare. Either trigram GIN indexes on the original columns or a text_pattern_ops btree index on a materialized view of individual words (with count).
Pattern matching with LIKE, SIMILAR TO or regular expressions in PostgreSQL
The MV approach is probably superior for many repetitions among words.

Must be possible to filter table names in a single database?

As far as I can tell, the search filter in the navigator will only search available database names, not table names.
If you click on a table name and start typing, it appears that a simple search can be performed beginning with the first letter of the tables.
I'm looking for way to be able to search all table names in a selected database. Sometimes there can be a lot of tables to sort through. It seems like a feature that would likely be there and I can't find it.
Found out the answer...
If you type for example *.test_table or the schema name instead of the asterisk it will filter them. The key is that the schema/database must be specified in the search query. The asterisk notation works with the table names as well. For example *.*test* will filter any table in any schema with test anywhere in the table name.
You can use the command
SHOW TABLES like '%%';
To have it always in your tools, you can add it as a snippet to SQL aditions panel on the right.
Then you can always either bring it in your editor and type your search key between %%, or just execute it as it is (It will fetch all the tables of the database) and then just filter using the "filter rows" input of the result set.

Full-Text search on a table column issue

I have a Table that I want to search its title(nvarchar(max)) column.
But I am getting an error when I create an index over the title column so I can enable Full Text search on it.
I am going to use the Contains keyword to do the job.
Any ideas?
Thanks,
You say in the comments
When I create the index over the
column Title, I get an error stating
that you cannot create an index over a
column of this type
This sounds like you are trying to create a regular index on it not a full text index. Right click the table in SSMS and choose "Full Text Index" to set up full text indexing.
If this option is greyed out you might need to run exec sp_fulltext_database 'enable' first.