Cockpit: Universal search engine :)

Created on 13 Mar 2018  路  6Comments  路  Source: agentejo/cockpit

Hello !
I'm trying to do an universal search (search engine) in Cockpit.
First, I tried to use regexp :
find(array('title'=> array('$regex' => $_POST['title'])))->sort(["created"=>"-1"]) as $item): ?>

Here, I can find post like in sql :
select * from post where title like '%$_POST['title']%';

Now, I want to do it case insensive : something like :
select * from post where title like '%$_POST['title']%';

But I failed :( I tried to use regexp for mongo... but it doesn't work.
Can you help me ?

THank you

Most helpful comment

The other approach is to go outside the API entirely and generate the search index from whatever site is consuming the API. I've got a proof-of-concept project with Algolia here:

https://github.com/ICJIA/algolia-site-indexer

Essentially, this takes a sitemap.xml file for a site (in my case a sitemap.xml generated by Nuxt.js), parses it, and then one-by-one indexes each url from the site. If it's in the sitemap, it'll get indexed.

I grab key meta items -- title, keywords, description -- and then append a set limit of characters from the page's main body content (by checking whatever class/id attribute is used for the content).

Then, I generate a unique Algolia objectID based on an MD5 hash of the actual URL. That way, I know the objectIDs are unique to each page.

Then I send all the results to the Algolia index.

For the final step, I check and see if pages have been deleted since the last indexing. If so, I delete those pages from the Algolia index. (Added pages are automatically included, so I don't need to worry about those.)

In my actual site, I use the Algolia 'vue-instantsearch' component to display the results.

It works incredibly well. I'm not sure if this is the best way to do it, but for a basic, (and instant!) search. this works great.

All 6 comments

You would have read :
select * from post where lower(title) like '%lower($_POST['title'])%';

I would approach a search functionality by leveraging a search engine like Apache Solr or Algolia. The contents can be indexed by pushing the contents to the search engine during a "collections.save.after" event.
Resuming I see some space for a custom addon that provides the mechanisms to integrate with such engines.

https://github.com/agentejo/Detektivo - a Proof of concept project

Exactly :)

Thank you ! I will have a look to this addon. Don't understant how it's work at first sight, but I will dig !

The other approach is to go outside the API entirely and generate the search index from whatever site is consuming the API. I've got a proof-of-concept project with Algolia here:

https://github.com/ICJIA/algolia-site-indexer

Essentially, this takes a sitemap.xml file for a site (in my case a sitemap.xml generated by Nuxt.js), parses it, and then one-by-one indexes each url from the site. If it's in the sitemap, it'll get indexed.

I grab key meta items -- title, keywords, description -- and then append a set limit of characters from the page's main body content (by checking whatever class/id attribute is used for the content).

Then, I generate a unique Algolia objectID based on an MD5 hash of the actual URL. That way, I know the objectIDs are unique to each page.

Then I send all the results to the Algolia index.

For the final step, I check and see if pages have been deleted since the last indexing. If so, I delete those pages from the Algolia index. (Added pages are automatically included, so I don't need to worry about those.)

In my actual site, I use the Algolia 'vue-instantsearch' component to display the results.

It works incredibly well. I'm not sure if this is the best way to do it, but for a basic, (and instant!) search. this works great.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

poldixd picture poldixd  路  4Comments

flayks picture flayks  路  5Comments

TechnicallyJoe picture TechnicallyJoe  路  4Comments

tsimenis picture tsimenis  路  5Comments

elpeyotl picture elpeyotl  路  5Comments