/[sdx]/demos/quran/search.xsp
ViewVC logotype

Annotation of /demos/quran/search.xsp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.6 - (hide annotations) (download)
Sun Jan 18 17:54:09 2004 UTC (20 years, 3 months ago) by brihaye
Branch: MAIN
CVS Tags: HEAD
Changes since 1.5: +65 -57 lines
Robustness issue.

1 brihaye 1.1 <?xml version="1.0" encoding="ISO-8859-1"?>
2     <!--
3     Copyright (C) 2003, Pierrick Brihaye
4     pierrick.brihaye@wanadoo.fr
5    
6     This program is free software; you can redistribute it and/or
7     modify it under the terms of the GNU General Public License
8     as published by the Free Software Foundation; either version 2
9     of the License, or (at your option) any later version.
10    
11     This program is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14     See the GNU General Public License for more details.
15    
16     You should have received a copy of the GNU General Public License
17     along with this program; if not, write to the
18     Free Software Foundation, Inc.
19     59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
20     or connect to:
21     http://www.fsf.org/copyleft/gpl.html
22     -->
23     <xsp:page language="java" xmlns:xsp="http://apache.org/xsp" xmlns:sdx="http://www.culture.gouv.fr/ns/sdx/sdx">
24     <xsp:structure>
25 brihaye 1.5 <xsp:include>gpl.pierrick.brihaye.aramorph.AraMorph</xsp:include>
26 brihaye 1.1 <xsp:include>fr.gouv.culture.sdx.documentbase.LuceneDocumentBase</xsp:include>
27     <xsp:include>fr.gouv.culture.sdx.search.lucene.analysis.Analyzer</xsp:include>
28     <xsp:include>fr.gouv.culture.sdx.search.lucene.analysis.Analyzer_en</xsp:include>
29     <xsp:include>fr.gouv.culture.sdx.utils.lucene.LuceneTools</xsp:include>
30     </xsp:structure>
31     <sdx:page>
32     <menu/>
33     <xsp:logic>
34 brihaye 1.6 AraMorph araMorph = new AraMorph();
35     String queryType = request.getParameter("type");
36     String queryText = request.getParameter("query");
37     if ("arabic".equals(queryType) &amp;&amp; queryText != null &amp;&amp; !"".equals(queryText)) {
38     //arabize a query in the Buckwalter transliteration
39     //TODO : field names are arabized as well :-(
40     queryText = araMorph.arabizeWord(queryText);
41     <viewresults>
42     <sdx:executeSimpleQuery base="ar" hilite="true" queryString="queryText" docs="true"/>
43     <xsp:logic>
44     Hashtable terms = new Hashtable();
45     LuceneTools.getTerms(sdx_query.getLuceneQuery(), terms, true);
46     Iterator it = terms.values().iterator();
47     while (it.hasNext()) {
48     <stem>
49     <xsp:logic>
50     String stem = (String)it.next();
51     stem = araMorph.arabizeWord(stem);
52     Boolean hasSolutions = new Boolean(araMorph.analyzeToken(stem));
53     <xsp:attribute name="hasSolutions">
54     <xsp:expr>hasSolutions.toString()</xsp:expr>
55     </xsp:attribute>
56     </xsp:logic>
57     <xsp:content>
58     <xsp:expr>stem</xsp:expr>
59     </xsp:content>
60     </stem>
61     }
62     </xsp:logic>
63 brihaye 1.3 </viewresults>
64 brihaye 1.6 }
65     if ("english".equals(queryType) &amp;&amp; queryText != null &amp;&amp; !"".equals(queryText)) {
66     <!-- let's change the Analyzer for english DB : it is different from the one used when indexing -->
67     LuceneDocumentBase db = (LuceneDocumentBase)sdx_application.getDocumentBase("en");
68     LuceneIndex index = (LuceneIndex)db.getIndex();
69     Hashtable terms;
70     Iterator it;
71     fr.gouv.culture.sdx.search.lucene.Field df = index.getDefaultField();
72     //Store current analyzer
73     Analyzer oldAnalyzer = df.getAnalyzer();
74     String qid = null;
75     try {
76     //Change current analyzer to english analyzer
77 brihaye 1.1 Analyzer_en analyzer = new Analyzer_en();
78 brihaye 1.6 df.setAnalyzer((Analyzer)analyzer);
79     //Execute the query with the english analyzer (remember that terms are indexed in english)
80 brihaye 1.4 <sdx:executeSimpleQuery base="en" queryString="queryText" hilite="true"/>
81 brihaye 1.6 //terms = new Hashtable();
82     //LuceneTools.getTerms(sdx_query.getLuceneQuery(), terms, true);
83     //it = terms.values().iterator();
84     //while (it.hasNext()) {
85     <!-- <token><xsp:expr>(String)it.next()</xsp:expr></token> -->
86     //}
87 brihaye 1.1 //Get the query id
88 brihaye 1.6 qid = sdx_qid;
89     } finally {
90 brihaye 1.1 //Restore old analyzer
91     df.setAnalyzer(oldAnalyzer);
92 brihaye 1.6 }
93     <viewresults>
94 brihaye 1.5 <xsp:logic>
95 brihaye 1.6 //Execute the same query... with the arabic analyzer so that arabic words are highlighted
96     <sdx:executeSimpleQuery base="en" hilite="true" qidString="qid" docs="true"/>
97     terms = new Hashtable();
98     LuceneTools.getTerms(sdx_query.getLuceneQuery(), terms, true);
99     it = terms.values().iterator();
100     while (it.hasNext()) {
101     <token>
102 brihaye 1.5 <xsp:expr>(String)it.next()</xsp:expr>
103     </token>
104 brihaye 1.6 }
105     </xsp:logic>
106 brihaye 1.5 </viewresults>
107 brihaye 1.6 }
108     </xsp:logic>
109 brihaye 1.1 </sdx:page>
110     </xsp:page>

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26