|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| |
|
16 |
| |
|
17 |
| |
|
18 |
| |
|
19 |
| |
|
20 |
| package org.apache.xindice.core.query; |
|
21 |
| |
|
22 |
| import org.apache.xpath.XPathContext; |
|
23 |
| import org.apache.xpath.functions.FunctionOneArg; |
|
24 |
| import org.apache.xpath.objects.XObject; |
|
25 |
| import org.apache.xpath.objects.XBoolean; |
|
26 |
| import org.apache.lucene.queryParser.ParseException; |
|
27 |
| import org.apache.lucene.analysis.Analyzer; |
|
28 |
| import org.apache.xindice.core.query.ftsearch.Searcher; |
|
29 |
| import org.apache.xindice.core.data.NodeSet; |
|
30 |
| import org.apache.xindice.core.Collection; |
|
31 |
| import org.apache.xindice.core.indexer.Indexer; |
|
32 |
| import org.apache.xindice.core.indexer.LuceneIndexer; |
|
33 |
| import org.apache.xindice.xml.dom.NodeListImpl; |
|
34 |
| import org.w3c.dom.Node; |
|
35 |
| |
|
36 |
| import javax.xml.transform.TransformerException; |
|
37 |
| |
|
38 |
| |
|
39 |
| |
|
40 |
| |
|
41 |
| |
|
42 |
| |
|
43 |
| public class FuncFTContains extends FunctionOneArg { |
|
44 |
| |
|
45 |
| |
|
46 |
| |
|
47 |
| |
|
48 |
| |
|
49 |
| |
|
50 |
| |
|
51 |
| |
|
52 |
| |
|
53 |
44
| public XObject execute(XPathContext xctxt) throws TransformerException {
|
|
54 |
| |
|
55 |
44
| XPathQueryResolver.XPathResolverContext ctxt = (XPathQueryResolver.XPathResolverContext) xctxt;
|
|
56 |
| |
|
57 |
| |
|
58 |
| |
|
59 |
| |
|
60 |
44
| Analyzer analyzer = (Analyzer) ctxt.getParameter(XPathQueryResolver.PARAM_ANALYZER);
|
|
61 |
44
| if (analyzer == null) {
|
|
62 |
0
| try {
|
|
63 |
0
| Collection collection = (Collection) ctxt.getParameter(XPathQueryResolver.PARAM_COLLECTION);
|
|
64 |
0
| Indexer idx = collection.getIndexManager().getBestIndexer(Indexer.STYLE_FULLTEXT, null);
|
|
65 |
0
| if (idx instanceof LuceneIndexer) {
|
|
66 |
0
| analyzer = ((LuceneIndexer) idx).getAnalyzer();
|
|
67 |
| } else { |
|
68 |
0
| analyzer = (Analyzer) Class.forName(LuceneIndexer.DEFANALYZER).newInstance();
|
|
69 |
| } |
|
70 |
| |
|
71 |
| |
|
72 |
| |
|
73 |
0
| ctxt.setParameter(XPathQueryResolver.PARAM_ANALYZER, analyzer);
|
|
74 |
| } catch (Exception e) { |
|
75 |
0
| throw new TransformerException("Could not get text analyzer");
|
|
76 |
| } |
|
77 |
| } |
|
78 |
| |
|
79 |
44
| String query = getArg0().execute(xctxt).str();
|
|
80 |
44
| try {
|
|
81 |
44
| int ctxtNode = xctxt.getCurrentNode();
|
|
82 |
44
| Node node = xctxt.getDTM(ctxtNode).getNode(ctxtNode);
|
|
83 |
44
| NodeListImpl list = new NodeListImpl(null);
|
|
84 |
44
| list.add(node);
|
|
85 |
| |
|
86 |
44
| Searcher searcher = new Searcher(list, analyzer);
|
|
87 |
44
| NodeSet nodes = searcher.search(query);
|
|
88 |
| |
|
89 |
44
| return nodes.hasMoreNodes() ? XBoolean.S_TRUE : XBoolean.S_FALSE;
|
|
90 |
| } catch (ParseException e) { |
|
91 |
0
| throw new TransformerException("Error in text query", e);
|
|
92 |
| } |
|
93 |
| } |
|
94 |
| } |