-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9fefa19
commit 5144016
Showing
6 changed files
with
133 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package meowranker; | ||
|
||
import java.util.*; | ||
import org.bson.Document; | ||
import org.bson.types.ObjectId; | ||
import org.jsoup.Jsoup; | ||
|
||
public class QueryRanker extends Ranker{ | ||
|
||
public List<Double> QueryDocRel; | ||
|
||
public QueryRanker(){ | ||
super(); | ||
QueryDocRel = new ArrayList<>(); | ||
} | ||
|
||
protected List<ObjectId> getMatchingDocs(List<String> searchTokens, String query){ | ||
List<ObjectId> docsUnion = db.getDocIDs(searchTokens); | ||
|
||
Map<ObjectId , Integer> docRepetition = new HashMap<>(); | ||
|
||
List<ObjectId> distinctDocs = new ArrayList<>(); | ||
|
||
ProcessedDocs = new ArrayList<>(); | ||
for(ObjectId docId : docsUnion){ | ||
if(docRepetition.containsKey(docId)){ | ||
// System.out.println(docId); | ||
int currRep = docRepetition.get(docId); | ||
docRepetition.remove(docId); | ||
docRepetition.put(docId , currRep+1); | ||
} | ||
else{ | ||
distinctDocs.add(docId); | ||
docRepetition.put(docId ,1 ); | ||
ProcessedDocs.add(db.getDocument(docId.toString())); | ||
} | ||
} | ||
|
||
for(ObjectId docId :distinctDocs){ | ||
QueryDocRel.add((double)docRepetition.get(docId)/(double)searchTokens.size()); | ||
} | ||
|
||
return distinctDocs; | ||
} | ||
|
||
protected List<Double> addQueryDocRel(List<Double> relevance){ | ||
int ind = 0; | ||
for(Double val:relevance){ | ||
val*=QueryDocRel.get(ind); | ||
ind++; | ||
} | ||
|
||
|
||
return relevance; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters