79082

Querying against a comma separated list of IDs with Examine and Lucene.Net?

I am using Examine for Umbraco (which is built on top of Lucene.net) to do my search. I am quite sure my problem is Lucene related.

One of my fields contains a list of comma separated IDs. How do I query this field in the right way?

Eg. I have a field with the values "64,65". I have tried using MultipleCharacterWildcard which only returns a result if I query for the ID 64, but not for ID 65. SingleCharacterWildcard does not return anything, and Fuzzy only returns something if there is only one ID in the field. Any ideas of how to do a proper search? I guess what I am looking for is a "Contains"-query.

Also is this the right way to handle fields with comma separated lists or would it be better to instead split the comma separated list up into individual fields?

Answer1:

I would certainly split the list up into separate fields. You can have multiple values for the same field name in a document, which is a fairly natural way to represent a set of values:

venue_id: 12345 treatment_id_set: 1234 treatment_id_set: 2345

With documents like this, I can simply query for "treatment_id_set:1234" to find all the venues supporting that treatment. Of course, the ordering of the treatments is lost. If you need to recover it, store the comma-separated value while indexing the individual members:

# stored, indexed venue_id: 12345 # stored, not indexed treatment_id_list: 1234,2345 # not stored, indexed treatment_id_set: 1234 treatment_id_set: 2345

Answer2:

In order to add duplicate fields with the same key value into Lucene using Umbraco Examine, you need to hook on to the 'Document Writing' event.

_index.DocumentWriting += _index_DocumentWriting;

This will then expose the underlying Lucene document.

Fields can then be added like this:

foreach (var item in someList) { e.Document.Add(new Field("fieldName", item, Field.Store.YES, Field.Index.NOT_ANALYZED)); }

Recommend

  • Is there an efficient way of returning a sub-section of a text string
  • Server sends Encrypted Handshake right after Server Hello
  • Misspelling & synonym support for Azure Search?
  • Get the ASCII value of a character in Redshift
  • String fuzzy matching in dataframe
  • Simultaneous fuzzy and non-fuzzy join
  • hit highlighting in lucene
  • When Does The JDK Compile Version Matter?
  • How to generate custom case statement in Ruby
  • C++ Parser/Model for Java
  • Scan HBase rows by ignoring a part of the start and end row in Java
  • ElasticSearch: Full-Text Search made easy
  • Python: Split a String Field into 3 Separate Fields using Lambda
  • how can I compare dates in array to find the earliest one?
  • Divide a $1 by 3 and adjusting 1 cent
  • Retrieving specified columns from a list of csv files to create a data data frame in R
  • netsh acl setting (need alternative method - registry settings?)
  • How to override value that appears in a dropdown in the rails_admin gem
  • how to set variables in a php include file?
  • How do I shift the decimal place in Python?
  • What and where is mdimport
  • Does it make sense to call System.gc() and Thread.sleep() when working on Bitmaps?
  • Django rest serializer Breaks when data exists
  • How to rebase a series of branches?
  • Recording logins for password protected directories
  • Azure Cloud Service Web Role web pages do not load
  • Get object from AWS S3 as a stream
  • Javascript Callbacks with Object constructor
  • what is the difference between the asp.net mvc application and asp.net web application
  • Comma separated Values
  • Proper folder structure for lots of source files
  • SQL merge duplicate rows and join values that are different
  • Exception on Android 4.0 `android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode)`
  • How to get Windows thread pool to call class member function?
  • Bitwise OR returns boolean when one of operands is nil
  • Is there any way to bind data to data.frame by some index?
  • Django query for large number of relationships
  • Why is Django giving me: 'first_name' is an invalid keyword argument for this function?
  • How can I use `wmic` in a Windows PE script?
  • How to push additional view controllers onto NavigationController but keep the TabBar?