Jump to content

Free text search field, best way to search page selector text


cb2004
 Share

Recommended Posts

I haven't used the search in ProcessWire yet, but I have a project coming up that will require it. It is kind of an ecommerce setup where the product has options like manufacturer, colour, size etc. These are managed by the client using a page structure of:

- Options

  - Manufacturers

    - Manufacturer

    - Manufacturer

When a product is added these options are then selected using page selectors. On the site there is a requirement for the search field (text), however I am thinking as the options will not appear in the actual product data (red, blue, small, large), they will just be id's to relate to the pages, the products will not appear in the search results. So my thought process is this, hook into save and populate a text field with csv (Search tags) all of the text from the selected results e.g. red, small, then when somebody searches for red, the products will appear.

Does that sound like the best way?

Link to comment
Share on other sites

Hi, I always find searching a tricky topic. Depending on the requirements you might even want to consider using a 3rd party search engine for much better results.

However, if you have a clear page structure and you only want to search a specific field in a page selector field. You should be able to just use it like this for example:

$items = $pages->find("template=product, options.title*='red'"); //assuming "options" is the page selector field and you want to search the title

And even if it is more complex you might consider using sub-selector or (since 3.x) even nested selectors as described here: https://processwire.com/api/selectors/#sub-selectors

I hope this helps

Link to comment
Share on other sites

Yeah, I always find a text field as a search an odd one, is the user expected to know what to search for. But thats what the client wants. There is also no textarea fields for the products which means its harder to search for keywords.

I think my idea could work, so the user would type in "red" as their search and any products with "red" in the field search_tags would show up. This fields data could be:

red, blue, small, large, manufacturer

Link to comment
Share on other sites

That's not necessarily what I meant. Your solution should work too, but I think you don't need to do this extra copying.

$items = $pages->find("template=product, title|body|options.title*=$freetext); 

E.g. if the user searched red, you can search within the fields of the product itself (e.g. title and body), aswell as in the fields of pages from the pageselector (e.g. options.title).
This should be what you are looking for or did I miss something?

What I meant regarding usage of 3rd party search is mainly regarding typos, result preview text and similar things that are offered e.g. when searching with google and co.

  • Like 2
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...