private void DoAssert(Document doc, bool fromIndex) { System.String[] keywordFieldValues = doc.GetValues("keyword"); System.String[] textFieldValues = doc.GetValues("text"); System.String[] unindexedFieldValues = doc.GetValues("unindexed"); System.String[] unstoredFieldValues = doc.GetValues("unstored"); Assert.IsTrue(keywordFieldValues.Length == 2); Assert.IsTrue(textFieldValues.Length == 2); Assert.IsTrue(unindexedFieldValues.Length == 2); // this test cannot work for documents retrieved from the index // since unstored fields will obviously not be returned if (!fromIndex) { Assert.IsTrue(unstoredFieldValues.Length == 2); } Assert.IsTrue(keywordFieldValues[0].Equals("test1")); Assert.IsTrue(keywordFieldValues[1].Equals("test2")); Assert.IsTrue(textFieldValues[0].Equals("test1")); Assert.IsTrue(textFieldValues[1].Equals("test2")); Assert.IsTrue(unindexedFieldValues[0].Equals("test1")); Assert.IsTrue(unindexedFieldValues[1].Equals("test2")); // this test cannot work for documents retrieved from the index // since unstored fields will obviously not be returned if (!fromIndex) { Assert.IsTrue(unstoredFieldValues[0].Equals("test1")); Assert.IsTrue(unstoredFieldValues[1].Equals("test2")); } }
/// <summary> Find words for a more-like-this query former. /// /// </summary> /// <param name="docNum">the id of the lucene document from which to find terms /// </param> protected virtual PriorityQueue <object[]> RetrieveTerms(int docNum) { IDictionary <string, Int> termFreqMap = new HashMap <string, Int>(); for (int i = 0; i < fieldNames.Length; i++) { System.String fieldName = fieldNames[i]; ITermFreqVector vector = ir.GetTermFreqVector(docNum, fieldName); // field does not store term vector info if (vector == null) { Document d = ir.Document(docNum); System.String[] text = d.GetValues(fieldName); if (text != null) { for (int j = 0; j < text.Length; j++) { AddTermFrequencies(new System.IO.StringReader(text[j]), termFreqMap, fieldName); } } } else { AddTermFrequencies(termFreqMap, vector); } } return(CreateQueue(termFreqMap)); }
/// <summary> Find words for a more-like-this query former. /// /// </summary> /// <param name="docNum">the id of the lucene document from which to find terms /// </param> private PriorityQueue RetrieveTerms(int docNum) { System.Collections.IDictionary termFreqMap = new System.Collections.Hashtable(); for (int i = 0; i < fieldNames.Length; i++) { System.String fieldName = fieldNames[i]; TermFreqVector vector = ir.GetTermFreqVector(docNum, fieldName); // field does not store term vector info if (vector == null) { Document d = ir.Document(docNum); System.String[] text = d.GetValues(fieldName); if (text != null) { for (int j = 0; j < text.Length; j++) { AddTermFrequencies(new System.IO.StringReader(text[j]), termFreqMap, fieldName); } } } else { AddTermFrequencies(termFreqMap, vector); } } return(CreateQueue(termFreqMap)); }
private System.Collections.Hashtable GetScores(Hits hits) { System.Collections.Hashtable scoreMap = new System.Collections.Hashtable(); int n = hits.Length(); for (int i = 0; i < n; ++i) { Document doc = hits.Doc(i); System.String[] v = doc.GetValues("tracer"); Assert.AreEqual(v.Length, 1); scoreMap[v[0]] = (float)hits.Score(i); } return(scoreMap); }
// make sure the documents returned by the search match the expected list private void AssertMatches(Searcher searcher, Query query, Sort sort, System.String expectedResult) { Hits result = searcher.Search(query, sort); System.Text.StringBuilder buff = new System.Text.StringBuilder(10); int n = result.Length(); for (int i = 0; i < n; ++i) { Document doc = result.Doc(i); System.String[] v = doc.GetValues("tracer"); for (int j = 0; j < v.Length; ++j) { buff.Append(v[j]); } } Assert.AreEqual(expectedResult, buff.ToString()); }
// make sure the documents returned by the search match the expected list pattern private void AssertMatchesPattern(Searcher searcher, Query query, Sort sort, System.String pattern) { Hits result = searcher.Search(query, sort); System.Text.StringBuilder buff = new System.Text.StringBuilder(10); int n = result.Length(); for (int i = 0; i < n; ++i) { Document doc = result.Doc(i); System.String[] v = doc.GetValues("tracer"); for (int j = 0; j < v.Length; ++j) { buff.Append(v[j]); } } // System.out.println ("matching \""+buff+"\" against pattern \""+pattern+"\""); System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex(pattern); Assert.IsTrue(regex.IsMatch(buff.ToString())); }