Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2015-04-02 15:18:23

towndock
Member
From: Oriental, NC USA
Registered: 2007-04-06
Posts: 333
Website

keyword phrases / or ignoring the comma

I have a site with place names like:

Tarrytown, NY

I’d like it to also come up in a search for “Tarrytown NY”, “Tarrytown, New York” and “Tarrytown New York”

The TXP keyword list is comma delimited. How can I add phrases that include a comma?

OR

How can I get TXP search results to simply ignore the comma – returning the same result whether a comma is there or not.

Offline

#2 2015-04-02 15:30:16

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,793
Website GitHub

Re: keyword phrases / or ignoring the comma

Without some PHP, I think you might have reached the limit of the rudimentary built-in search / keywords system in this instance (unless someone wants to prove me wrong). If you’re not above using a plugin, may I offer etc_search?


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Online

#3 2015-04-02 15:31:51

maniqui
Member
From: Buenos Aires, Argentina
Registered: 2004-10-10
Posts: 3,070
Website

Re: keyword phrases / or ignoring the comma

Another approach could be to remove the comma using JS, just before submitting the form.


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#4 2015-04-02 15:50:24

towndock
Member
From: Oriental, NC USA
Registered: 2007-04-06
Posts: 333
Website

Re: keyword phrases / or ignoring the comma

Bloke wrote #289685:

If you’re not above using a plugin, may I offer etc_search?

Stef, I’m not above using a hammer, much less a plugin. I’ll try it. I’m already using your smd_fuzzyfind plugin. It works great if you actually misspell – but the comma thing still returns “no results match”.

maniqui wrote #289686:

Another approach could be to remove the comma using JS, just before submitting the form.

If the plugin won’t do it, I’ll examine that approach (although I’m not smart enough to make it happen easily).

Offline

#5 2015-04-02 19:05:08

philwareham
Core designer
From: Haslemere, Surrey, UK
Registered: 2009-06-11
Posts: 3,564
Website GitHub Mastodon

Re: keyword phrases / or ignoring the comma

I was thinking about this very thing earlier today. I use the keywords field for meta descriptions in a couple of sites, because I’m adverse to using plugins unless I really have to. It would be nice to have the option (possibly a core attribute on the txp:keywords tag) that allows commas to be used in this field if an author so wishes.

Offline

#6 2015-04-02 19:19:01

towndock
Member
From: Oriental, NC USA
Registered: 2007-04-06
Posts: 333
Website

Re: keyword phrases / or ignoring the comma

philwareham wrote #289693:

It would be nice to have the option (possibly a core attribute on the txp:keywords tag) that allows commas to be used in this field if an author so wishes.

That would be really nice.

Offline

#7 2015-04-02 20:40:41

etc
Developer
Registered: 2010-11-11
Posts: 5,396
Website GitHub

Re: keyword phrases / or ignoring the comma

I’m not sure removing/ignoring the comma would help. The main problem is converting Tarrytown New York to Tarrytown, NY. How a simple script would know that Las Vegas Nevada should be Las Vegas, NV, and not Las, VN? Your best option is to separate city from state, I think, but if the site already exists, you can pass users input through something like maps.googleapis.com/maps/api/geocode/json?address=Tarrytown+New+York, to get a standard representation.

Edit: also note that Tarrytown, NY will be stored as Tarrytown,NY (without space) in the Keywords field.

Last edited by etc (2015-04-02 21:40:11)

Offline

#8 2015-04-03 13:07:24

towndock
Member
From: Oriental, NC USA
Registered: 2007-04-06
Posts: 333
Website

Re: keyword phrases / or ignoring the comma

etc wrote #289696:

I’m not sure removing/ignoring the comma would help.

I think it would, although you clearly have better knowledge of how Textpattern works under the hood than I. In the example, the title includes Tarrytown, NY. I can put Tarrytown NY and Tarrytown New York as phrases in keywords. But I can’t put Tarrytown, New York in – because one can’t include a comma in the keywords.

If the search simply ignored the comma, both the above problem is solved, and I would need fewer keyword entries (half). The site I’m working on has thousands of entries, so that becomes a rather huge victory.

Can etc_search be set to ignore the comma?

Last edited by towndock (2015-04-03 13:09:14)

Offline

#9 2015-04-03 15:34:08

etc
Developer
Registered: 2010-11-11
Posts: 5,396
Website GitHub

Re: keyword phrases / or ignoring the comma

towndock wrote #289711:

I can put Tarrytown NY and Tarrytown New York as phrases in keywords. If the search simply ignored the comma, both the above problem is solved, and I would need fewer keyword entries (half).

Put like this, yes, it will work. I thought you had the keywords already filled with Tarrytown, NY entries and minded changing it.

Can etc_search be set to ignore the comma?

It can, but you could first try a JS approach (uses jQuery):

<script>
(function($){
	$input = $('input[name="q"]');
	$input.parent("form").on("submit", function() {
		$input.val($input.val().replace(/\W+/g, ' '))
	});
})(jQuery);
</script>

This will replace all non-literal character chains with a space. Note that txp does not search in keywords (only title and body), you will need to install wet_haystack or similar.

Offline

Board footer

Powered by FluxBB