eelkenet Posted January 26, 2015 Share Posted January 26, 2015 Hi all, I'm not sure how to proceed on the following. I have a ajax-driven search working on my site, which works like a charm. My site is a historic overview and as such content-rich site about cities/villages (template: areas) and it's children: locations (homes, churches, etc) located in those areas. (Sadly I can't show off the site yet, but the release is getting closer and closer.) My query is the following: $matches = $pages->find("title|body|short|keyword|photos.description|remarks*=$q, limit=50, template=area|location, sort=template"); I currently loop through the pages, displaying the title and the short fields. However, the result of this may be that a user has no idea how his search for city A can yield city B showing up in the list, while not showing as to why this happened. (Technically this can happen when city A is mentioned in the body text of city B.) This can be very confusing for people, who are very used to Google's way of returning results. So I would like to be able to show the bit of the body text which shows the query instead of the short, whenever this is applicable. Is there a way to know which part of full query resulted it showing up in the search results? Or should I split up my query into separate ones? And/or should I do some regex magic on all the returned fields to figure out which bit contains the query? Thank you for your thoughts. Link to comment Share on other sites More sharing options...
verdeandrea Posted March 9, 2015 Share Posted March 9, 2015 I'm also interested in this topic. Did you find a solution? Can anyone suggest a solution? Thanks! Link to comment Share on other sites More sharing options...
LostKobrakai Posted March 9, 2015 Share Posted March 9, 2015 I'd go with something like this: foreach($matches as $match){ foreach(["title", "body", "short", "keyword", …] as $field){ if($match->is("$field*=$q")){ $textposition_in_field[] = array($field => strpos($match->$field, $q)); } } } After that one can decide which textposition will be the most important. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now