Example #1
0
        /// <summary>
        /// Recursively search all documents for a phrase
        /// </summary>
        /// <param Name="documents">The list of documents to search</param>
        /// <param Name="location">The location to start searching in</param>
        /// <param Name="phrase">The phrase to search for</param>
        /// <param Name="reverse">Whether the search should be backwards</param>
        /// <returns>The location of the phrase, or null if not found</returns>
        protected static Location SearchDocuments(Document[] documents, Location location, string phrase, bool reverse)
        {
            //Search for the phrase, and return if found
            Location output = SearchDocument(location, phrase, reverse);
            if (output != null) { return output; }

            //Remove the first document fro the array, and exit if no documents remain
            Document[] newDocuments = documents.Skip(1).ToArray();
            if (newDocuments.Length == 0) { return null; }

            //Begin the next recursion
            Location newLocation = new Location(location.Window, newDocuments[0], null, null);
            return SearchDocuments(newDocuments, newLocation, phrase, reverse);
        }
Example #2
0
        /// <summary>
        /// Order documents for searching
        /// </summary>
        /// <param Name="documents">The list of documents to search</param>
        /// <param Name="startDoc">The index of the document to start searching at</param>
        /// <param Name="reverse">Whether the search should be backwards</param>
        /// <returns></returns>
        protected static Document[] OrderDocuments(Document[] documents, int startDoc, bool reverse)
        {
            //If the search is backwards, reverse the list
            //And update the startDoc pointer to the new location
            if (reverse)
            {
                documents = documents.Reverse().ToArray();
                startDoc = documents.Length - startDoc - 1;
            }

            //Reorder the list such that all documents from before the start document
            //are removed and added to the end of the list
            return documents.Skip(startDoc).Concat(documents.Take(startDoc + 1)).ToArray();
        }