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

Propose a tutorial #118

Open
nticaric opened this issue Nov 10, 2017 · 35 comments
Open

Propose a tutorial #118

nticaric opened this issue Nov 10, 2017 · 35 comments

Comments

@nticaric
Copy link
Contributor

If you have a topic you would like to read about and how to do it using TNTSearch, propose it here and we'll try to write a tutorial about it

@OGhawsi
Copy link

OGhawsi commented Nov 11, 2017

A complete example, like searching a Post model or anything like that would be more helpful.
Because those who are new to Laravel and TNTSearch will learn easily.

@syntaxseed
Copy link

syntaxseed commented Nov 26, 2017

I'd like to know if the initial seed of the index from a db can be skipped.... and just add new records on the fly. Ie a tutorial for using it without a source db.

@stokic
Copy link
Contributor

stokic commented Nov 26, 2017

@OGhawsi http://tnt.studio/blog/searching-for-bobby-fisher-with-laravel-5 is there something that's not clear from this tutorial? If yes, please suggest on how to improve it.

@syntaxseed I don't think that there needs to be a special tutorial for this, when you insert your first record, do your first index then and that's it :)

@ultrono
Copy link

ultrono commented Dec 4, 2017

@syntaxseed I'd imagine you'd need an empty .sqllite file i.e. "products.sqlite". I don't see why you wouldn't want to create the index full initially and then follow https://github.com/teamtnt/tntsearch#updating-the-index to update the index as items are added.

@syntaxseed
Copy link

syntaxseed commented Dec 5, 2017

@ultrono My data, as it exists in the DB is not in a format ready to be indexed. For example, the text contains BBCODES kind of like [snippet=12] which insert text snippets stored in other tables. It's only the 'published' version of the data that makes sense to index. But that is stored in JSON files. Soooo I was hoping to start with an empty index, and then just add records as the publishing process creates them, but before they are saved as JSON. Ie... that intermediary stage in memory in which all snippets are inserted, but before it's in json format.

This is why I was looking for an indexing solution instead of just doing queries on the database.

@ultrono
Copy link

ultrono commented Dec 5, 2017

@syntaxseed I have an older version of TNT search here and I'm able to insert records one by one, into an empty sqlite file. Is that was you're referring to?

@syntaxseed
Copy link

@ultrono Yes!!
My only questions would be how to init the empty sqlite file... and would it work for the latest version?

@ultrono
Copy link

ultrono commented Dec 6, 2017

@syntaxseed Try $tnt->createIndex('name.index').

Depending upon your server setup/permissions you may need to manually create the raw file from the command line: touch app/path/name.index

@pmartelletti
Copy link

@nticaric implementing ACL would be an awesome tutorial: ie, searching a given query might return different results based on the roles / permissions the users have (we don't want to show link to threads they don't have access to, for example).

@ultrono
Copy link

ultrono commented Dec 7, 2017

@pmartelletti TNT Search shouldn't be responsible for ACL. You'd implement ACL yourself. You'd either add an extra where clause to the resulting Eloquent query, or (less efficiently) filter the resulting Eloquent collection i.e.

$filtered = $posts->reject(function($post) use ($user) {
  return $post->author_id != $user->id;
});

Or you could make use of a relation on your model:

$filtered =  $posts->reject(function($post) use ($user) {
  return $user->isAuthorOf($post);
});

However, all this is going off topic a little as ACL is not TNT's responsibility.

@OGhawsi
Copy link

OGhawsi commented Jan 9, 2018

@stokic, @nticaric I went through those three tuts on TNT studio but still, I couldn't implement anyone successfully,
I am suggesting some tutorial like they have for implementing Algolia, that is really simple.
Thanks.

@stokic
Copy link
Contributor

stokic commented Jan 9, 2018

@OGhawsi this tutorial http://tnt.studio/blog/searching-for-bobby-fisher-with-laravel-5 has a total of 5 lines of code if you don't count the configuration file, I can't possibly see how easier a tutorial should be than adding 5 lines of code in 2 files :)

If there is something that is not clear from those tutorials or from the documentation please let us know. Could you give us an example of the tutorial (url) which is more simple than the one with 5 lines of code? :)

@ultrono
Copy link

ultrono commented Jan 9, 2018

@OGhawsi If you're using the TNT Search Scout driver there is next to no difference to implementing Agolia and TNT Search - it's just configuration changes using the same API. If implementing TNT Search stand alone the readme at https://github.com/teamtnt/tntsearch and the tests folder at https://github.com/teamtnt/tntsearch/tree/master/tests contain all the code you could require - the code is literally written for you. What are you missing exactly as all the code is there for you.

@OGhawsi
Copy link

OGhawsi commented Jan 11, 2018

I am trying one of the tutorials on tntstudio: Searching for Bobby Fisher with Laravel 5
I have got an error:
Non-static method TeamTNT\TNTSearch\TNTSearch::createIndex() should not be called statically

Any idea how to fix

@ultrono
Copy link

ultrono commented Jan 11, 2018

@OGhawsi When using code on Github I'd strongly advise reading at least the readme and browsing the tests folder.

The error is very self explanatory - you are trying to call the none static createIndex() method, statically.

Usage is explained in the readme for this repo i.e. https://github.com/teamtnt/tntsearch#creating-an-index

$tnt = new TNTSearch;

$tnt->loadConfig([
// config settings
]);

// Note the none static call
$indexer = $tnt->createIndex('name.index');

@OGhawsi
Copy link

OGhawsi commented Jan 12, 2018

Thanks @ultrono for your advice and help, I solved that.
I am sorry being new here.
Can you help me with this one last thing, which might be a general Laravel question and I have tried too much:
Documentation says:

// to display the results you need an additional query against your application database
// SELECT * FROM articles WHERE id IN $res ORDER BY FIELD(id, $res);

I am trying to display the results in view but the search does not return a single array of ids, instead it returns a multidimensional array which contains ids[ ], hits[ ], execution time[ ].

Here is my query:

`

  $res = $tnt->search($request->input('q'));

  $users = DB::table('users')->whereIn('id', $res)->orderBy('id')->get();

  return view('users.show')->with(compact('users'));

`

This throws an error:

SQLSTATE[HY093]: Invalid parameter number: parameter was not defined (SQL: select * from "users" where "id" in (1, 6, 13) order by "id" asc)

Thanks so much in advance, you guys are really good.

@ultrono
Copy link

ultrono commented Jan 12, 2018

@OGhawsi If you're using Laravel Scout, that query doesn't apply. Laravel handles that for you. If using TNT search stand alone you'll need to do something like the following with the ids IIRC:

$ids = implode(",", $res['ids']);

@OGhawsi
Copy link

OGhawsi commented Jan 13, 2018

@ultrono I am using Laravel Scout, so how should I do that.

Thanks.

@ultrono
Copy link

ultrono commented Jan 14, 2018

@OGhawsi Firstly you're commenting on the wrong repo if you're using Scout :)

IF using Scout you don;t need to worry about writing the query are per the Laravel Scout documentation. I would highly recommend spending 5 or 10 mins reading the Laravel docs on this topic as it is very clearly explained, see https://laravel.com/docs/5.5/scout#searching. Whatever the Scout driver you use, the same API applies applies. When using Scout there really isn't anything to it, all the hard work has been done for you.

@b12k
Copy link

b12k commented May 28, 2018

Greetings.

Can you, please, explain how can I implement range search within a free text query.
For example I want to search for a specific car make and model with defined price range and mileage.
The thing is that website is multilingual so I assume i need to have synonyms.

Query example:

  • en - BMW M3 2017 or BMW M3 from 2014 to 2017
  • de - BMW M3 2017 or BMW M3 von 2014 bis 2017

Is there a way to define operators, synonyms and maybe ignored words?
Of course I can do manual query modification before using it with TNTSearch, but is there a built-in functionality for that?

Thank you in advance!

PS: Also it would be nice to have a more advanced documentation with examples for dummies =)

@JustAWebDev
Copy link

Is there a way to use mysql instead of sqlite? If so, how do you configure that?

@q2apro
Copy link

q2apro commented Jun 19, 2023

I am new to TNTSearch and have problems already with a normal start. The documentation is insufficient (or I am stupid). Tutorials online are rare.

  1. I don't use Laravel/composer, so I would need a pure PHP installation guide.
  2. How to start?
  3. A full walkthrough would be the best help.

I would like to index and search through a MySQL database that holds title, content and tags columns. Similar to a blog.

How to start?

@stokic
Copy link
Contributor

stokic commented Jun 19, 2023 via email

@q2apro
Copy link

q2apro commented Jun 19, 2023

It is not pure php, always Laravel.

Imagine I give you an FTP client and PHPmyadmin. How would you start?!

Suggest a link please.

@stokic
Copy link
Contributor

stokic commented Jun 19, 2023 via email

@q2apro
Copy link

q2apro commented Jun 19, 2023

It starts with use TeamTNT\TNTSearch\TNTSearch; ... as a beginner I have no idea what that means.

Why not to start with "Upload the folder xyz to your server, then create a file abc.php, then put this code into the file"?

It is sad that great projects are not used by so many developers because the first steps are not described and not clarified.

@nticaric
Copy link
Contributor Author

I understand your concern. As a friendly suggestion, I would encourage you to consider using Composer for your project. It's a widely adopted tool that greatly simplifies dependency management in PHP.

Without Composer, it could become increasingly difficult to manually manage and update libraries in your project, which might lead to compatibility issues down the road. Learning to use Composer could significantly enhance the maintainability of your project and is considered a best practice in modern PHP development.

I hope this suggestion will contribute to the success of your project. Please feel free to ask if you have any questions about Composer or dependency management in general.

As for the use TeamTNT\TNTSearch\TNTSearch; statement, this is not specific to Composer but is part of PHP's namespace system, which is used to avoid naming conflicts between different pieces of code. The use statement allows you to refer to a class using a shorter name instead of the full namespace.

Lastly, while the suggestion of uploading a folder and creating a file can work for smaller projects or scripts, it becomes infeasible for larger, more complex projects that use many external libraries and need to manage dependencies between them. Composer is a tool that is designed to manage this complexity, making it easier to build, maintain, and collaborate on PHP projects.

@stokic
Copy link
Contributor

stokic commented Jun 19, 2023 via email

@q2apro
Copy link

q2apro commented Jun 19, 2023

If you have no SSH rights, and only FTP client and PHPmyadmin (no composer), it seems, that TNTSearch is not the right choice.

Sad because many developers are using only tools like that.

@stokic
Copy link
Contributor

stokic commented Jun 19, 2023 via email

@q2apro
Copy link

q2apro commented Jun 19, 2023

When I see a project that is many years old and there is not any advice how to start under the circumstances described, and just a comment "you are a developer, find out yourself", I really wonder why, and what happened all those years.

I just asked how to start. And I didn't receive any help.

@q2apro
Copy link

q2apro commented Jun 19, 2023

Here is a good and simple example: https://github.com/phpsearch/library#without-composer

@stokic
Copy link
Contributor

stokic commented Jun 19, 2023 via email

@q2apro
Copy link

q2apro commented Jun 20, 2023

I glanced over the code. Well written.

However, one thing I noticed is that there are DB tables wordlist, doclist, fields, hitlist, info.

Those tables should have prefixes to not colide with other tables in the same database.

I recommend to use tnt_ as a prefix for all of them.

Update:

The SQLite directly stores info in a single file, making it easy to copy. No configurations are required, and the process ca be done using minimal support.

So no prefixes are needed. Thanks @stokic

@stokic
Copy link
Contributor

stokic commented Jun 20, 2023 via email

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

No branches or pull requests

9 participants