Keystone-classic: Add a search option to the front end

Created on 16 Dec 2013  路  10Comments  路  Source: keystonejs/keystone-classic

I was thinking about adding a search feature on each page (blog, wiki, whatever) and also a global that one that could be used on header or something.

I thought the search used in the admin is really nice, so it'd be basically adding that to users that are not logged in.

I'd been more than happy in doing this, then submit it as a merge request as long as you point me in the right direction.

discussion

Most helpful comment

keystone.list('Post').model.find({
  title: new RegExp('^'+req.body.search+'$', "i")
}, function(err, results) {
  // Do your action here..
  locals.data.locations = results;
  if (results == ''){
    locals.data.invalid = 'Invalid search';
  }
  next(err);
});

All 10 comments

Hi Wagner,

Interesting idea, although Keystone doesn't have a standard concept of pages for users that aren't logged in.

There are some (not documented yet) features that make implementing search easy on a per-list basis, including the searchFields option and getSearchFilters method on the List class.

A global search that you could opt lists into (maybe with a globalSearch: true option) sounds like a neat feature to add for header search (maybe a new method on keystone itself called globalSearch(query)). We could add that to Admin UI in the header and homepage as well.

Keen to hear more about what you've got in mind.

Hey Jed,

Sorry about the delay. Had a very hectic week.

What I meant by page was actually a list. So whenever you have a list of content you could have a search feature for those who are not logged in. And/or maybe one on the header as well. My ideas was, the header would work like a global search while the one located in each list would be limited to that particular content type.

Also, do you mind sharing your plans for future updates? I was thinking it'd pretty neat to have mark down editor with integrated code highlighter. Hence my question as to where you want to go with Keystone. Do you plan to proceed as a framework or as a full-on cms?

Cheers
Wagner

Hi Wagner,

No problems - same here.

It sounds like a good idea. I'd also like to make the list search available on the Item Details screen (see #97) - maybe we could 'borrow' GitHub's idea of a single search field that searches the current list by default, but lets you search other / all lists.

As for future plans, I'm happy to share, and should probably write them up properly in an issue or the wiki. But briefly,

Now that the basic functionality is stabilising we're going to be focusing more on improving the Admin UI, as well as the documentation and getting started experience.

We think that Keystone can, if we do it right, be a great framework _and_ cms. The idea is to build the Admin UI up to provide a great user experience for editing content, and possibly support special interfaces for common content types (such as blog posts or pages), while also leaving it modular enough that it still provides a lot of useful framework-style features for projects that don't use the Admin UI much (or at all; Keystone can be used without it).

There is a page-content feature in the works, as well as front-end editing features, and aside from the content editing experience, we're also planning to make it better for filtering and reporting on data.

Another thing I'm really keen on is getting a good system in place for quickly creating new projects from templates, and a command line utility to scaffold new models, views / etc. I've been looking at yeoman for this...

I really like your idea about the markdown editor - there is a markdown field available, and it'd be great to improve the writing experience for that.

If you're any good with photoshop, any chance you can sketch up a concept of what you've got in mind?

Cheers,
Jed.

Hi JedWatson
i want to add search on frontend for posts.
can u help me how can i do this.

Any update on this?

@JedWatson @WagnerMatos any updates on this one? Allowing the users to search on the front end is a feature that most blogs need. If there's no work on this issue, could someone point me out to the place in which I could manually add indexes to the underlying mongodb collections and use mongo's built in search?

keystone.list('Post').model.find({
  title: new RegExp('^'+req.body.search+'$', "i")
}, function(err, results) {
  // Do your action here..
  locals.data.locations = results;
  if (results == ''){
    locals.data.invalid = 'Invalid search';
  }
  next(err);
});

@alterx to add indexes you do that in the mongoshell or programmatically in some init code for your project.

@morenoh149 thanks, yeah. Just wanted to know if there麓s some place in which, by convention, that code should go however I think I麓ll try @Nitish27麓s code first. The site is small and that should suffice.
Thanks guys.

We're closing all feature requests to keep the issue tracker unpolluted. From now on submit feature requests on productpains.com!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

schybo picture schybo  路  3Comments

christroutner picture christroutner  路  4Comments

celiao picture celiao  路  4Comments

josephg picture josephg  路  4Comments

webteckie picture webteckie  路  5Comments