Forum
Search Function - From path not working correctly
Hi there,
On my site my root directories are REGIONs i.e
- /en-eu
- /en-us
This is defined globally in my config file like so
$explode = explode('/', $_SERVER["REQUEST_URI"]);
define('REGION', $explode[1]);
On my search page I have this script. So it only searches pages based on the from path which is the REGION.
PerchSystem::set_var('home', REGION);
$query = perch_get('q');
perch_content_search($query, [
'count'=>10,
'from-path'=> '/'.REGION,
]);
My template is pretty much the same as the default
<perch:before>
<header>
<h1 class="block-heading block-heading--grey block-heading--news a350 gamma">
<perch:if exists="paging"><perch:search id="total" /> - </perch:if>Search results for “<perch:search id="search_key" />”
</h1>
</header>
<div class="news-article news-article__search">
</perch:before>
<div class="<perch:search id="perch_item_odd" />">
<h2><a href="<perch:search id="result_url" />"><perch:search id="result_title" /></a></h2>
<perch:if exists="result_excerpt"><p class="excerpt">…<perch:search id="result_excerpt" encode="false" />…</p></perch:if>
</div>
<perch:after>
<perch:if exists="paging">
<div class="paging">
Page <perch:search id="current_page" /> of <perch:search id="number_of_pages" />
<perch:if exists="not_first_page">
<a href="<perch:search id="prev_url" encode="false" />">Previous</a>
</perch:if>
<perch:if exists="not_last_page">
<a href="<perch:search id="next_url" encode="false" />">Next</a>
</perch:if>
</div>
</perch:if>
</div>
<div class="social-sharing">
<h3 class="c700 zeta caps primary">Share this post</h3>
<span class='st_facebook_large' displayText='Facebook'></span>
<span class='st_twitter_large' displayText='Tweet'></span>
<span class='st_linkedin_large' displayText='LinkedIn'></span>
</div>
</perch:after>
<perch:noresults>
<perch:if exists="search_key">
<header>
<h1 class="block-heading block-heading--grey block-heading--news a350 gamma">Search results for “<perch:search id="search_key" />”</h1>
</header>
<perch:else />
<header>
<h1 class="block-heading block-heading--grey block-heading--news a350 gamma">Search</h1>
</header>
</perch:if>
<perch:if exists="search_key">
<p>Sorry, there are no results for “<perch:search id="search_key" />”.</p>
</perch:if>
</perch:noresults>
In my DEBUG message I cant find any reference to other regions, but in the search results there are some results which are from another region
Debug Message [74] SELECT p.pagePath, pr.routePattern, pr.routeRegExp, p.pageTemplate FROM perch2_pages p LEFT JOIN perch2_page_routes pr ON p.pageID=pr.pageID ORDER BY pr.routeOrder ASC, p.pagePath ASCMatched page: /en-eu/search, so not using routes.Using master page: /templates/pages/search.php [1] SELECT * FROM perch2_pages WHERE pagePath='/en-eu/search' LIMIT 1Using template: /templates/pages/attributes/language_code.htmlUsing template: /templates/pages/attributes/language_code.htmlUsing template: /templates/pages/attributes/language_code.htmlUsing template: /templates/pages/attributes/language_code.htmlUsing template: /templates/pages/attributes/seo.htmlUsing template: /templates/pages/attributes/body_attributes.html [1] SELECT pageID, pageParentID, pageDepth, pageTreePosition FROM perch2_pages WHERE pagePath='/en-eu' OR pageSortPath='/en-eu' LIMIT 1 [10] SELECT * FROM perch2_pages WHERE pageNew=0 AND pageHidden=0 AND pageTreePosition LIKE '000-004%' AND pageDepth >=1 AND pageDepth<=3 ORDER BY pageTreePosition ASC [1] SELECT pageTreePosition FROM perch2_pages WHERE pagePath='/en-eu/search' LIMIT 1 [2] SELECT pageID FROM perch2_pages WHERE pageTreePosition IN ('000-004-008', '000-004', '000') ORDER BY pageTreePosition DESCUsing template: /templates/navigation/nav.html [4] Using template: /templates/navigation/subnav.htmlUsing template: /templates/search/search-form.html [1] SELECT groupID FROM perch2_navigation WHERE groupSlug='europe' LIMIT 1 [10] SELECT np.pageID, np.pageParentID, p.pagePath, p.pageTitle, p.pageNavText, p.pageNew, p.pageOrder, np.pageDepth, p.pageSortPath, np.pageTreePosition, p.pageAccessTags, p.pageAttributes FROM perch2_navigation_pages np, perch2_pages p WHERE p.pageID=np.pageID AND np.groupID=2 AND p.pageNew=0 AND np.pageDepth >=0 AND np.pageDepth<=1 ORDER BY np.pageTreePosition ASC [0] SELECT np.pageTreePosition FROM perch2_pages p, perch2_navigation_pages np WHERE np.pageID=p.pageID AND np.groupID=2 AND p.pagePath='/en-eu/search' LIMIT 1 [10] Using template: /templates/navigation/choose_region.html [1] SELECT groupID FROM perch2_navigation WHERE groupSlug='north-america' LIMIT 1 [3] SELECT np.pageID, np.pageParentID, p.pagePath, p.pageTitle, p.pageNavText, p.pageNew, p.pageOrder, np.pageDepth, p.pageSortPath, np.pageTreePosition, p.pageAccessTags, p.pageAttributes FROM perch2_navigation_pages np, perch2_pages p WHERE p.pageID=np.pageID AND np.groupID=3 AND p.pageNew=0 AND np.pageDepth >=0 AND np.pageDepth<=1 ORDER BY np.pageTreePosition ASC [0] SELECT np.pageTreePosition FROM perch2_pages p, perch2_navigation_pages np WHERE np.pageID=p.pageID AND np.groupID=3 AND p.pagePath='/en-eu/search' LIMIT 1 [3] Using template: /templates/navigation/choose_region.html [1] SELECT groupID FROM perch2_navigation WHERE groupSlug='south-america' LIMIT 1 [1] SELECT np.pageID, np.pageParentID, p.pagePath, p.pageTitle, p.pageNavText, p.pageNew, p.pageOrder, np.pageDepth, p.pageSortPath, np.pageTreePosition, p.pageAccessTags, p.pageAttributes FROM perch2_navigation_pages np, perch2_pages p WHERE p.pageID=np.pageID AND np.groupID=4 AND p.pageNew=0 AND np.pageDepth >=0 AND np.pageDepth<=1 ORDER BY np.pageTreePosition ASC [0] SELECT np.pageTreePosition FROM perch2_pages p, perch2_navigation_pages np WHERE np.pageID=p.pageID AND np.groupID=4 AND p.pagePath='/en-eu/search' LIMIT 1 [1] Using template: /templates/navigation/choose_region.html [1] SELECT groupID FROM perch2_navigation WHERE groupSlug='asia' LIMIT 1 [1] SELECT np.pageID, np.pageParentID, p.pagePath, p.pageTitle, p.pageNavText, p.pageNew, p.pageOrder, np.pageDepth, p.pageSortPath, np.pageTreePosition, p.pageAccessTags, p.pageAttributes FROM perch2_navigation_pages np, perch2_pages p WHERE p.pageID=np.pageID AND np.groupID=5 AND p.pageNew=0 AND np.pageDepth >=0 AND np.pageDepth<=1 ORDER BY np.pageTreePosition ASC [0] SELECT np.pageTreePosition FROM perch2_pages p, perch2_navigation_pages np WHERE np.pageID=p.pageID AND np.groupID=5 AND p.pagePath='/en-eu/search' LIMIT 1 [1] Using template: /templates/navigation/choose_region.htmlSearch term: Foodservice [29] SELECT DISTINCT settingID, settingValue FROM perch2_settings WHERE userID=0 [10] SELECT SQL_CALC_FOUND_ROWS DISTINCT 'PerchContent_SearchHandler' AS source, MATCH(ci.itemSearch) AGAINST('Foodservice') AS score, r.regionPage AS col1, ci.itemSearch AS col2, ci.itemJSON AS col3, r.regionOptions AS col4, p.pageNavText AS col5, p.pageTitle AS col6, regionTemplate AS col7, r.regionKey AS col8 FROM perch2_content_regions r, perch2_content_items ci, perch2_pages p WHERE r.regionID=ci.regionID AND r.regionRev=ci.itemRev AND r.pageID=p.pageID AND r.regionPage!='*' AND r.regionSearchable=1 AND (MATCH(ci.itemSearch) AGAINST('Foodservice') OR MATCH(ci.itemSearch) AGAINST('Foodservice') ) AND r.regionPage LIKE '/en-eu%' UNION SELECT 'PerchContent_RunwaySearch' AS source, MATCH(ci.itemSearch) AGAINST('Foodservice') AS score, c.collectionKey AS col1, ci.itemSearch AS col2, ci.itemJSON AS col3, c.collectionOptions AS col4, c.collectionKey AS col5, c.collectionKey AS col6, collectionTemplate AS col7, c.collectionKey AS col8 FROM perch2_collections c, perch2_collection_items ci, perch2_collection_revisions cr WHERE c.collectionID=cr.collectionID AND cr.itemID=ci.itemID AND cr.itemRev=ci.itemRev AND c.collectionSearchable=1 AND cr.itemSearchable=1 AND (MATCH(ci.itemSearch) AGAINST('Foodservice') OR MATCH(ci.itemSearch) AGAINST('Foodservice') ) UNION SELECT 'PerchBlog_SearchHandler' AS source, MATCH(postTitle, postDescRaw, postTags) AGAINST('Foodservice') AS score, postTitle, postSlug, postDateTime, postDescHTML, postID, sectionSlug, "", "" FROM perch2_blog_posts p, perch2_blog_sections s WHERE postStatus='Published' AND postDateTime<'2016-02-18 15:41:14' AND p.sectionID=s.sectionID AND MATCH(postTitle, postDescRaw, postTags) AGAINST('Foodservice') ORDER BY score DESC LIMIT 0, 10 [75] SELECT FOUND_ROWS() AS `count` [10] Using template: /templates/search/search-result.html [1] SELECT blogID FROM perch2_blogs WHERE blogSlug='en-eu' LIMIT 1 [4] SELECT SQL_CALC_FOUND_ROWS DISTINCT tbl.* FROM ( SELECT idx.itemID, main.*, idx2.indexValue as sortval FROM perch2_blog_index idx JOIN perch2_blog_posts main ON idx.itemID=main.postID AND idx.itemKey='postID' JOIN perch2_blog_index idx2 ON idx.itemID=idx2.itemID AND idx.itemKey='postID' AND idx2.indexKey='_id' WHERE 1=1 AND ((idx.indexKey='postSlug' AND idx.indexValue != '')) AND idx.itemID=idx2.itemID AND idx.itemKey=idx2.itemKey GROUP BY idx.itemID, idx2.indexValue ) as tbl WHERE ( blogID=3 AND postStatus='Published' AND postDateTime<='2016-02-18 15:41:00' ) GROUP BY itemID, sortval ORDER BY sortval ASC LIMIT 0, 4 [1] SELECT FOUND_ROWS() AS `count` [4] Using template: /templates/blog/post_sidebar.html [1] SELECT * FROM perch2_blog_sections ORDER BY sectionTitle ASC [3] SELECT * FROM perch2_blogs ORDER BY blogTitle ASCUsing template: /templates/pages/attributes/twitter_name.html [1] SELECT * FROM perch2_twitter_tweets WHERE tweetType='mine' AND tweetAccount='Chicopee_Europe' ORDER BY tweetDate DESC LIMIT 1 [1] Using template: /templates/twitter/tweet.html [1] SELECT regionID, regionTemplate, regionPage, regionRev AS rev FROM perch2_content_regions WHERE regionKey='Telephone en-eu' AND (regionPage='/en-eu/search' OR regionPage='*') [1] SELECT * FROM ( SELECT idx.itemID, c.regionID, idx.pageID, c.itemJSON, idx2.indexValue as sortval FROM perch2_content_index idx JOIN perch2_content_items c ON idx.itemID=c.itemID AND idx.itemRev=c.itemRev AND idx.regionID=c.regionID JOIN perch2_content_index idx2 ON idx.itemID=idx2.itemID AND idx.itemRev=idx2.itemRev AND idx2.indexKey='_order' WHERE ((idx.regionID=173 AND idx.itemRev=5)) AND idx.itemID=idx2.itemID AND idx.itemRev=idx2.itemRev ) as tbl GROUP BY itemID, pageID, itemJSON, sortval ORDER BY sortval ASC [1] Using template: /templates/content/text.html [1] SELECT pageID, pageParentID, pageDepth, pageTreePosition FROM perch2_pages WHERE pagePath='/en-eu' OR pageSortPath='/en-eu' LIMIT 1 [8] SELECT * FROM perch2_pages WHERE pageNew=0 AND pageTreePosition LIKE '000-004%' AND pageDepth >=1 AND pageDepth<=2 ORDER BY pageTreePosition ASC [1] SELECT pageTreePosition FROM perch2_pages WHERE pagePath='/en-eu/search' LIMIT 1 [2] SELECT pageID FROM perch2_pages WHERE pageTreePosition IN ('000-004-008', '000-004', '000') ORDER BY pageTreePosition DESC [7] Using template: /templates/navigation/item.html [1] SELECT pageID, pageParentID, pageDepth, pageTreePosition FROM perch2_pages WHERE pagePath='/en-eu/segments' OR pageSortPath='/en-eu/segments' LIMIT 1 [7] SELECT * FROM perch2_pages WHERE pageNew=0 AND pageHidden=0 AND pageTreePosition LIKE '000-004-003%' AND pageDepth >=2 AND pageDepth<=3 ORDER BY pageTreePosition ASC [1] SELECT pageTreePosition FROM perch2_pages WHERE pagePath='/en-eu/search' LIMIT 1 [2] SELECT pageID FROM perch2_pages WHERE pageTreePosition IN ('000-004-008', '000-004', '000') ORDER BY pageTreePosition DESC [6] Using template: /templates/navigation/item.html [1] SELECT regionID, regionTemplate, regionPage, regionRev AS rev FROM perch2_content_regions WHERE regionKey='Social en-eu' AND (regionPage='/en-eu/search' OR regionPage='*') [1] SELECT * FROM ( SELECT idx.itemID, c.regionID, idx.pageID, c.itemJSON, idx2.indexValue as sortval FROM perch2_content_index idx JOIN perch2_content_items c ON idx.itemID=c.itemID AND idx.itemRev=c.itemRev AND idx.regionID=c.regionID JOIN perch2_content_index idx2 ON idx.itemID=idx2.itemID AND idx.itemRev=idx2.itemRev AND idx2.indexKey='_order' WHERE ((idx.regionID=170 AND idx.itemRev=4)) AND idx.itemID=idx2.itemID AND idx.itemRev=idx2.itemRev ) as tbl GROUP BY itemID, pageID, itemJSON, sortval ORDER BY sortval ASC [1] Using template: /templates/content/footer/social.htmlRequest time: 1.0489Process time: 1.0471Memory: 5.9056 - See more at: https://chico.pee/en-eu/search?q=Foodservice#sthash.dI4oMiZ1.dpuf
So in this example I am searching within the REGION /en-eu
but in the search results there is some results with /en-us
https://www.awesomescreenshot.com/image/1008933/ce89b60bc595daf96f13304079fad685
Any ideas why this would be?
Regarding products, Each REGION have their own product collections
and I have configured them within the collection options like so
https://www.awesomescreenshot.com/image/1008973/cfa11fdc926a5b8fe89bd32eba58ed78
The above is the
en-us
collection so foren-eu
its the same except for the root path its changes toen-eu
Is the data in a collection? Collections aren't filtered by path as they exist outside of a path. I guess we could add an option to filter against the single item path - that would make sense.
Yes, all product data are within collections. Yes this would help us out massively.
I've logged that as an enhancement request.