View Javadoc

1   /*
2    * Copyright 2008 FatWire Corporation. All Rights Reserved.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *    http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package com.fatwire.gst.foundation.facade.search;
18  
19  import com.fatwire.cs.core.search.data.ResultRow;
20  import com.fatwire.cs.core.search.query.Operation;
21  import com.fatwire.cs.core.search.query.QueryExpression;
22  
23  import junit.framework.TestCase;
24  
25  /**
26   * Simple test utility for running a search against the standard FSII search respository.
27   * Not yet set up to follow a proper test framework.  Must be called from within a JSP scriptlet for now.
28   *
29   * @author Tony Field
30   * @since Feb 15, 2011
31   */
32  public final class FSIIRepositoryTest extends TestCase {
33      // x and y and z and (a or b)
34      // x is between condition
35      // the rest are equals conditions
36      /*
37  FSIIAbstract
38  FSIIBody
39  FSIIByline
40  FSIICategoryName
41  FSIIDescriptionAttr
42  FSIIHeadline
43  FSIIImage
44  FSIIKeyword
45  FSIINameAttr
46  FSIIPostDate
47  FSIISubheadline
48  FSIITemplateAttr
49  FSIITitle
50  
51  
52  <%
53  SimpleSearchEngine lucene = SimpleSearchEngine.getInstance("lucene");
54          QueryExpression qry = lucene.newQuery("FSIIBody", Operation.CONTAINS, "device");
55          qry = qry.and("createdby", Operation.CONTAINS, "admin");
56  List<Date> dates = new ArrayList<Date>();
57  dates.add(new Date(0L));
58  dates.add(new Date(911120000019828L));
59  //dates.add(new Date(2L));
60  //qry = qry.and("createddate", Operation.RANGE, dates);
61  //qry = qry.and("FSIIByline", Operation.EQUALS, "Barton P. Fooman");
62  
63          StringBuilder sb = new StringBuilder("Search results:");
64          sb.append("<table>");
65          sb.append("<tr><th>id</th><th>name</th><th>relevance</th></tr>");
66          for (ResultRow row : lucene.search(qry, "Content_C")) {
67              sb.append("<tr>");
68              sb.append("<td>").append(row.getIndexData("id").getData()).append("</td>");
69              sb.append("<td>").append(row.getIndexData("name").getData()).append("</td>");
70              sb.append("<td>").append(row.getRelevance()).append("</td>");
71              sb.append("</tr>");
72          }
73          sb.append("</table>");
74  %><%=sb%>
75  
76  
77  
78       */
79  
80      public void testAndQuery() {
81          // getTestOutput();
82          // todo: low priority: make this into an actual test.
83      }
84  
85      public String getTestOutput() {
86  
87          SimpleSearchEngine lucene = SimpleSearchEngine.getInstance("lucene");
88          QueryExpression qry = lucene.newQuery("FSIIByline", Operation.CONTAINS, "Barton");
89          qry.and("FSIITitle", Operation.CONTAINS, "About");
90  
91          StringBuilder sb = new StringBuilder("Search results:");
92          sb.append("<table>");
93          sb.append("<tr><th>id</th><th>name</th><th>relevance</th></tr>");
94          for (ResultRow row : lucene.search(qry, "Content_C")) {
95              sb.append("<tr>");
96              sb.append("<td>").append(row.getIndexData("id").getData()).append("</td>");
97              sb.append("<td>").append(row.getIndexData("name").getData()).append("</td>");
98              sb.append("<td>").append(row.getRelevance()).append("</td>");
99              sb.append("</tr>");
100         }
101         sb.append("</table>");
102         return sb.toString();
103     }
104 
105 }