Skip to content

Commit

Permalink
[GRAPHDB-57] implemented Score for Lucene query return entries
Browse files Browse the repository at this point in the history
  • Loading branch information
sunlounger committed Nov 24, 2011
1 parent 2378036 commit b3ba296
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
8 changes: 5 additions & 3 deletions Plugins/Index/Implementations/SonesLuceneIndex/LuceneEntry.cs
Expand Up @@ -93,12 +93,13 @@ public LuceneEntry()
/// <param name="myIndexId">The index id.</param>
/// <param name="myVertexId">The vertex id.</param>
/// <param name="myText">The text.</param>
public LuceneEntry(String myIndexId, long myVertexId, String myText, long? myPropertyId = null)
public LuceneEntry(String myIndexId, long myVertexId, String myText, long? myPropertyId = null, float? myScore = null)
{
this.IndexId = myIndexId;
this.VertexId = myVertexId;
this.Text = myText;
this.PropertyId = myPropertyId;
this.Score = myScore;

if (myPropertyId != null)
{
Expand All @@ -110,13 +111,14 @@ public LuceneEntry(String myIndexId, long myVertexId, String myText, long? myPro
}
}

public LuceneEntry(Document myLuceneDocument)
public LuceneEntry(Document myLuceneDocument, float? myScore = null)
{
this.Id = myLuceneDocument.GetField(LuceneIndex.FieldNames[LuceneIndex.Fields.ID]).StringValue();
this.IndexId = myLuceneDocument.GetField(LuceneIndex.FieldNames[LuceneIndex.Fields.INDEX_ID]).StringValue();
this.VertexId = Convert.ToInt64(myLuceneDocument.GetField(LuceneIndex.FieldNames[LuceneIndex.Fields.VERTEX_ID]).StringValue());
this.Text = myLuceneDocument.GetField(LuceneIndex.FieldNames[LuceneIndex.Fields.TEXT]).StringValue();

this.Score = myScore;

var propertyIdField = myLuceneDocument.GetField(LuceneIndex.FieldNames[LuceneIndex.Fields.PROPERTY_ID]);
if (propertyIdField != null)
{
Expand Down
Expand Up @@ -37,7 +37,7 @@ public LuceneEntry Current
if (_pos < 0) MoveNext();

var docnum = _docs.ScoreDocs[_pos].doc;
var entry = new LuceneEntry(_IndexSearcher.Doc(docnum));
var entry = new LuceneEntry(_IndexSearcher.Doc(docnum), _docs.ScoreDocs[_pos].score);

FieldQuery fieldquery = _highlighter.GetFieldQuery(_query);
entry.Highlights = _highlighter.GetBestFragments(fieldquery, _IndexSearcher.GetIndexReader(), docnum, LuceneIndex.FieldNames[LuceneIndex.Fields.TEXT], 100, 3);
Expand Down

0 comments on commit b3ba296

Please sign in to comment.