Collapse AllExpand All

4.8.3. 추천 검색어

sample3.jsp

추천 검색어 목록을 구하는 과정은 다음과 같다. 추천 검색어를 항상 구할 수도 있지만, 아래의 예에서는 오타가 포함되어 있지 않을 경우에만 추천 검색어를 구한다.

9.	…
10.	if (!query.equals(originalQuery)) {
  // 오타 교정
11.	  ….
12.	  if (misspell) {
13.	    …
14.	  } else { // 오타가 포함되어 있지 않을 경우
    // 추천 검색어 추출
15.	   String[] suggestions = ksfclient.suggestRelated(0, query, 10);
    // 세션 변수에 추천 검색어 목록을 저장한다.
16.	   session.setAttribute("suggestions", suggestions);
17.	  }
18.	}
19.	…
1.	<c:if test="${not empty suggestions}">
2.	  <dl class="suggestions dl-horizontal">
3.	    <dt>관련검색</dt>
4.	    <dd>
5.	      <ul class="list-inline">
6.	        <c:forEach var="suggestion" items="${suggestions}">
7.	          <li><a href="#"><c:out value="${suggestion}"/></a></li>
8.	        </c:forEach>
9.	      </ul>
10.	    </dd>
11.	  </dl>
12.	</c:if>
결과

그림 C.11. 추천검색어

추천검색어