Search the FirstSpirit Knowledge Base
Hello,
I'm looking for some additional information about how to render results using the BasicSearch module. In section 5.5.2 of the English documentation, there is a section detailing how to render results while inside the <fss:iterateResults> block. I am not clear how the properties work, or how I can use them in my project.
This example is given:
<fss:iterateResults
properties="tel:java.lang.String=CUST_PHONE,fax:java.lang.String=CUST_FAX">
<%= relNo %> of <%= pageSize %>
Telefon: <%= tel %>
Telefax: <%= fax %>
</fss:iterateResults>
In the example, two additional values from the results are made available as variables of the type
"String". "CUST_PHONE" and "CUST_FAX" are given the identifiers "tel" and "fax" in the JSP
page.
I am hoping that I can use these properties to render additional information about results, but it is not clear to me where the values for 'tel' and 'fax' are coming from in the example. How does this data relate to objects/fields in FirstSpirit? What exactly are 'CUST_PHONE' and 'CUST_FAX' in this example?
Thanks, Justin
Hi Justin,
I am referring to your inqueries to our technical support here and not to the post above since you gave them further specs on the topic above.
Unfortunately the main search servlet does a redirect in the search result page after the form post which does not include any fomer request or form parameters of origin request.
I would sugguest that you use either JavaScript to fake the query parameter on the URL if you need it (window.location.replace(url), see http://www.w3schools.com/jsref/met_loc_replace.asp) or you should consider to use an AJAX request in the background to collect the query string via a rest API or both together.
If this is all no help maybe you should consider to put a feature request here to ask for change of the basic search behaviour.
Best regards,
Marian
Hi Marian,
Thank you for the reply. This thread was about a different question but I will provide some background in case anyone else comes across this:
When using the BasicSearch module, the results page URL that the module redirects to after a search is performed does not contain the search query in the query string. I was asking if it was possible to include the search term in the results page query string, as our client had requested this so they could better understand how people are using the search.
I am going to use an AJAX request as Marian suggested to get the functionality I need.
Justin
Hello Justin,
I just came across another idea to append the query parameter to the URL. You could change the resultsURL parameter of your form and let the search module redirect to a different page (see the example source code below) which then will perform a redirect to the actual search result page including the query in the URL.
<%@ taglib uri="fs-search" prefix="fss" %>
<fss:getSearchDetails>
<% response.sendRedirect("searchresults.jsp?cid=" + request.getParameter("cid") + "&query=" + query ); %>
</fss:getSearchDetails>
Regards,
Donato
Hi Marian,
I have the work done for an AJAX setup but I am having some trouble getting the module page to respond. It looks like some of the data I am POSTing to the module page is not getting through and I am not sure why.
I have set up a new page that parses the search results and returns them as a JSON object (pageref:"search_results_json"). I am POSTing to the module and using that JSON page as the resultsURL parameter:
var request = $.ajax({
method: "POST",
url: "<%=request.getContextPath() %>/do.search",
data: {
query: "california",
pageSize: "100",
resultsURL: "$CMS_REF(pageref:"search_results_json")$"
}
});
The call works - the module redirects to the JSON page, which means that the resultsURL parameter is working, but it is not getting the "query" parameter I am also passing, so no actual search is taking place.
I'm not sure what the difference is between this jQuery call and what I was using originally as a form. This is what the old form looked like:
<form method="post" action="<%=request.getContextPath() %>/do.search" name="fss">
<input type="text" name="query" class="search-input" />
<input type="hidden" name="resultsURL" value="$CMS_REF(pageref:"search_results")$" />
<input type="hidden" name="pageSize" value="10" />
<input type="submit" value="Search" />
</form>
The parameters seem to line up to me. Any ideas why the query is not getting through?
For reference, here is the code for the JSON page that I am having the search module redirect to:
<%@ page language="java" contentType="application/json; charset=UTF-8" %>
<%@ taglib uri="fs-search" prefix="fss" %>
<%@ page import="java.util.*" %>
$CMS_TRIM(level:4)$
{
<fss:getSearchDetails>
<fss:isTrue>
"query":"<%=query %>",
"results":[
<fss:iterateResults>
{
"title":"<%=title %>",
"url":"<%=url %>",
"content":"<%=content.substring(0, Math.min(content.length(), 300)) %>"
},
</fss:iterateResults>
]
</fss:isTrue>
<fss:isFalse>
"query":"<%=query %>",
"results":[]
</fss:isFalse>
</fss:getSearchDetails>
}
$CMS_END_TRIM$
Hi Justin,
I am getting the feeling you misunderstood me. I had meant that you can use on the result page a dedicated AJAX request to log your query string in background to self made REST service which just collects the query string. In this scenario you can see what is searched for.
Behind the "do.search" there is a servlet which will NOT transmit any additional post data you will send to the destination page.
(More technical: The servlet does a redirect and not a dispatch as it would be needed if you want to get your additional post data)
This is the limit. But Donato's solution above is a quite nice idea and workround for that limit because it will introduce an intermediate page in which you can add the query string. Any other post parameter is still lost.
Regards
Marian
Hello Justin
do you need further help or did the given answers already help you? If so it would be great if you mark the "correct answer".
If you found a solution by yourself it would be very kind of you if you post it here.
Best regards
Michaela