Jump to content

Prioritizing certain fields in search


canwild
 Share

Recommended Posts

Hi all,

I'm looking for an elegant way to prioritize certain fields in search. Basically, a search for "pizza" should return a page titled pizza before a page with pizza somewhere deep in the text. What do you recommend? Thanks!

		$q = wire('input')->get('q');
		$q = wire('sanitizer')->text($q);
		if($q) {
			$q = wire('sanitizer')->selectorValue($q);
			$selector = "title|summary|textarea|text|citation_author|citation_book|citation_publisher*+=$q";
			$results = $results->filter($selector);
		} else {
			//
		}	

 

Link to comment
Share on other sites

@canwild I think the way to go is to have multiple selectors

// selectors
$selector_title = "title%=$q";
$selector_summary = "summary%=$q";

// do the search

// make matches unique
$matches_summary->removeItems($matches_title);
$matches_title->import($matches_summary);

 

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...