|
1 /* |
|
2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 #include <stdio.h> |
|
18 #include <stdlib.h> |
|
19 #include <wchar.h> |
|
20 |
|
21 #include "clucene.h" |
|
22 #include "clucene/queryParser/multifieldqueryparser.h" |
|
23 |
|
24 #include "cpixtools.h" |
|
25 |
|
26 #include "cpixhits.h" |
|
27 #include "cpixsearch.h" |
|
28 #include "cpixidxdb.h" |
|
29 #include "cpixexc.h" |
|
30 #include "iidxdb.h" |
|
31 #include "initparams.h" |
|
32 #include "cpixutil.h" |
|
33 #include "iqrytype.h" |
|
34 |
|
35 #include "cpixmaindefs.h" |
|
36 |
|
37 |
|
38 namespace Cpix |
|
39 { |
|
40 |
|
41 /** |
|
42 * Format and semantics are described in iqrytype.cpp |
|
43 */ |
|
44 class PrefixQryType : public IQryType |
|
45 { |
|
46 private: |
|
47 // |
|
48 // private members |
|
49 // |
|
50 lucene::queryParser::QueryParser * clQueryParser_; |
|
51 lucene::search::Query * clQuery_; |
|
52 |
|
53 public: |
|
54 // |
|
55 // public operators |
|
56 // |
|
57 |
|
58 // |
|
59 // from interface IQryType |
|
60 // |
|
61 |
|
62 virtual void setUp(cpix_QueryParser * queryParser, |
|
63 const std::list<std::wstring> & args, |
|
64 const wchar_t * qryStr) |
|
65 { |
|
66 wchar_t mQryStr[250]; |
|
67 |
|
68 wmemset(mQryStr,0,250); |
|
69 getAnalyzedString(qryStr, mQryStr ); |
|
70 |
|
71 clQueryParser_ = Cast2Native<cpix_QueryParser>(queryParser); |
|
72 |
|
73 if (args.size() > 0) |
|
74 { |
|
75 THROW_CPIXEXC(PL_ERROR "No arguments needed here"); |
|
76 } |
|
77 |
|
78 clQuery_ = clQueryParser_->parse((const wchar_t *)mQryStr); |
|
79 |
|
80 if (clQuery_ == NULL) |
|
81 { |
|
82 THROW_CPIXEXC("Query reduced to empty query."); |
|
83 } |
|
84 } |
|
85 |
|
86 |
|
87 virtual cpix_Hits * search(cpix_IdxSearcher * idxSearcher) |
|
88 { |
|
89 return CLuceneSearchIdx(idxSearcher, |
|
90 clQuery_); |
|
91 } |
|
92 |
|
93 |
|
94 virtual cpix_Hits * search(cpix_IdxDb * idxDb) |
|
95 { |
|
96 return CLuceneSearchIdx(idxDb, |
|
97 clQuery_); |
|
98 } |
|
99 |
|
100 void getAnalyzedString(const wchar_t* input, wchar_t* output) |
|
101 { |
|
102 |
|
103 CL_NS_USE(index) |
|
104 CL_NS_USE(util) |
|
105 CL_NS_USE(store) |
|
106 CL_NS_USE(search) |
|
107 CL_NS_USE(document) |
|
108 CL_NS_USE(queryParser) |
|
109 CL_NS_USE(analysis) |
|
110 CL_NS_USE2(analysis,standard) |
|
111 |
|
112 StandardAnalyzer sAnalyser; |
|
113 |
|
114 Reader* reader = _CLNEW StringReader(input); |
|
115 TokenStream* ts = sAnalyser.tokenStream(_T("dummy"), reader ); |
|
116 Token t; |
|
117 |
|
118 while(ts->next(&t)) |
|
119 { |
|
120 wcscat(output,t.termText()); |
|
121 wcscat(output,L"* "); |
|
122 } |
|
123 size_t len = wcslen(output); |
|
124 |
|
125 if(len == 0) |
|
126 wcscpy(output,L"*"); |
|
127 else |
|
128 { |
|
129 if(output[len-1] == L' ') |
|
130 output[len-1] = L'\0'; |
|
131 } |
|
132 |
|
133 ts->close(); |
|
134 _CLDELETE(ts); |
|
135 _CLDELETE(reader); |
|
136 |
|
137 |
|
138 } |
|
139 |
|
140 |
|
141 private: |
|
142 // |
|
143 // private implementation details |
|
144 // |
|
145 }; |
|
146 |
|
147 |
|
148 |
|
149 IQryType * CreatePrefixQryType() |
|
150 { |
|
151 return new PrefixQryType; |
|
152 } |
|
153 |
|
154 } |