Exemple #1
0
		/// <summary>
		/// Search the notes! A match number of
		/// <see cref="int.MaxValue"/> indicates that the note
		/// title contains the search term.
		/// </summary>
		/// <param name="query">
		/// A <see cref="System.String"/>
		/// </param>
		/// <param name="case_sensitive">
		/// A <see cref="System.Boolean"/>
		/// </param>
		/// <param name="selected_notebook">
		/// A <see cref="Notebooks.Notebook"/>.  If this is not
		/// null, only the notes of the specified notebook will
		/// be searched.
		/// </param>
		/// <returns>
		/// A <see cref="IDictionary`2"/> with the relevant Notes
		/// and a match number. If the search term is in the title,
		/// number will be <see cref="int.MaxValue"/>.
		/// </returns>
		public IDictionary<Note,int> SearchNotes (
				string query,
				bool case_sensitive,
				Notebooks.Notebook selected_notebook)
		{
			string [] words = Search.SplitWatchingQuotes (query);

			// Used for matching in the raw note XML
			string [] encoded_words = SplitWatchingQuotes (XmlEncoder.Encode (query));
			Dictionary<Note,int> temp_matches = new Dictionary<Note,int>();
			
			// Skip over notes that are template notes
			Tag template_tag = TagManager.GetOrCreateSystemTag (TagManager.TemplateNoteSystemTag);

			foreach (Note note in manager.Notes) {
				// Skip template notes
				if (note.ContainsTag (template_tag))
					continue;
				
				// Skip notes that are not in the
				// selected notebook
				if (selected_notebook != null
						&& selected_notebook.ContainsNote (note) == false)
					continue;
				
				// First check the note's title for a match,
				// if there is no match check the note's raw
				// XML for at least one match, to avoid
				// deserializing Buffers unnecessarily.

				if (0 < FindMatchCountInNote (note.Title,
						                      words,
						                      case_sensitive))
					temp_matches.Add(note,int.MaxValue);
				else if (CheckNoteHasMatch (note,
					               encoded_words,
					               case_sensitive)){
					int match_count =
						FindMatchCountInNote (note.TextContent,
						                      words,
						                      case_sensitive);

					if (match_count > 0)
						// TODO: Improve note.GetHashCode()
						temp_matches.Add(note,match_count);
				}
			}
			return temp_matches;
		}