Skip to content

Commit

Permalink
[GRAPHDB-57] implemented Lucene Index TryGetValuesPartial method + fi…
Browse files Browse the repository at this point in the history
…xed correct Lazy breakup
  • Loading branch information
sunlounger committed Nov 25, 2011
1 parent 8d282f0 commit c26f640
Showing 1 changed file with 44 additions and 9 deletions.
53 changes: 44 additions & 9 deletions Plugins/Index/Implementations/SonesLuceneIndex/SonesLuceneIndex.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public IEnumerable<IComparable> Keys(long myPropertyID)
result = _LuceneIndex.GetEntriesInnerByField(result.TotalHits, "*:*", myPropertyID.ToString(), LuceneIndex.Fields.PROPERTY_ID);
}

// unforunately we have to breakup Lazy as interface does not support closing
// Unfortunately we have to breakup Lazy here as index interface doesn't support close (GRAPHDB-544)
List<IComparable> ret = new List<IComparable>();

foreach (var entry in result.Select<LuceneEntry, IComparable>((e) => (e.Text)))
Expand Down Expand Up @@ -185,20 +185,25 @@ public void AddRange(IEnumerable<KeyValuePair<IEnumerable<ICompoundIndexKey>, lo

public bool TryGetValues(IEnumerable<ICompoundIndexKey> myKeys, out IEnumerable<long> myVertexIDs)
{
LuceneReturn results = null;
var results_compound = new List<Tuple<long, IComparable, long>>();
foreach (var key in myKeys)
{
var results = _LuceneIndex.GetEntriesInnerByField(_MaxResultsFirst, key.Key as String, key.PropertyID.ToString(), LuceneIndex.Fields.PROPERTY_ID);
results = _LuceneIndex.GetEntriesInnerByField(_MaxResultsFirst, key.Key as String, key.PropertyID.ToString(), LuceneIndex.Fields.PROPERTY_ID);
if (results.TotalHits > _MaxResultsFirst)
{
results.Close();
results = _LuceneIndex.GetEntriesInnerByField(results.TotalHits, key.Key as String, key.PropertyID.ToString(), LuceneIndex.Fields.PROPERTY_ID);
}
results_compound
.AddRange(
results

// Unfortunately we have to breakup Lazy here as index interface doesn't support close (GRAPHDB-544)
foreach (var entry in results
.Where((e) => e.PropertyId != null)
.Select((e) => new Tuple<long, IComparable, long>((long)e.PropertyId, e.Text, e.VertexId))
);
.Select((e) => new Tuple<long, IComparable, long>((long)e.PropertyId, e.Text, e.VertexId)))
{
results_compound.Add(entry);
}
results.Close();
}

var grouped = from myresults in results_compound group myresults by myresults.Item3;
Expand Down Expand Up @@ -254,7 +259,37 @@ join key in myKeys

public bool TryGetValuesPartial(IEnumerable<ICompoundIndexKey> myKeys, out IEnumerable<long> myVertexIDs)
{
throw new NotImplementedException();
LuceneReturn results = null;
var results_compound = new List<Tuple<long, IComparable, long>>();
foreach (var key in myKeys)
{
results = _LuceneIndex.GetEntriesInnerByField(_MaxResultsFirst, key.Key as String, key.PropertyID.ToString(), LuceneIndex.Fields.PROPERTY_ID);
if (results.TotalHits > _MaxResultsFirst)
{
results.Close();
results = _LuceneIndex.GetEntriesInnerByField(_MaxResultsFirst, key.Key as String, key.PropertyID.ToString(), LuceneIndex.Fields.PROPERTY_ID);
}

// Unfortunately we have to breakup Lazy here as index interface doesn't support close (GRAPHDB-544)
foreach (var entry in results.Where((e) => e.PropertyId != null).Select((e) => new Tuple<long, IComparable, long>((long)e.PropertyId, e.Text, e.VertexId)))
{
results_compound.Add(entry);
}
results.Close();
}

var grouped = from myresults in results_compound group myresults by myresults.Item3;

if (grouped.Count() > 0)
{
myVertexIDs = grouped.Select<IGrouping<long, Tuple<long, IComparable, long>>, long>((g) => g.Key);
return true;
}
else
{
myVertexIDs = null;
return false;
}
}

public IEnumerable<long> this[IEnumerable<ICompoundIndexKey> myKeys]
Expand Down Expand Up @@ -320,7 +355,7 @@ public override IEnumerable<IComparable> Keys()
var keys_withdoubles = _LuceneIndex.GetKeys(entry => entry.IndexId == this.IndexId);
var keys_grouped = keys_withdoubles.GroupBy(s => s);

// unforunately we have to breakup Lazy as interface does not support closing
// Unfortunately we have to breakup Lazy here as index interface doesn't support close (GRAPHDB-544)
List<String> keys = new List<String>();
foreach (var group in keys_grouped)
{
Expand Down

0 comments on commit c26f640

Please sign in to comment.