• Hi there,

    I have a search form on one of my pages. I am having issues with search results that contain more than one word.

    It is set up as ‘Search Any Profile Field’ with ‘contains’ as the search mode.

    For instance, I have an industry field and a location field.

    If I type in for example ‘Manufacturing Glasgow’ there will be no results. If I type in Manufacturing on its own there are results. The same applies for Glasgow on its own.

    How can I get results to appear with two words entered in search field? I need it to return results that contain both words.

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author Andrea Tarantini

    (@dontdream)

    Hi kpkreative,

    If you search for Manufacturing Glasgow your results will contain that exact sequence of words and spaces.

    To get results containing one or both words, you can search for:

    Manufacturing OR Glasgow

    To get results containing both words, you can search for:

    Manufacturing AND Glasgow

    Please note that the AND and OR keywords must be in uppercase.

    Thread Starter kpkreative

    (@kpkreative)

    Thank you Andrea,

    I really appreciate your response.

    I have tested this and it seems to work, though there are less results than expected in results like it is possibly skipping some profile fields.

    Plugin Author Andrea Tarantini

    (@dontdream)

    Hello kpkreative,

    You’re very welcome! And of course if you have a member who should be in your search results but isn’t, I’ll be available to fix the problem.

    Thread Starter kpkreative

    (@kpkreative)

    Thanks for your response Andrea.

    Is there a simpler way for this search field without the need to add ‘AND’ between words, as it wouldn’t be how I would expect a user to search without being given instruction to.

    I was hoping for example the user could use for example ‘Manufacturing in Glasgow’ or ‘Manufacturing Glasgow’ to pull results for profiles containing both words.

    Plugin Author Andrea Tarantini

    (@dontdream)

    Hi kpkreative,

    I can suggest two possible workarounds to achieve what you need:

    1) Replace the AND keyword with a different text, adding a line to your bp-custom.php, for instance:

    define ('BPS_AND', ' in ');

    2) Filter the search request using the ‘bps_request’ hook, and insert the AND keyword between words. See line 36 in bps-search.php for details.

    Thread Starter kpkreative

    (@kpkreative)

    Hi Andrea,

    Thank you for your feedback and suggestions for change.

    My only concern using either methods, would depend on how the user reacts. For instance they may choose to type in ‘Word one’ in ‘Word two’ or just ‘Word one’ ‘Word Two’ without the ‘in’.

    Plugin Author Andrea Tarantini

    (@dontdream)

    Hi kpkreative,

    In this case probably the best solution is to filter the search request using the ‘bps_validate_field’ hook.

    If you find “wordone in wordtwo” you can replace it with “wordone AND wordtwo”, if you find “wordone wordtwo” you can replace it with “wordone AND wordtwo”, and if you find something you can’t handle you can even output an error message.

    For details, please see line 286 in bps-request.php.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘No return results for more than 1 word’ is closed to new replies.