The problem is, that the $doc.space doesn’t work and I have to add the space name directly (e.g. space_prefix:Test) and if there are spaces in the name I have to add a \ before the space (e.g. space_prefix:Test\ A).
Is there a possibility to get the script working with the $doc.space variable? Because I don’t want to edit the code when I copy it into another page or if I rename/move the page for some reason.
I myself wanted to have a space search and found your code to start with. I think I solved two of your problems. First my code:
{{include reference="XWiki.SearchCode"/}}
{{velocity}}
#set($docSpace = $doc.space)
## to search in siblings too uncomment next two lines and comment line above
##set($docSpace = $doc.parent)
##set($docSpace = $docSpace.replaceAll('.WebHome', ''))
## not sure whether this is the perfect escaping but it works w/ white space + dots in spaces
#set($docSpace = $escapetool.css($docSpace))
#if($searchEngine == 'solr')
#set ($solrConfig = {
'queryFields': {
'DOCUMENT': 'spaces^15.0
title^10.0 name^10.0
doccontent^2.0
objcontent^0.4 filename^0.4 attcontent^0.4 doccontentraw^0.4
author_display^0.08 creator_display^0.08
comment^0.016 attauthor_display^0.016',
'ATTACHMENT': 'filename^5.0 attcontent attauthor_display^0.2'
},
'filterQuery': [
"space_prefix:$docSpace",
"wiki:$doc.wiki"
]
})
#end
#if ("$searchPage" != '')
{{include reference="$searchPage"/}}
#end
{{/velocity}}
Your $doc.space did not work because it was inside single quotes. That means a literal string. Changing single to double quotes makes variables work inside the config.
With the $escapetool white spaces (and dots) in space names will escaped the way that the query worked. I’m not sure if the method “css” is the perfect one but it worked during my tests.
I added the filterQuery “wiki” because I got results from my sub wiki and the uninteresting main wiki too before. I had one space name in both wikis.
I added the queryFields because otherwise I got only results matching the search string with the location.
There are two things I’m about to wonder. The tabs “history”, “comments”, “information” and “attachements” are gone. Even with
they won’t be shown. I don’t know how to display them.
Second problem isn’t easy to describe. If I have additional content to the search code above or below it then this content will be added a second, third … time every time I set or unset a facet on the right side.