Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Advanced FTS queries not working in DB published using datasette-publish-now #22

Open
aborruso opened this issue Apr 22, 2020 · 11 comments

Comments

@aborruso
Copy link

Hi,
in the sf-trees project, it's possible to use *, NEAR, AND, etc. In example the string melanoxylo*.

I have created my first datasette project, I have enabled full-text search, but I cannot use in example *: the query for vill* (I have the word "villa" and "ville").

I have enabled full-text running:

sqlite-utils enable-fts my.db mytable fieldone fieldtwo

I have published it without any option using this command:

datasette publish now commissioniComunePalermo.db --project=my-database

Thank you very much

@simonw
Copy link
Owner

simonw commented Apr 27, 2020

I thought that maybe your table was FTS4 and the Datasette fixtures table was FTS5, but no - yours is FTS5 too according to the schema at the bottom of https://my-database.now.sh/commissioniComunePalermo/youtube_fts

CREATE VIRTUAL TABLE [youtube_fts] USING FTS5 (
                [#text], [commissione],
                content=[youtube]
            );

@simonw
Copy link
Owner

simonw commented Apr 27, 2020

The escape_fts() function is applied to user-provided ?_search= queries by design - I don't want users to have to know SQLite FTS syntax in order to use search.

If you want to run a query that takes advantage of FTS syntax you would need to do so using either a completely custom SQL query or using the ?_where= table option, like this:

https://latest.datasette.io/fixtures/searchable?_where=rowid+in+(select+rowid+from+searchable_fts+where+searchable_fts+match+%27bar%2A+NEAR+cat%27)

@simonw
Copy link
Owner

simonw commented Apr 27, 2020

So: my recommendation is for you to use ?_where= or an entirely custom SQL query if you want to use advanced FTS syntax.

@simonw simonw closed this as completed Apr 27, 2020
@simonw
Copy link
Owner

simonw commented Apr 27, 2020

... or use the feature I forgot about, ?_searchmode=raw!

https://datasette.readthedocs.io/en/stable/json_api.html#special-table-arguments

JSON_API_—_Datasette_documentation

@aborruso
Copy link
Author

Hi @simonw and thank you.

So: my recommendation is for you to use ?_where= or an entirely custom SQL query if you want to use advanced FTS syntax.

But if I use ?_where= , I have no result https://my-database.now.sh/commissioniComunePalermo?sql=select+rowid+from+youtube_fts+where+youtube_fts+match+escape_fts%28%27vill*%27%29

Is it a bugged db?
What can I do? Delete it and build again?

I don't want users to have to know SQLite FTS syntax in order to use search.

Ok, me neither. But I see what is possible to do here by default and it's great. I can search:

I would like to use it to build my datasette website. How to have it?

Thank you for this great tool

@simonw
Copy link
Owner

simonw commented Apr 27, 2020

I'm really confused by that example - I don't know why that's not working for you.

Once we figure out what's wrong with that you can get advanced FTS working on your pages by adding &_searchmode=raw to the querystring in the URL for the table pages.

@simonw simonw changed the title Full text seach option Advanced FTS queries not working in DB published using datasette-publish-now Apr 27, 2020
@simonw simonw reopened this Apr 27, 2020
@simonw
Copy link
Owner

simonw commented Apr 27, 2020

Huh, here's another bug: I'm trying to download your SQLite database from https://my-database.now.sh/commissioniComunePalermo.db but my request is hanging. Eventually I get this error:

An error occurred with this application.

NO_STATUS_CODE_FROM_FUNCTION

That's another datasette-publish-now bug. I'm going to move this issue to that repo.

@simonw simonw transferred this issue from simonw/datasette Apr 27, 2020
@simonw
Copy link
Owner

simonw commented Apr 27, 2020

Could you make a copy of your commissioniComunePalermo.db file available somewhere so I can take a look at it? Running datasette publish now --public might do the trick - that would let me download it from https://my-database.now.sh/_src (which I can't access at the moment).

@aborruso
Copy link
Author

I'm attaching it here. Thank you

commissioniComunePalermo.zip

@aborruso
Copy link
Author

aborruso commented Apr 28, 2020

Once we figure out what's wrong with that you can get advanced FTS working on your pages by adding &_searchmode=raw to the querystring in the URL for the table pages.

Is there a way to add searchmode=raw to configuration and enable it by default, without adding it every time to the URL? Probably here it's in this way.

Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants