Skip to content

Commit

Permalink
updated the place address search to use a minimum of 3 characters whe…
Browse files Browse the repository at this point in the history
…n searching

also updated the place address search to be case insensitive
  • Loading branch information
Nityan Khanna committed Jan 24, 2018
1 parent bd6c1d4 commit a8d1a91
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 3 deletions.
19 changes: 18 additions & 1 deletion OpenIZAdmin.Services/Entities/EntityService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,22 @@ public IEnumerable<T> Search<T>(string searchTerm, string[] expandProperties) wh
/// <param name="invertClassConceptFilterCheck">if set to <c>true</c> [invert class concept filter check].</param>
/// <returns>Returns a list of entities which match the given search term and class concept key filter.</returns>
public IEnumerable<T> Search<T>(string searchTerm, Guid classConceptFilterKey, string[] expandProperties, bool invertClassConceptFilterCheck = false) where T : Entity
{
return this.Search<T>(searchTerm, classConceptFilterKey, 0, null, expandProperties, invertClassConceptFilterCheck);
}

/// <summary>
/// Searches the specified search term.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="searchTerm">The search term.</param>
/// <param name="classConceptFilterKey">The class concept filter key.</param>
/// <param name="offset">The offset.</param>
/// <param name="count">The count.</param>
/// <param name="expandProperties">The expand properties.</param>
/// <param name="invertClassConceptFilterCheck">if set to <c>true</c> [invert class concept filter check].</param>
/// <returns>Returns a list of entities which match the given search term and class concept key filter.</returns>
public IEnumerable<T> Search<T>(string searchTerm, Guid classConceptFilterKey, int offset, int? count, string[] expandProperties, bool invertClassConceptFilterCheck = false) where T : Entity
{
var results = new List<T>();

Expand All @@ -560,7 +576,7 @@ public IEnumerable<T> Search<T>(string searchTerm, Guid classConceptFilterKey, s
queryExpression = p => p.Names.Any(n => n.Component.Any(c => c.Value.Contains(searchTerm))) && p.ClassConceptKey != classConceptFilterKey;
}

var bundle = this.Client.Query<T>(queryExpression, 0, null, expandProperties);
var bundle = this.Client.Query<T>(queryExpression, offset, count, expandProperties);

foreach (var item in bundle.Item.OfType<T>().LatestVersionOnly().Where(queryExpression.Compile()))
{
Expand All @@ -576,6 +592,7 @@ public IEnumerable<T> Search<T>(string searchTerm, Guid classConceptFilterKey, s
coreAuditService.AuditGenericError(OutcomeIndicator.EpicFail, this.entityAuditService.QueryEntityAuditCode, EventIdentifierType.ApplicationActivity, e);
throw;
}

return results;
}

Expand Down
13 changes: 13 additions & 0 deletions OpenIZAdmin.Services/Entities/IEntityService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,19 @@ public interface IEntityService
/// <returns>Returns a list of entities which match the given search term and class concept key filter.</returns>
IEnumerable<T> Search<T>(string searchTerm, Guid classConceptFilterKey, string[] expandProperties, bool invertClassConceptFilterCheck = false) where T : Entity;

/// <summary>
/// Searches the specified search term.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="searchTerm">The search term.</param>
/// <param name="classConceptFilterKey">The class concept filter key.</param>
/// <param name="offset">The offset.</param>
/// <param name="count">The count.</param>
/// <param name="expandProperties">The expand properties.</param>
/// <param name="invertClassConceptFilterCheck">if set to <c>true</c> [invert class concept filter check].</param>
/// <returns>Returns a list of entities which match the given search term and class concept key filter.</returns>
IEnumerable<T> Search<T>(string searchTerm, Guid classConceptFilterKey, int offset, int? count, string[] expandProperties, bool invertClassConceptFilterCheck = false) where T : Entity;

/// <summary>
/// Searches for a specific entity by search term.
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion OpenIZAdmin/Controllers/PlaceController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -928,7 +928,7 @@ public ActionResult SearchAddressAjax(string searchTerm, string classConcept)

if (Guid.TryParse(classConcept, out classConceptKey))
{
var places = this.entityService.Query<Place>(p => p.Names.Any(n => n.Component.Any(c => c.Value.Contains(searchTerm))) && p.ObsoletionTime == null && p.ClassConceptKey == classConceptKey, 0, 15, new string[] { "typeConcept", "address.use" });
var places = this.entityService.Search<Place>(searchTerm, classConceptKey, 0, 15, new []{ "typeConcept", "address.use" });

results = places.Select(p => new PlaceViewModel(p)).OrderBy(p => p.Name).ToList();
}
Expand Down
2 changes: 1 addition & 1 deletion OpenIZAdmin/Scripts/address-search.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
maximumSelectionLength: 1,
keepSearchResults: true,
escapeMarkup: function (markup) { return markup; },
minimumInputLength: 4,
minimumInputLength: 3,
templateResult: function (data) {
var retVal = "";
if (data.data) {
Expand Down

0 comments on commit a8d1a91

Please sign in to comment.