Skip to content

Commit

Permalink
fixed results and space error in Searcher
Browse files Browse the repository at this point in the history
  • Loading branch information
amit223 committed Jan 1, 2019
1 parent 5e2507e commit 9286c74
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/main/java/Searcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ public Searcher(double avgldl, int numOfIndexedDocs, String path, HashSet<String
_chosenCities = chosenCities;
_path=path;
this.toStem=toStem;
loadDictionaryToMemory(toStem); //using for "Entities"
_toSave=pathToSave;
}

Expand All @@ -83,6 +82,7 @@ private void build_doc_termPlusTfs(String query, boolean toStem) {
term = termsIt.next();
addDocsTo_doc_termPlusTfs(term);
}
dictionary.clear();//todo
}

/**
Expand Down Expand Up @@ -150,16 +150,15 @@ private String queryWithPluses(String query) {
*/
private void addDocsTo_doc_termPlusTfs(String term) {
Map<Integer, Integer> doc_tf = readTermDocs(term);
_term_docsCounter.put(term, doc_tf.size());
Iterator<Integer>docs=doc_tf.keySet().iterator();
while (docs.hasNext()) {
Integer docNum = docs.next();
Integer termTfInDoc = doc_tf.get(docNum);
if (_doc_termPlusTfs.containsKey(docNum)) {
_doc_termPlusTfs.get(docNum).add(new Pair<String, Integer>(term, termTfInDoc)); //todo - future error - if not update, do put after getting copy.
_doc_termPlusTfs.get(docNum).add(new Pair<String, Integer>(term, termTfInDoc));
} else {
_doc_termPlusTfs.put(docNum, new Vector<Pair<String, Integer>>());
_doc_termPlusTfs.get(docNum).add(new Pair<String, Integer>(term, termTfInDoc)); //todo - future error - if not update, do put after getting copy.
_doc_termPlusTfs.get(docNum).add(new Pair<String, Integer>(term, termTfInDoc));
}
}
}
Expand Down Expand Up @@ -187,6 +186,7 @@ else if (Character.isDigit(letter) || letter == '-')
RandomAccessFile raf = new RandomAccessFile(new File(fullPath), "r");
int lineNum = dictionary.get(term).elementAt(2);//the pointer;
int numOfDocs = dictionary.get(term).elementAt(0);//num of docs
_term_docsCounter.put(term,numOfDocs);
for (int i = 0; i < numOfDocs; i++) {
byte[] fullLine=new byte[8];
raf.seek((lineNum + i) * 8);
Expand Down Expand Up @@ -381,6 +381,7 @@ private Vector<Pair<String,Integer>> findEntities(byte[] line) {
public Collection<Document> Search(String id, String query, boolean toTreatSemantic) {
Collection<Document> docs= new Vector<>();
isSemantic=toTreatSemantic;
loadDictionaryToMemory(toStem); //using for "Entities"
build_doc_termPlusTfs(query, toStem);
FilterDocsByCitys();
Collection<Integer> docNums = _ranker.Rank(_doc_termPlusTfs, _doc_size, _numOfIndexedDocs, _term_docsCounter, _avgldl,_path); // return only 50 most relvante
Expand Down Expand Up @@ -433,11 +434,11 @@ private Collection<String> docNumToNames(Collection<Integer> ans,String id) {
* writes to the results file the result for the query
*/
private void WriteToQueryFile(Map<String, Double> docs_rank,String id) {
File file=new File("results.txt");
File file=new File(_toSave+"/results.txt");
try {
if(!file.exists())
file.createNewFile();
BufferedWriter writer=new BufferedWriter(new FileWriter(file));
//if(!file.exists())
// file.createNewFile();
BufferedWriter writer=new BufferedWriter(new FileWriter(file,true));
Iterator<String> docs=docs_rank.keySet().iterator();
while(docs.hasNext()){
String document=docs.next();
Expand Down

0 comments on commit 9286c74

Please sign in to comment.