WordPress.org

Make WordPress Core

Opened 9 years ago

Closed 5 years ago

Last modified 2 years ago

#1435 closed enhancement (fixed)

Pages should be searched

Reported by: markjaquith Owned by:
Milestone: 2.5 Priority: high
Severity: major Version: 2.3
Component: General Keywords: trac-irrelivent search pages static needs-patch
Focuses: Cc:

Description

Include 'static' pages in search results

Attachments (1)

classes.php.diff (471 bytes) - added by markjaquith 9 years ago.
Allows searches on pages

Download all attachments as: .zip

Change History (28)

markjaquith9 years ago

Allows searches on pages

comment:1 Nazgul8 years ago

  • Keywords dev-feedback added
  • Milestone set to 2.1

There are plugins out there which do this. Do we want it in core?

comment:2 foolswisdom8 years ago

  • Cc foolswisdom added

+1 I think it is most people's expectation that pages are searched by default, so I would like to see it in core.

comment:3 skeltoac8 years ago

Yes, it should. The last time we discussed this, the problem of how to display results with both posts and pages was never solved.

Any implementation is better than no implementation?

comment:4 markjaquith8 years ago

  • Milestone changed from 2.1 to 2.2

I reported this and wrote that patch, but no, I don't agree that any implementation is better than no implementation.

Sticking pages within the post results (interspersed) doesn't seem right.

In fact, any good implementation is going to require theme changes, as right now all we can do is stick the pages into the loop.

Two approaches I see:

A switch to search posts or pages, defaulting to posts. We could make a new template file: page-search.php, and the Default and Classic themes can show our ideal implementation of page search results. Then it would be up to theme authors to create their own implementations.

Unified searching, but using two WP_Query instances. We could run the query made for posts again, searching for pages. $page_search = new WP_Query('foo'); Then in search.php, we would have a second loop. Maybe it could be up at the top, styled differently, only showing titles. Again, it would be up to theme authors to implement that.

It's one of those things where everyone agrees that we should have it, but no one really knows the best way to do it... :-\

2.2 milestone sounds better. We're not even past the idea stage here.

comment:5 andy8 years ago

Third option:

Search does not discriminate between posts and pages. Instead of sorting by date, it sorts by relevance. This is more like what search engines have trained people to expect.

Sorting by date excludes pages.

comment:6 markjaquith8 years ago

I like that.

Search algorithms aren't my thing... but doesn't searching by relevance require more than LIKE '%foo%' queries? Are there any GPL projects with advanced searching that we might emulate?

comment:7 majelbstoat8 years ago

If there are fulltext indices on post_content and post_title, you can do a MySQL MATCH() query:

SELECT * FROM wp_posts WHERE MATCH(post_content, post_title) AGAINST('my string to search for');

which returns in order of relevance descending (best first), or to do the same, but also get the relevance (so you can generate 98% match etc):

SELECT p.*, MATCH (post_title, post_content) AGAINST ('My search string') AS score FROM wp_posts AS p WHERE MATCH (post_title, post_content) AGAINST ('My search string');

All this should be valid for MySQL 3.23.23+

More info at:

http://dev.mysql.com/doc/refman/4.1/en/fulltext-search.html

comment:8 foolswisdom7 years ago

  • Milestone changed from 2.2 to 2.3

This is the 5th highest rated WordPress idea: http://wordpress.org/extend/ideas/topic.php?id=19

comment:9 foolswisdom7 years ago

  • Priority changed from normal to high
  • Severity changed from normal to critical

comment:10 follow-up: Otto427 years ago

I don't see why having them in the loop is such a big deal. We put trackbacks and pingbacks in the comments loop. Most themes don't bother to separate them, although they could do it via CSS, since the information is available as part of the comment ($comment_type).

Similarly, if search returns pages in the loop, then the theme can choose whether or not to separate them out based on $post->post_type.

We should not lock themes into doing it only one way. Stick the results in the loop. Themes can determine for themselves whether or not to display it. If you like, make the search default to returning only posts unless there's a "searchpages=true" hidden parameter or something. Again, this leaves it up to the theme (or at least, the search form).

comment:11 in reply to: ↑ 10 ; follow-up: westi7 years ago

Replying to Otto42:

I don't see why having them in the loop is such a big deal. We put trackbacks and pingbacks in the comments loop. Most themes don't bother to separate them, although they could do it via CSS, since the information is available as part of the comment ($comment_type).

Putting them in the loop for a search that returns results in date order is bad because they don't have a correct place in that type of ordering as they are by the nature not date related.

Trackbacks and Pingbacks are subtypes of comment - they are just other ways of commenting on a post. A Page is much less similar to a port than that.

I like andys suggestion of search results returning sorted by relevence and then encouraging people to add good search result templates to there themes.

comment:12 Otto427 years ago

Well, then don't limit them to date order either. I like the notion of the relevance order above as well. But optional, of course, as some people won't like that. Perhaps an optional "order=whatever" field to the search form...

More to the point, you're thinking of the Loop as returning a big list of results in a specific order. But the theme can rewind those results and replay them if necessary. If a theme wants to move the Page results to the top, they just write two Loops. The first one only spits out the post_type='page' results, the second one rewinds and then spits out the rest.

comment:13 zamoose7 years ago

  • Severity changed from critical to major
  • Version changed from 1.5.1.1 to 2.3

Bumping this back into contention for inclusion in 2.3 as per the current thread on the mailing list.

There are some great ideas in this ticket thread.

comment:14 johnbillion7 years ago

If any additional parameters were to be sent with the search term it would make it harder to create pretty URLs of search results.

rob1n has been working on a system allowing for customisation and i18n of all the pretty permalinks bases at ticket #1762 . It would be nice to get this in.

comment:15 johnbillion7 years ago

Whoops, went a bit off-topic there. What I meant is creating pretty URLs from search results needs to remain a consideration however the searching of pages is implemented.

comment:16 in reply to: ↑ 11 strider727 years ago

Replying to westi:

Replying to Otto42:

I don't see why having them in the loop is such a big deal. We put trackbacks and pingbacks in the comments loop. Most themes don't bother to separate them, although they could do it via CSS, since the information is available as part of the comment ($comment_type).

Putting them in the loop for a search that returns results in date order is bad because they don't have a correct place in that type of ordering as they are by the nature not date related.

So include them separately somehow. Start with "Undated" and then show "Dated", (kind of like Google's "sponsored results" are separated from regular results). Presumably part of the Theme, but do it this way in the default themes and show people the way :)

No doubt in my mind pages should be included in searches. I hadn't realized there weren't!

comment:17 Nazgul7 years ago

  • Keywords needs-patch added; dev-feedback removed
  • Milestone changed from 2.3 (trunk) to 2.4 (future)

comment:18 snakefoot7 years ago

Ideas for search #1176

comment:19 follow-up: thee176 years ago

  • Keywords trac-irrelivent added

According to http://codex.wordpress.org/Version_2.4 isnt this alread in core now?

comment:20 in reply to: ↑ 19 DD326 years ago

Replying to thee17:

According to http://codex.wordpress.org/Version_2.4 isnt this alread in core now?

Ref:

(In [6467]) Throw pages into search queries. Let's see how they handle. see #5149

comment:21 thee176 years ago

  • Resolution set to fixed
  • Status changed from new to closed

comment:22 jidm5 years ago

  • Cc jidm added
  • Milestone changed from 2.5 to 2.7.2
  • Resolution fixed deleted
  • Status changed from closed to reopened

Hi.

I seriously believe that there should be an option to choose between search on 'any' or 'post'. This could be changed from the admin panel.

In some projects i don't need/want to searh on pages, so i have to manually change 'any' for 'post on:

	if ( !isset($q['post_type']) ) {
			if ( $this->is_search )
				$q['post_type'] = 'any';
			else
				$q['post_type'] = 'post';

I think this can't be hard to implement (an option in the backend, a row in wp_options [maybe wp_blogs in case of wpmu] and a modification on the code above to ask for that option).

Please consider implementing this. It has been stuck like this since 2.4 and still is on 2.7.1

Thanks!

comment:23 johnbillion5 years ago

  • Resolution set to fixed
  • Status changed from reopened to closed

jidm, please open a new Trac ticket for your request as it's separate to this issue which was implemented.

comment:24 johnbillion5 years ago

  • Milestone 2.7.2 deleted

comment:25 DD325 years ago

  • Milestone set to 2.5

comment:26 bestbooker2 years ago

.

Last edited 2 years ago by duck_ (previous) (diff)

comment:27 Anton Torvald2 years ago

.

Last edited 2 years ago by Otto42 (previous) (diff)
Note: See TracTickets for help on using tickets.