public bool TryGetValuesPartial(IEnumerable <ICompoundIndexKey> myKeys, out ICloseableEnumerable <long> myVertexIDs) { 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); } results_compound.AddRange(results.Where((e) => e.PropertyId != null).Select((e) => new Tuple <long, IComparable, long>((long)e.PropertyId, e.Text, e.VertexId))); } var grouped = from myresults in results_compound group myresults by myresults.Item3; if (grouped.Count() > 0) { myVertexIDs = new CloseableEnumerable <long>(grouped.Select <IGrouping <long, Tuple <long, IComparable, long> >, long>((g) => g.Key), results.Close); return(true); } else { myVertexIDs = null; return(false); } }
/// <summary> /// Checks whether the Lucene index has entries matching the specified Lucene query. /// </summary> /// /// <param name="myQuery">The query string.</param> /// <param name="select">A predicate which takes a LuceneEntry and returns whether a LuceneEntry should be taken into account when looking for Lucene entries. /// If this parameter is NULL, no Lucene entry is ignored.</param> /// /// <returns> /// true, if there are matching entries; otherwise false. /// </returns> /// /// <exception cref="System.ArgumentNullException"> /// myQuery is NULL. /// </exception> /// <exception cref="System.ArgumentException"> /// myQuery is an empty string or contains only whitespace. /// </exception> public Boolean HasEntry(String myQuery, Predicate <LuceneEntry> select = null) { if (myQuery == null) { throw new InvalidOperationException("myQuery cannot be null!"); } LuceneReturn ret = null; if (select != null) { ret = GetEntries(1, myQuery); ret.Close(); if (ret.TotalHits > 0) { ret = GetEntries(ret.TotalHits, myQuery); foreach (var entry in ret) { if (select(entry)) { ret.Close(); return(true); } } } ret.Close(); return(false); } else { ret = GetEntries(1, myQuery); ret.Close(); if (ret.TotalHits > 0) { return(true); } else { return(false); } } }
/// <summary> /// Deletes all entries that match the specified Lucene query. /// </summary> /// /// <param name="myLuceneQuery">The Lucene query.</param> /// <param name="select">A predicate which takes a LuceneEntry and returns whether a LuceneEntry should be taken into account when deleting entries. /// If this parameter is NULL, no Lucene entry is ignored.</param> /// /// <returns> /// 0 (zero) if the operation succeeded; otherwise a value other than 0 (zero). /// </returns> /// /// <exception cref="System.ArgumentNullException"> /// myLuceneQuery is NULL. /// </exception> public int DeleteEntry(String myLuceneQuery, Predicate <LuceneEntry> select = null) { int count = 0; if (myLuceneQuery == null) { throw new InvalidOperationException("myLuceneQuery parameter cannot be null!"); } var reader = GetIndexReader(false); LuceneReturn ret = null; ret = GetEntries(1, myLuceneQuery); if (ret.TotalHits > 1) { ret.Close(); ret = GetEntries(ret.TotalHits, myLuceneQuery); } foreach (var entry in ret) { if ((select == null) || select(entry)) { if (entry.DocNum != null) { int docnum = (int)entry.DocNum; reader.DeleteDocument(docnum); count++; } } } ret.Close(); CloseIndexReader(reader); return(count); }
public LuceneResultEntryListEnumerator(LuceneReturn myLuceneReturn) { _LuceneReturnEnumerator = myLuceneReturn.GetEnumerator(); }
public LuceneResult(LuceneReturn result) { _entries = new LuceneResultEntryList(result); _MaxScore = result.MaxScore; }
public LuceneResultEntryList(LuceneReturn myLuceneReturn) { _LuceneReturn = myLuceneReturn; }
public bool TryGetValues(IEnumerable <ICompoundIndexKey> myKeys, out ICloseableEnumerable <long> myVertexIDs) { 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(results.TotalHits, key.Key as String, key.PropertyID.ToString(), LuceneIndex.Fields.PROPERTY_ID); } results_compound.AddRange(results .Where((e) => e.PropertyId != null) .Select((e) => new Tuple <long, IComparable, long>((long)e.PropertyId, e.Text, e.VertexId))); } var grouped = from myresults in results_compound group myresults by myresults.Item3; if (grouped.Count() > 0) { var _myVertexIDs = grouped .Where((myGroup) => { var join = from entry in myGroup join key in myKeys on new { JoinField1 = entry.Item2, JoinField2 = entry.Item1 } equals new { JoinField1 = key.Key, JoinField2 = key.PropertyID } select entry; if (join.Count() == myKeys.Count()) { return(true); } else { return(false); } }) .Select <IGrouping <long, Tuple <long, IComparable, long> >, long>((g) => g.Key); if (_myVertexIDs.Count() > 0) { myVertexIDs = new CloseableEnumerable <long>(_myVertexIDs, results.Close); return(true); } else { myVertexIDs = null; return(false); } } else { myVertexIDs = null; return(false); } }