public void Reset() { LibrarySearchCriteria crit = new LibrarySearchCriteria() .AddTextFieldToSearch(LibrarySearchCriteria.SearchableTextField.Names) .AddBalanceType(Element.BalanceType.na) .AddProhibitedWord("Crapburger") .AddOptionalWord("Cheeseburger") .AddRequiredWord("Now") .ExcludingAbstractElements() .ExcludingExtendedElements() .MatchingWholeWords() .DescendingFrom("A/Path/Right/Here"); Assert.AreEqual(new LibrarySearchCriteria.SearchableTextField[] { LibrarySearchCriteria.SearchableTextField.Labels, LibrarySearchCriteria.SearchableTextField.Definitions, LibrarySearchCriteria.SearchableTextField.Names }, crit.TextFieldsToSearch, "Pre-reset TextFieldsToSearch"); Assert.AreEqual(new Element.BalanceType[] { Element.BalanceType.na }, crit.BalanceTypes, "Pre-reset BalanceTypes"); Assert.AreEqual(new string[] { "Crapburger" }, crit.ProhibitedWords, "Pre-reset WithoutWords"); Assert.AreEqual(new string[] { "Cheeseburger" }, crit.OptionalWords, "Pre-reset OneOrMoreWords"); Assert.AreEqual(new string[] { "Now" }, crit.RequiredWords, "Pre-reset AllWords"); Assert.AreEqual(false, crit.IsIncludeAbstractElements, "Pre-reset IsIncludeAbstractElements"); Assert.AreEqual(false, crit.IsIncludeExtendedElements, "Pre-reset IsIncludeExtendedElements"); Assert.AreEqual("A/Path/Right/Here", crit.AncestryPath, "Pre-reset AncestryPath"); crit.Reset(); AssertFullResetState(crit); }
public void AddTextFieldToSearch_Adds_Type() { LibrarySearchCriteria crit = new LibrarySearchCriteria() .AddTextFieldToSearch(LibrarySearchCriteria.SearchableTextField.Names); Assert.AreEqual(new LibrarySearchCriteria.SearchableTextField[] { LibrarySearchCriteria.SearchableTextField.Labels, LibrarySearchCriteria.SearchableTextField.Definitions, LibrarySearchCriteria.SearchableTextField.Names }, crit.TextFieldsToSearch); }
public void DescendingFrom() { LibrarySearchCriteria crit = new LibrarySearchCriteria() .DescendingFrom("A/Path/Here"); Assert.AreEqual("A/Path/Here", crit.AncestryPath); }
public void ReIndexNode_Replaces_Old_Document() { Node node = GetNodeProvider().GetNodesForIndexing()[2]; LibrarySearchCriteria crit = new LibrarySearchCriteria() .MatchingWholeWords() .WithOptionalWords(node.Id) .IncludingExtendedElements() .IncludingAbstractElements() .AgainstTextFields(new LibrarySearchCriteria.SearchableTextField[] { LibrarySearchCriteria.SearchableTextField.ElementId }); ILibrarySearchResult result = _indexMgr.Search(crit); Assert.AreEqual(1, result.Count, "TEST SANITY: There should only be one result"); Assert.AreEqual(node.Label, result.Items[0].Label, "TEST SANITY: Node label should match the result label"); string oldLabel = node.Label; string newLabel = oldLabel + " UNIT TEST"; node.Label = newLabel; _indexMgr.ReIndexNode(node); ILibrarySearchResult result2 = _indexMgr.Search(crit); Assert.AreEqual(1, result2.Count, "There should only be one result"); Assert.AreEqual(newLabel, result2.Items[0].Label, "The result label should match the new node label"); //Reset the index for other tests node.Label = oldLabel; _indexMgr.ReIndexNode(node); }
private static void AssertQueryString(string expected, LibrarySearchCriteria crit) { LuceneLibrarySearchCriteriaAdaptor adaptor = new LuceneLibrarySearchCriteriaAdaptor(); string result = adaptor.BuildQueryString(crit); Assert.AreEqual(expected, result); }
public void AddRequiredWord_Appends_Word() { LibrarySearchCriteria crit = new LibrarySearchCriteria() .AddRequiredWord("Joey") .AddRequiredWord("Lawrence"); Assert.AreEqual(new string[] { "Joey", "Lawrence" }, crit.RequiredWords); }
public void AddBalanceType_Adds_Type() { LibrarySearchCriteria crit = new LibrarySearchCriteria() .AddBalanceType(Element.BalanceType.credit) .AddBalanceType(Element.BalanceType.debit); Assert.AreEqual(new Element.BalanceType[] { Element.BalanceType.credit, Element.BalanceType.debit }, crit.BalanceTypes); }
public void AddIncludingWord_Appends_Word() { LibrarySearchCriteria crit = new LibrarySearchCriteria() .AddOptionalWord("Joey") .AddOptionalWord("Lawrence"); Assert.AreEqual(new string[] { "Joey", "Lawrence" }, crit.OptionalWords); }
///<summary> ///</summary> public ILibrarySearchResult Search(LibrarySearchCriteria criteria) { if (!IsInitialized) { throw new InvalidOperationException("Cannot Search: The Search Index Mgr has not been initialized. Please call Initialize() first."); } return(DoSearch(criteria)); }
public void Search() { LibrarySearchCriteria criteria = new LibrarySearchCriteria() .WithOptionalWords("Cash"); ILibrarySearchResult result = _indexMgr.Search(criteria); Assert.IsNotNull(result, "Search results should not be null"); Assert.AreEqual(143, result.Count); }
public void Path() { LibrarySearchCriteria criteria = new LibrarySearchCriteria() .WithRequiredWords("Hedging") .DescendingFrom("/Notes to the Financial Statements/usfr-pte_NotesFinancialStatementsAbstract/usfr-pte_GeneralNotesAbstract/usfr-pte_DerivativesHedgesNote"); ILibrarySearchResult result = _indexMgr.Search(criteria); Assert.AreEqual(30, result.Count, "Num results"); }
public void ConvertPluralsToSingular_With_Partial_Word_Matching() { const string expectedResult = "(Label:(\"Joes Fishes Exes Candies Dresses Handles\"~6 Joe*^6 Fish*^5 Exe*^4 Cand*^3 Dress*^2 Handl*^1))"; LibrarySearchCriteria crit = new LibrarySearchCriteria() .MatchingPartialWords() .WithOptionalWords("Joes Fishes Exes Candies Dresses Handles") .AgainstTextFields(new LibrarySearchCriteria.SearchableTextField[] { LibrarySearchCriteria.SearchableTextField.Labels }); AssertQueryString(expectedResult, crit); }
private static void AssertFullResetState(LibrarySearchCriteria crit) { Assert.AreEqual(new LibrarySearchCriteria.SearchableTextField[] { LibrarySearchCriteria.SearchableTextField.Labels, LibrarySearchCriteria.SearchableTextField.Definitions }, crit.TextFieldsToSearch, "Post-reset TextFieldsToSearch"); Assert.AreEqual(new Element.BalanceType[] { }, crit.BalanceTypes, "Post-reset BalanceTypes"); Assert.AreEqual(new string[] { }, crit.ProhibitedWords, "Post-reset WithoutWords"); Assert.AreEqual(new string[] { }, crit.OptionalWords, "Post-reset OneOrMoreWords"); Assert.AreEqual(new string[] { }, crit.RequiredWords, "Post-reset AllWords"); Assert.AreEqual(true, crit.IsIncludeAbstractElements, "Post-reset IsIncludeAbstractElements"); Assert.AreEqual(true, crit.IsIncludeExtendedElements, "Post-reset IsIncludeExtendedElements"); Assert.IsNull(crit.AncestryPath, "Pre-reset AncestryPath"); }
public void ConvertPluralsToSingular_With_Gaming() { const string expectedResult = "(Label:(Gam*^1))"; LibrarySearchCriteria crit = new LibrarySearchCriteria() .MatchingPartialWords() .WithOptionalWords("Gaming") .AgainstTextFields(new LibrarySearchCriteria.SearchableTextField[] { LibrarySearchCriteria.SearchableTextField.Labels }); AssertQueryString(expectedResult, crit); }
public void WithAllWordsSeparatedBySpace_Clears_And_Adds_Range() { LibrarySearchCriteria crit = new LibrarySearchCriteria() .WithRequiredWords("Joey"); Assert.AreEqual(new string[] { "Joey" }, crit.RequiredWords); crit.WithRequiredWords("Lawrence"); Assert.AreEqual(new string[] { "Lawrence" }, crit.RequiredWords); }
public void WithBalanceTypes_Clears_And_Adds_Range() { LibrarySearchCriteria crit = new LibrarySearchCriteria() .WithBalanceTypes(new Element.BalanceType[] { Element.BalanceType.credit }); Assert.AreEqual(new Element.BalanceType[] { Element.BalanceType.credit }, crit.BalanceTypes); crit.WithBalanceTypes(new Element.BalanceType[] { Element.BalanceType.debit }); Assert.AreEqual(new Element.BalanceType[] { Element.BalanceType.debit }, crit.BalanceTypes); }
public void AgainstTextFields_Clears_And_Adds_Range() { LibrarySearchCriteria crit = new LibrarySearchCriteria() .AgainstTextFields(new LibrarySearchCriteria.SearchableTextField[] { LibrarySearchCriteria.SearchableTextField.Labels }); Assert.AreEqual(new LibrarySearchCriteria.SearchableTextField[] { LibrarySearchCriteria.SearchableTextField.Labels }, crit.TextFieldsToSearch); crit.AgainstTextFields(new LibrarySearchCriteria.SearchableTextField[] { LibrarySearchCriteria.SearchableTextField.Definitions }); Assert.AreEqual(new LibrarySearchCriteria.SearchableTextField[] { LibrarySearchCriteria.SearchableTextField.Definitions }, crit.TextFieldsToSearch); }
public void ProhibitedWords_Only() { string expectedResult = "-(Label:(-Dirt^1))"; LibrarySearchCriteria crit = new LibrarySearchCriteria() .MatchingWholeWords() .WithProhibitedWords("Dirt") .AgainstTextFields(new LibrarySearchCriteria.SearchableTextField[] { LibrarySearchCriteria.SearchableTextField.Labels }); AssertQueryString(expectedResult, crit); }
public void OneOrMoreWords_With_AllWords_Not_Matching_Whole_Words() { string expectedResult = "(Label:(Joe*^1)) AND +(Label:(+Dirt*^1))"; LibrarySearchCriteria crit = new LibrarySearchCriteria() .WithOptionalWords("Joe") .MatchingPartialWords() .WithRequiredWords("Dirt") .AgainstTextFields(new LibrarySearchCriteria.SearchableTextField[] { LibrarySearchCriteria.SearchableTextField.Labels }); AssertQueryString(expectedResult, crit); }
public void OneOrMoreWords_With_AllWords_And_Many_Fields() { string expectedResult = "+(Label:(\"Dirt Kid\"~6 +Dirt^4 +Kid^3) Definition:(+Dirt^2 +Kid^1))"; //string expectedResult = "+(Label:Dirt^4 Definition:Dirt^2) AND +(Label:Kid^3 Definition:Kid^1)"; LibrarySearchCriteria crit = new LibrarySearchCriteria() .MatchingWholeWords() .WithRequiredWords("Dirt Kid") .AgainstTextFields(new LibrarySearchCriteria.SearchableTextField[] { LibrarySearchCriteria.SearchableTextField.Labels, LibrarySearchCriteria.SearchableTextField.Definitions }); AssertQueryString(expectedResult, crit); }
public void Search_With_No_Search_Fields_Selected_Returns_A_Zero_Hits_Result() { LibrarySearchCriteria crit = new LibrarySearchCriteria() .MatchingWholeWords() .WithOptionalWords("Joe") .IncludingExtendedElements() .AgainstTextFields(new LibrarySearchCriteria.SearchableTextField[] { }); ILibrarySearchResult result = _indexMgr.Search(crit); Assert.AreEqual(0, result.Count, "Num results"); }
public void Reset_With_Options_Full() { LibrarySearchCriteria crit = new LibrarySearchCriteria() .WithBalanceTypes(new Element.BalanceType[] { Element.BalanceType.credit, Element.BalanceType.debit, Element.BalanceType.na }) .WithOptionalWords("Blah blah") .WithRequiredWords("Blab blab") .DescendingFrom("Test/Path/Here"); crit.Reset(LibrarySearchCriteriaResetOptions.Full); AssertFullResetState(crit); }
public void ProhibitedWords_With_No_Fields() { const string expectedResult = null; LibrarySearchCriteria crit = new LibrarySearchCriteria() .MatchingWholeWords() .WithProhibitedWords("Joe") .IncludingExtendedElements() .AgainstTextFields(new LibrarySearchCriteria.SearchableTextField[] { }); AssertQueryString(expectedResult, crit); }
public void OneOrMoreWords_With_Do_Not_IncludeExtended() { string expectedResult = "(Label:(Joe^1)) AND (IsExtended:false)"; LibrarySearchCriteria crit = new LibrarySearchCriteria() .MatchingWholeWords() .WithOptionalWords("Joe") .ExcludingExtendedElements() .AgainstTextFields(new LibrarySearchCriteria.SearchableTextField[] { LibrarySearchCriteria.SearchableTextField.Labels }); AssertQueryString(expectedResult, crit); }
public void OneOrMoreWords_With_IncludeAbstract() { string expectedResult = "(Label:(Joe^1))"; LibrarySearchCriteria crit = new LibrarySearchCriteria() .MatchingWholeWords() .WithOptionalWords("Joe") .IncludingAbstractElements() .AgainstTextFields(new LibrarySearchCriteria.SearchableTextField[] { LibrarySearchCriteria.SearchableTextField.Labels }); AssertQueryString(expectedResult, crit); }
public void OneOrMoreWords_With_BalanceType() { string expectedResult = "(Label:(Joe^1)) AND (BalanceType:credit BalanceType:debit)"; LibrarySearchCriteria crit = new LibrarySearchCriteria() .MatchingWholeWords() .WithOptionalWords("Joe") .AgainstTextFields(new LibrarySearchCriteria.SearchableTextField[] { LibrarySearchCriteria.SearchableTextField.Labels }) .WithBalanceTypes(new Element.BalanceType[] { Element.BalanceType.credit, Element.BalanceType.debit }); AssertQueryString(expectedResult, crit); }
public void OneOrMoreWords_With_ProhibitedWords() { string expectedResult = "(Label:(Joe^1)) AND -(Label:(-Dirt^1))"; LibrarySearchCriteria crit = new LibrarySearchCriteria() .MatchingWholeWords() .WithOptionalWords("Joe") .WithProhibitedWords("Dirt") .AgainstTextFields(new LibrarySearchCriteria.SearchableTextField[] { LibrarySearchCriteria.SearchableTextField.Labels }); AssertQueryString(expectedResult, crit); }
public void ConvertPluralsToSingular_With_Whole_Word_Matching() { const string expectedResult = "(Label:(\"Joes Fishes Exes Candies Dresses Handles\"~6 Joes^6 Fishes^5 Exes^4 Candies^3 Dresses^2 Handles^1))"; //const string expectedResult = "(Label:Joes^6 Label:Fishes^5 Label:Exes^4 Label:Candies^3 Label:Dresses^2 Label:Handles^1)"; LibrarySearchCriteria crit = new LibrarySearchCriteria() .MatchingWholeWords() .WithOptionalWords("Joes Fishes Exes Candies Dresses Handles") .AgainstTextFields(new LibrarySearchCriteria.SearchableTextField[] { LibrarySearchCriteria.SearchableTextField.Labels }); AssertQueryString(expectedResult, crit); }
public void OneOrMoreWords_With_AllWords() { string expectedResult = "(Label:(Joe^1)) AND +(Label:(\"Dirt Kid\"~6 +Dirt^2 +Kid^1))"; // string expectedResult = "(Label:Joe^1) AND +(Label:Dirt^2) AND +(Label:Kid^1)"; LibrarySearchCriteria crit = new LibrarySearchCriteria() .MatchingWholeWords() .WithOptionalWords("Joe") .WithRequiredWords("Dirt Kid") .AgainstTextFields(new LibrarySearchCriteria.SearchableTextField[] { LibrarySearchCriteria.SearchableTextField.Labels }); AssertQueryString(expectedResult, crit); }
public void IncludeExtendedElements() { LibrarySearchCriteria crit = new LibrarySearchCriteria() .SetIncludeExtendedElements(true); Assert.IsTrue(crit.IsIncludeExtendedElements); crit.SetIncludeExtendedElements(false); Assert.IsFalse(crit.IsIncludeExtendedElements); crit.SetIncludeExtendedElements(true); Assert.IsTrue(crit.IsIncludeExtendedElements); }
///<summary> ///</summary> public Query BuildQuery(LibrarySearchCriteria criteria) { if( criteria == null ) return null; QueryParser queryParser = new QueryParser(string.Empty, ANALYZER); string queryString = BuildQueryString(criteria); if( string.IsNullOrEmpty(queryString) ) { Debug.WriteLine("Ignoring search request because the resultant query string is null or empty: Returning null"); return null; } Debug.WriteLine("Searching with query: " + queryString); return queryParser.Parse(queryString); }
///<summary> ///</summary> public ILibrarySearchResult Search(LibrarySearchCriteria criteria) { if( !IsInitialized ) throw new InvalidOperationException("Cannot Search: The Search Index Mgr has not been initialized. Please call Initialize() first."); return DoSearch(criteria); }
/// <summary> /// </summary> public static string GetFieldName(LibrarySearchCriteria.SearchableTextField fromSearchableTextField) { switch(fromSearchableTextField) { case LibrarySearchCriteria.SearchableTextField.Definitions: return DEFINITION_FIELD; case LibrarySearchCriteria.SearchableTextField.Labels: return LABEL_FIELD; case LibrarySearchCriteria.SearchableTextField.Names: return NAME_FIELD; case LibrarySearchCriteria.SearchableTextField.References: return REFERENCES_FIELD; case LibrarySearchCriteria.SearchableTextField.ElementId: return ELEMENTID_FIELD; } throw new NotImplementedException("The universe is crashing: Unable to get index field name for SearchableTextField " + fromSearchableTextField); }
/// <summary> /// </summary> protected abstract ILibrarySearchResult DoSearch(LibrarySearchCriteria criteria);
/// <summary> /// </summary> protected override ILibrarySearchResult DoSearch(LibrarySearchCriteria criteria) { LuceneLibrarySearchCriteriaAdaptor adaptor = new LuceneLibrarySearchCriteriaAdaptor(); Query query = adaptor.BuildQuery(criteria); if( query == null ) { Debug.WriteLine("LuceneIndexMgr: Query is null, returning a zero-hits result"); return new NoHitsLibrarySearchResult(); } IndexSearcher searcher = new IndexSearcher(CurrentDirectory); Hits hits = searcher.Search(query); string tmpPathFilter = (criteria.AncestryPath == null) ? null : criteria.AncestryPath.Replace(LuceneNodeIndexer.PATH_EOL_MARKER, string.Empty); return new LuceneLibrarySearchResult(hits, tmpPathFilter,0.0499); }
// private static string MakePathQuery(string path) // { // if( string.IsNullOrEmpty(path) ) // { // return null; // } // // return string.Format("({0}:\"{1}/*\")", LuceneNodeIndexer.PATH_FIELD, path.Replace(LuceneNodeIndexer.PATH_EOL_MARKER,string.Empty)); // } ///<summary> ///</summary> public string BuildQueryString(LibrarySearchCriteria criteria) { string oneOrMoreWordsFragment = MakeOneOrMoreWordsQuery(criteria.OptionalWords, criteria.TextFieldsToSearch, criteria.IsMatchWholeWordsOnly, criteria.IsConvertPluralsToSingular); string allWordsFragment = MakeAllWordsQuery(criteria.RequiredWords, criteria.TextFieldsToSearch, criteria.IsMatchWholeWordsOnly, criteria.IsConvertPluralsToSingular); string prohibitedWordsFragment = MakeProhibitedWordsQuery(criteria.ProhibitedWords, criteria.TextFieldsToSearch, criteria.IsMatchWholeWordsOnly, criteria.IsConvertPluralsToSingular); string balanceTypeFragment = MakeBalanceTypeQuery(criteria.BalanceTypes); string includeAbstractFragment = MakeNullIfTrueIncludeXXXElementsQuery(criteria.IsIncludeAbstractElements, LuceneNodeIndexer.ISABSTRACT_FIELD); string includeExtendedFragment = MakeNullIfTrueIncludeXXXElementsQuery(criteria.IsIncludeExtendedElements, LuceneNodeIndexer.ISEXTENDED_FIELD); string includeOnlyExtendedFragment = MakeIncludeNullIfFalseXXXElementsQuery(criteria.IsIncludeOnlyExtendedElements, LuceneNodeIndexer.ISEXTENDED_FIELD); //string pathFragment = MakePathQuery(criteria.AncestryPath); StringBuilder result = new StringBuilder(); bool needsAndDelimiter = false; const string andDelimiter = " AND "; if( !string.IsNullOrEmpty(oneOrMoreWordsFragment) ) { result.AppendFormat("{0}{1}", needsAndDelimiter ? andDelimiter : string.Empty, oneOrMoreWordsFragment); needsAndDelimiter = true; } if( !string.IsNullOrEmpty(allWordsFragment) ) { result.AppendFormat("{0}{1}", needsAndDelimiter ? andDelimiter : string.Empty, allWordsFragment); needsAndDelimiter = true; } if (!string.IsNullOrEmpty(prohibitedWordsFragment)) { result.AppendFormat("{0}{1}", needsAndDelimiter ? andDelimiter : string.Empty, prohibitedWordsFragment); needsAndDelimiter = true; } if (!string.IsNullOrEmpty(balanceTypeFragment)) { result.AppendFormat("{0}{1}", needsAndDelimiter ? andDelimiter : string.Empty, balanceTypeFragment); needsAndDelimiter = true; } if (!string.IsNullOrEmpty(includeAbstractFragment)) { result.AppendFormat("{0}{1}", needsAndDelimiter ? andDelimiter : string.Empty, includeAbstractFragment); } if (!string.IsNullOrEmpty(includeExtendedFragment)) { result.AppendFormat("{0}{1}", needsAndDelimiter ? andDelimiter : string.Empty, includeExtendedFragment); } if (!string.IsNullOrEmpty(includeOnlyExtendedFragment)) { result.AppendFormat("{0}{1}", needsAndDelimiter ? andDelimiter : string.Empty, includeOnlyExtendedFragment); } // if (!string.IsNullOrEmpty(pathFragment)) // { // result.AppendFormat("{0}{1}", needsAndDelimiter ? andDelimiter : string.Empty, pathFragment); // } if( result.Length == 0 ) return null; return result.ToString(); }