-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathSearch.cpp
More file actions
116 lines (106 loc) · 2.97 KB
/
Search.cpp
File metadata and controls
116 lines (106 loc) · 2.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#include "store/IndexOutput.h"
#include "store/IndexInput.h"
#include "document/Document.h"
#include "writer/IndexWriter.h"
#include "reader/IndexReader.h"
#include "reader/HitDoc.h"
#include "comm/stdHeader.h"
#include "search/IndexSearch.h"
#include "merge/SegmentInfos.h"
#include "merge/IndexMerge.h"
#include "search/PriQueue.h"
#include <stdio.h>
#include <string>
#include <iostream>
using namespace std;
CDict iDict;
int main(int argc, char* argv[]){
// IndexWriter *indexWriter=new IndexWriter();
// indexWriter->open("/home/luyf/index/",false);
// indexWriter->setBufferDoc(2);
// Document doc;
// Field *t=new Field();
// t->type= STORE_LONG;
// t->is_store=STORE_YES;
// t->token=STORE_KEYWORD;
// t->name="t";
// t->data="22";
// std::string nn="t";
// doc.addField(nn,t);
// Field *tx=new Field();
// tx->type= STORE_STRING;
// tx->is_store=STORE_YES;
// tx->token=STORE_KEYWORD;
// tx->name="tx";
// tx->data="you and me 2222222222" ;
// std::string nnx="tx";
// doc.addField(nnx,tx);
//
// Document doc1;
// Field *t1=new Field();
// t1->type= STORE_LONG;
// t1->is_store=STORE_YES;
// t1->token=STORE_KEYWORD;
// t1->name="t";
// t1->data="22";
// doc1.addField(nn,t1);
// Field *tx1=new Field();
// tx1->type= STORE_STRING;
// tx1->is_store=STORE_YES;
// tx1->token=STORE_KEYWORD;
// tx1->name="tx";
// tx1->data="you and you 22222222 ";
// doc1.addField(nnx,tx1);
// indexWriter->add( doc);
// indexWriter->add( doc1);
// delete indexWriter;
//
// IndexReader *reader=new IndexReader();
// reader->open("/home/luyf/index/");
// reader->del(6);
// delete reader;
//
// IndexReader *reader1=new IndexReader();
// reader1->open("/home/luyf/index/");
// for(int i=0;i<reader1->getNumDoc();i++){
// // int i=23;
// Document doc;
// cout<<i<<endl;
// reader1->doc(i,doc);
// std::string fieldName="t";
// cout<<doc.getLongField(fieldName)<<endl;
// fieldName="tx";
// std::string fieldValue;
// cout<<doc.getStringField(fieldName)<<endl;
// }
//
// delete reader1;
IndexSearch indexSearch;
indexSearch.open("/home/luyf/index/");
std::vector<HitDoc> hitVo;
std::string term="you me";
indexSearch.SearchOrString(term,hitVo);
cout<<"------SearchOrString----------"<<endl;
for(int i=0;i<indexSearch.hitCounts;i++){
HitDoc hdoc=hitVo[i];
Document doc;
int64_t id= hdoc.getDocId();
cout<<id<<":"<<hdoc.getHits()<<endl;
indexSearch.doc(id,doc);
cout<<doc.getLongField(std::string("t"))<<endl;
cout<<doc.getStringField(std::string("tx"))<<endl;
}
hitVo.clear();
cout<<"-------.SearchAndString---------"<<endl;
indexSearch.SearchAndString(term,hitVo);
for(int i=0;i<indexSearch.hitCounts;i++){
HitDoc hdoc=hitVo[i];
Document doc;
int64_t id= hdoc.getDocId();
cout<<id<<":"<<hdoc.getHits()<<endl;
indexSearch.doc(id,doc);
cout<<doc.getLongField(std::string("t"))<<endl;
cout<<doc.getStringField(std::string("tx"))<<endl;
}
return 0;
}