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

Design keyword based search for frontpage #684

Closed
18 tasks done
bajiat opened this issue Dec 4, 2015 · 10 comments
Closed
18 tasks done

Design keyword based search for frontpage #684

bajiat opened this issue Dec 4, 2015 · 10 comments
Assignees

Comments

@bajiat
Copy link
Contributor

bajiat commented Dec 4, 2015

Related to issue #629.

Definition of done

Frontpage

  • There is a search field prominently visible on frontpage.
  • Search field contains meaningful helptext.
  • Search fields queries API backend collection.
    • Query uses API backend title field.
    • Query uses API backend backend_host field. - ?
  • All search query fields are indexed.
  • Search query is case insensitive.
  • Search query accepts arbitrary length string, which can contain spaces.

Results page

  • Search results are displayed on a new page
  • Page has its own route.
    • Page route contains the search keyword(s)
  • Page displays search query texts
  • Page displayes number of results
  • Page display search field (open items: does it contain the current search query)

Search results

  • Individual results are listed separately.
  • Result contains title text.
    • Title text displays prominently.
    • Title text links to View API backend.
@bajiat
Copy link
Contributor Author

bajiat commented Dec 7, 2015

@frenchbread Since you were interested in the implementation task, could you take the design as well? Refer to #629 for original idea.

@frenchbread
Copy link
Contributor

Wireframe:

Search field is displayed on each page in the header.

search

@frenchbread
Copy link
Contributor

There are going to be two scenarios how to make a search for API Backends:

  1. Using search field on the home page - wireframe.
  2. Using search field in the header - wiraframe.

One of the approaches is to follow this guide provided in the README and use separate mongodb instance rather than build in meteor mongo. As mentioned in repo above:

By default, Meteor starts up its own instance of MongoDB, this does not have full-text indexing/search

Second is to build own method with a complex query:

return ApiBackends.find(<query_object>);

In example provided query_object takes name as a main key:

return ApiBackends.find({ "name": /maps/ }); 

// Returns an array ob objects with a name that contains "maps" word in it

Example above is case sensitive though, for that reason could use extended approach, e.g.:

return ApiBackends.find({ "name": /^maps$/i }); 

Or using RegEx by providing an object with a $regex operator:

return ApiBackends.find({ "name": { $regex : '^maps$' } }); // case INSENSITIVE

Source

@frenchbread
Copy link
Contributor

One useful feature:

Once search is submitted, and if the search query 100% matches the apiBackend (or only one document was returned), we can redirect user directly to that API Backend View page.

@frenchbread
Copy link
Contributor

Mongo query example that I came up with:

// Construct query
var query = {
  $or: [
    {
      name: {
        $regex: searchPhrase,
        $options: 'i'
      }
    },
    {
      backend_host: {
        $regex: searchPhrase,
        $options: 'i'
      }
    }
  ]
};

// Fetch apiBackends
var foundApiBackends = ApiBackends.find(query).fetch();

This example represents a search for <searchPhrase> in both name & backend_host fields.

$regex's i - option gives case-insensitivity (in Mongodb).

MongoDB - $regex docs.

Related commit - b4e83c7.

@frenchbread
Copy link
Contributor

Search functionality is implemented and works nicely.

Even though documents are returned, getting this error:

Exception from sub searchApiBackends id PR3nriYFkine3PFka Error: Publish function can only return a Cursor or an array of Cursors

I've been trying to fix it by adding waitOn for subscription function to a /search route but it did not fix the error.

@brylie Any thoughts?

working-branch

@brylie
Copy link
Contributor

brylie commented Dec 16, 2015

@frenchbread it looks like you return an empty object if there is not a search term, which is not a cursor.

Check out the Guide to Full Text Search in Meteor for a working implementation.

Make sure you are also indexing the fields for searching, using _ensureIndexed, which is also demonstrated in the previously mentioned article.

@frenchbread
Copy link
Contributor

@brylie Thanks! That helped to fix the issue.

@frenchbread
Copy link
Contributor

PR #719 created. Currently having WIP label on it.

I'm going to improve the visual design of search result returned on a search page with @elnzv's help.

@brylie brylie removed the APIKA label Dec 16, 2015
@frenchbread
Copy link
Contributor

Removed WIP label.

@apinf/developers please review.

@frenchbread frenchbread added this to the Sprint 18 milestone Dec 18, 2015
@bajiat bajiat modified the milestones: Sprint 19, Sprint 18 Dec 31, 2015
frenchbread added a commit that referenced this issue Dec 31, 2015
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

3 participants